-
Notifications
You must be signed in to change notification settings - Fork 261
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
update sendtoaddress for 0.21 #204
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,9 +121,6 @@ fn handle_defaults<'a, 'b>( | |
let defaults_i = defaults.len() - 1 - i; | ||
if args[args_i] == serde_json::Value::Null { | ||
if first_non_null_optional_idx.is_some() { | ||
if defaults[defaults_i] == serde_json::Value::Null { | ||
panic!("Missing `default` for argument idx {}", args_i); | ||
} | ||
args[args_i] = defaults[defaults_i].clone(); | ||
} | ||
} else if first_non_null_optional_idx.is_none() { | ||
|
@@ -900,6 +897,8 @@ pub trait RpcApi: Sized { | |
replaceable: Option<bool>, | ||
confirmation_target: Option<u32>, | ||
estimate_mode: Option<json::EstimateMode>, | ||
avoid_reuse: Option<bool>, | ||
fee_rate: Option<i32>, | ||
) -> Result<bitcoin::Txid> { | ||
let mut args = [ | ||
address.to_string().into(), | ||
|
@@ -910,12 +909,14 @@ pub trait RpcApi: Sized { | |
opt_into_json(replaceable)?, | ||
opt_into_json(confirmation_target)?, | ||
opt_into_json(estimate_mode)?, | ||
opt_into_json(avoid_reuse)?, | ||
opt_into_json(fee_rate)?, | ||
]; | ||
self.call( | ||
"sendtoaddress", | ||
handle_defaults( | ||
&mut args, | ||
&["".into(), "".into(), false.into(), false.into(), 6.into(), null()], | ||
&["".into(), "".into(), false.into(), false.into(), null(), null(), null(), null()], | ||
Comment on lines
-918
to
+919
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs, the node uses the default value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the case this change should probably be done as a separate patch (at the start of the PR) with full justification. This means next time someone is debugging they can use Sorry for such a delayed response, I was not focused on this crate for along time. |
||
), | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,17 +393,20 @@ fn test_set_label(cl: &Client) { | |
fn test_send_to_address(cl: &Client) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we could skip formatting for this? #[rustfmt::skip]
fn test_send_to_address(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let est = json::EstimateMode::Conservative;
let _ = cl.send_to_address(&addr, btc(1), Some("cc"), None, None, None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, Some("tt"), None, None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, Some(true), None, None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, Some(true), None, None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, Some(3), None, None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, Some(est), None, None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, Some(false), None).unwrap();
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, Some(5)).unwrap();
let _ =cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap();
} |
||
let addr = cl.get_new_address(None, None).unwrap(); | ||
let est = json::EstimateMode::Conservative; | ||
let _ = cl.send_to_address(&addr, btc(1), Some("cc"), None, None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, Some("tt"), None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, Some(true), None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, Some(true), None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, Some(3), None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, Some(est)).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), Some("cc"), None, None, None, None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, Some("tt"), None, None, None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, Some(true), None, None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, Some(true), None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, Some(3), None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, Some(est), None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, Some(false), None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, Some(5)).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
} | ||
|
||
fn test_get_received_by_address(cl: &Client) { | ||
let addr = cl.get_new_address(None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap(); | ||
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
assert_eq!(cl.get_received_by_address(&addr, Some(0)).unwrap(), btc(1)); | ||
assert_eq!(cl.get_received_by_address(&addr, Some(1)).unwrap(), btc(0)); | ||
let _ = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap()).unwrap(); | ||
|
@@ -413,13 +416,13 @@ fn test_get_received_by_address(cl: &Client) { | |
|
||
fn test_list_unspent(cl: &Client) { | ||
let addr = cl.get_new_address(None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let unspent = cl.list_unspent(Some(0), None, Some(&[&addr]), None, None).unwrap(); | ||
assert_eq!(unspent[0].txid, txid); | ||
assert_eq!(unspent[0].address.as_ref(), Some(&addr)); | ||
assert_eq!(unspent[0].amount, btc(1)); | ||
|
||
let txid = cl.send_to_address(&addr, btc(7), None, None, None, None, None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(7), None, None, None, None, None, None, None, None).unwrap(); | ||
let options = json::ListUnspentQueryOptions { | ||
minimum_amount: Some(btc(7)), | ||
maximum_amount: Some(btc(7)), | ||
|
@@ -442,7 +445,7 @@ fn test_get_connection_count(cl: &Client) { | |
|
||
fn test_get_raw_transaction(cl: &Client) { | ||
let addr = cl.get_new_address(None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let tx = cl.get_raw_transaction(&txid, None).unwrap(); | ||
let hex = cl.get_raw_transaction_hex(&txid, None).unwrap(); | ||
assert_eq!(tx, deserialize(&Vec::<u8>::from_hex(&hex).unwrap()).unwrap()); | ||
|
@@ -461,7 +464,7 @@ fn test_get_raw_mempool(cl: &Client) { | |
|
||
fn test_get_transaction(cl: &Client) { | ||
let txid = | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap(); | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let tx = cl.get_transaction(&txid, None).unwrap(); | ||
assert_eq!(tx.amount, sbtc(-1.0)); | ||
assert_eq!(tx.info.txid, txid); | ||
|
@@ -486,7 +489,7 @@ fn test_list_since_block(cl: &Client) { | |
|
||
fn test_get_tx_out(cl: &Client) { | ||
let txid = | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap(); | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let out = cl.get_tx_out(&txid, 0, Some(false)).unwrap(); | ||
assert!(out.is_none()); | ||
let out = cl.get_tx_out(&txid, 0, Some(true)).unwrap(); | ||
|
@@ -496,17 +499,17 @@ fn test_get_tx_out(cl: &Client) { | |
|
||
fn test_get_tx_out_proof(cl: &Client) { | ||
let txid1 = | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap(); | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let txid2 = | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap(); | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let blocks = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap()).unwrap(); | ||
let proof = cl.get_tx_out_proof(&[txid1, txid2], Some(&blocks[0])).unwrap(); | ||
assert!(!proof.is_empty()); | ||
} | ||
|
||
fn test_get_mempool_entry(cl: &Client) { | ||
let txid = | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap(); | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
let entry = cl.get_mempool_entry(&txid).unwrap(); | ||
assert!(entry.spent_by.is_empty()); | ||
|
||
|
@@ -516,7 +519,7 @@ fn test_get_mempool_entry(cl: &Client) { | |
|
||
fn test_lock_unspent_unlock_unspent(cl: &Client) { | ||
let addr = cl.get_new_address(None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
|
||
assert!(cl.lock_unspent(&[OutPoint::new(txid, 0)]).unwrap()); | ||
assert!(cl.unlock_unspent(&[OutPoint::new(txid, 0)]).unwrap()); | ||
|
@@ -832,7 +835,7 @@ fn test_finalize_psbt(cl: &Client) { | |
|
||
fn test_list_received_by_address(cl: &Client) { | ||
let addr = cl.get_new_address(None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap(); | ||
let txid = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
|
||
let _ = cl.list_received_by_address(Some(&addr), None, None, None).unwrap(); | ||
let _ = cl.list_received_by_address(Some(&addr), None, Some(true), None).unwrap(); | ||
|
@@ -1124,7 +1127,7 @@ fn test_getblocktemplate(cl: &Client) { | |
// contains an entry in the vector of GetBlockTemplateResultTransaction. | ||
// Otherwise the GetBlockTemplateResultTransaction deserialization wouldn't | ||
// be tested. | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap(); | ||
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None, None, None).unwrap(); | ||
|
||
cl.get_block_template(GetBlockTemplateModes::Template, &[GetBlockTemplateRules::SegWit], &[]) | ||
.unwrap(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason that this is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for reviewing the PR :) I removed this so that we can pass
null()
to the rpc commands and therefore make the node use the default configuration created internally by the node.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only newish to this crate but I'm almost certain we cannot remove this check, doing so changes the behaviour of the whole crate.