Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc_api: Add errors for unused arguments. #59

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions src/client/rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ impl RpcApi for Client {
txid: &bitcoin::Txid,
_block_hash: Option<&bitcoin::BlockHash>,
) -> bitcoincore_rpc::Result<bitcoin::Transaction> {
if _block_hash.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_block_hash)
)));
}

Ok(self.ledger.get_transaction(*txid)?)
}
/// Verbose flag enabled `get_raw_transaction`.
Expand All @@ -87,6 +94,13 @@ impl RpcApi for Client {
txid: &bitcoin::Txid,
_block_hash: Option<&bitcoin::BlockHash>,
) -> bitcoincore_rpc::Result<json::GetRawTransactionResult> {
if _block_hash.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_block_hash)
)));
}

let tx = self.get_raw_transaction(txid, _block_hash)?;

let mut hex: Vec<u8> = Vec::new();
Expand Down Expand Up @@ -186,6 +200,13 @@ impl RpcApi for Client {
txid: &bitcoin::Txid,
_include_watchonly: Option<bool>,
) -> bitcoincore_rpc::Result<json::GetTransactionResult> {
if _include_watchonly.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_include_watchonly)
)));
}

let raw_tx = self.get_raw_transaction(txid, None).unwrap();
let mut amount = Amount::from_sat(0);

Expand Down Expand Up @@ -262,6 +283,43 @@ impl RpcApi for Client {
_confirmation_target: Option<u32>,
_estimate_mode: Option<json::EstimateMode>,
) -> bitcoincore_rpc::Result<bitcoin::Txid> {
if _comment.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_comment)
)));
}
if _comment_to.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_comment_to)
)));
}
if _subtract_fee.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_subtract_fee)
)));
}
if _replaceable.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_replaceable)
)));
}
if _confirmation_target.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_confirmation_target)
)));
}
if _estimate_mode.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_estimate_mode)
)));
}

// First, create a random input. Why? Because calling this function for
// same amount twice will trigger a database error about same TXID blah,
// blah, blah.
Expand All @@ -286,6 +344,19 @@ impl RpcApi for Client {
_label: Option<&str>,
_address_type: Option<json::AddressType>,
) -> bitcoincore_rpc::Result<Address<bitcoin::address::NetworkUnchecked>> {
if _label.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_label)
)));
}
if _address_type.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_address_type)
)));
}

let address = ledger::Ledger::get_constant_credential_from_witness().address;

Ok(address.as_unchecked().to_owned())
Expand Down Expand Up @@ -320,6 +391,13 @@ impl RpcApi for Client {
vout: u32,
_include_mempool: Option<bool>,
) -> bitcoincore_rpc::Result<Option<json::GetTxOutResult>> {
if let Some(false) = _include_mempool {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_include_mempool)
)));
}

let bestblock = self.get_best_block_hash()?;

let tx = self.get_raw_transaction(txid, None)?;
Expand Down Expand Up @@ -377,6 +455,13 @@ impl RpcApi for Client {
options: Option<&json::FundRawTransactionOptions>,
_is_witness: Option<bool>,
) -> bitcoincore_rpc::Result<json::FundRawTransactionResult> {
if _is_witness.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_is_witness)
)));
}

let mut transaction: Transaction = encode::deserialize_hex(&tx.raw_hex())?;
tracing::debug!("Decoded input transaction: {transaction:?}");

Expand Down Expand Up @@ -447,6 +532,19 @@ impl RpcApi for Client {
_utxos: Option<&[json::SignRawTransactionInput]>,
_sighash_type: Option<json::SigHashType>,
) -> bitcoincore_rpc::Result<json::SignRawTransactionResult> {
if _utxos.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_utxos)
)));
}
if _sighash_type.is_some() {
return Err(Error::ReturnedError(format!(
"This argument is unimplemented: {}",
stringify!(_sighash_type)
)));
}

let mut transaction: Transaction = encode::deserialize_hex(&tx.raw_hex())?;
tracing::debug!("Decoded input transaction: {transaction:?}");

Expand Down
Loading