-
Notifications
You must be signed in to change notification settings - Fork 33
Implement scantxoutset method and test #164
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
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 |
---|---|---|
|
@@ -302,6 +302,28 @@ fn blockchain__savemempool() { | |
} | ||
} | ||
|
||
#[test] | ||
fn blockchain__scan_tx_out_set_modelled() { | ||
let node = match () { | ||
#[cfg(feature = "v21_and_below")] | ||
() => Node::with_wallet(Wallet::None, &[]), | ||
#[cfg(not(feature = "v21_and_below"))] | ||
() => Node::with_wallet(Wallet::None, &["-coinstatsindex=1"]) | ||
}; | ||
|
||
let dummy_pubkey_hex = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"; | ||
let scan_desc = format!("pkh({})", dummy_pubkey_hex); | ||
|
||
let json: ScanTxOutSetStart = node.client.scan_tx_out_set_start(&[&scan_desc]).expect("scantxoutset start"); | ||
|
||
let _: Option<ScanTxOutSetStatus> = node.client.scan_tx_out_set_status().expect("scantxoutset status"); | ||
|
||
let model: Result<mtype::ScanTxOutSetStart, ScanTxOutSetError> = json.into_model(); | ||
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. Moving this line to directly below |
||
model.unwrap(); | ||
|
||
let _: ScanTxOutSetAbort = node.client.scan_tx_out_set_abort().expect("scantxoutset abort"); | ||
} | ||
|
||
#[test] | ||
fn blockchain__verify_tx_out_proof__modelled() { | ||
let node = Node::with_wallet(Wallet::Default, &[]); | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -621,3 +621,42 @@ pub struct ReceiveActivity { | |||||||
/// The ScriptPubKey, converted to `model::ScriptPubkey`. | ||||||||
pub output_spk: ScriptPubkey, | ||||||||
} | ||||||||
|
||||||||
/// Models the result of the JSON-RPC method `scantxoutset` start. | ||||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||||||
pub struct ScanTxOutSetStart { | ||||||||
/// Whether the scan is completed. For v19 onwards. | ||||||||
pub success: Option<bool>, | ||||||||
/// The number of unspent transaction outputs scanned. For v19 onwards. | ||||||||
pub txouts: Option<u64>, | ||||||||
/// The current block height (index). For v19 onwards. | ||||||||
pub height: Option<u64>, | ||||||||
/// The hash of the block at the tip of the chain. For v19 onwards. | ||||||||
pub bestblock: Option<BlockHash>, | ||||||||
/// The unspents | ||||||||
pub unspents: Vec<ScanTxOutSetUnspent>, | ||||||||
/// The total amount of all found unspent outputs in BTC | ||||||||
pub total_amount: Amount, | ||||||||
} | ||||||||
|
||||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||||||
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.
Suggested change
Needs docs, e.g. above. Having scanned through the code a lot recently I find it useful if the original RPC is mentioned. |
||||||||
pub struct ScanTxOutSetUnspent { | ||||||||
/// The transaction id | ||||||||
pub txid: Txid, | ||||||||
/// The vout value | ||||||||
pub vout: u32, | ||||||||
/// The script key | ||||||||
pub script_pubkey: ScriptBuf, | ||||||||
/// An output descriptor. For v18 onwards. | ||||||||
pub desc: Option<String>, | ||||||||
/// The total amount in BTC of unspent output | ||||||||
pub amount: Amount, | ||||||||
/// Whether this is a coinbase output. For v25 onwards. | ||||||||
pub coinbase: Option<bool>, | ||||||||
/// Height of the unspent transaction output | ||||||||
pub height: u64, | ||||||||
/// Blockhash of the unspent transaction output. For v28 onwards. | ||||||||
pub blockhash: Option<BlockHash>, | ||||||||
/// Number of confirmations of the unspent transaction output when the scan was done. For v28 onwards. | ||||||||
pub confirmations: Option<u64>, | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -679,6 +679,45 @@ pub struct PruneBlockchain( | |||||||||||||||
pub i64, | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
/// Result of JSON-RPC method `scantxoutset`. | ||||||||||||||||
/// | ||||||||||||||||
/// > scantxoutset "action" ( [scanobjects,...] ) | ||||||||||||||||
/// > | ||||||||||||||||
/// > Arguments: | ||||||||||||||||
/// > 1. "action" (string, required) The action to execute | ||||||||||||||||
/// > 2. "scanobjects" (array, required) Array of scan objects | ||||||||||||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||||||||||||||
pub struct ScanTxOutSetStart { | ||||||||||||||||
/// The unspents | ||||||||||||||||
pub unspents: Vec<ScanTxOutSetUnspent>, | ||||||||||||||||
/// The total amount of all found unspent outputs in BTC | ||||||||||||||||
pub total_amount: f64, | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||||||||||||||
pub struct ScanTxOutSetAbort(pub bool); | ||||||||||||||||
Comment on lines
+696
to
+698
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. Needs rustdocs |
||||||||||||||||
|
||||||||||||||||
#[derive(Deserialize, Debug, Clone, PartialEq)] | ||||||||||||||||
pub struct ScanTxOutSetStatus { | ||||||||||||||||
/// Approximate percent complete | ||||||||||||||||
pub progress: f64, | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+700
to
+704
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.
Suggested change
Also needs docs. Was there a reason serialize was not included that I have missed? |
||||||||||||||||
|
||||||||||||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||||||||||||||
pub struct ScanTxOutSetUnspent { | ||||||||||||||||
/// The transaction id | ||||||||||||||||
pub txid: String, | ||||||||||||||||
/// The vout value | ||||||||||||||||
pub vout: u32, | ||||||||||||||||
/// The script key | ||||||||||||||||
#[serde(rename = "scriptPubKey")] | ||||||||||||||||
pub script_pubkey: String, | ||||||||||||||||
/// The total amount in BTC of unspent output | ||||||||||||||||
pub amount: f64, | ||||||||||||||||
/// Height of the unspent transaction output | ||||||||||||||||
pub height: u64, | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/// Result of JSON-RPC method `verifychain`. | ||||||||||||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||||||||||||||
#[serde(deny_unknown_fields)] | ||||||||||||||||
|
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.
nit: This change is unrelated and wrong. It's not fixed by cargo fmt due to the skip above the block.
NB. I'm ok with the random fix being in this PR if done correctly though.