1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-24 06:57:53 +01:00

Refactor find_funding_outputs in query crate

This commit is contained in:
Roman Zeyde 2018-05-16 21:54:01 +03:00
parent a2dea8c3f2
commit 14f132a766
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB

View file

@ -104,6 +104,22 @@ impl<'a> Query<'a> {
}
}
fn find_funding_outputs(&self, t: &TxnHeight, script_hash: &[u8]) -> Vec<FundingOutput> {
let mut result = Vec::new();
let txn_id = t.txn.txid();
for (index, output) in enumerate(&t.txn.output) {
if compute_script_hash(&output.script_pubkey[..]) == script_hash {
result.push(FundingOutput {
txn_id: txn_id,
height: t.height,
output_index: index,
value: output.value,
})
}
}
result
}
pub fn status(&self, script_hash: &[u8]) -> Status {
let mut status = Status {
balance: 0,
@ -119,17 +135,9 @@ impl<'a> Query<'a> {
.collect(),
);
for t in funding_txns {
let txn_id = t.txn.txid();
for (index, output) in enumerate(&t.txn.output) {
if compute_script_hash(&output.script_pubkey[..]) == script_hash {
status.funding.push(FundingOutput {
txn_id: txn_id,
height: t.height,
output_index: index,
value: output.value,
})
}
}
status
.funding
.extend(self.find_funding_outputs(&t, script_hash));
}
for funding_output in &status.funding {
if let Some(spent) = self.find_spending_input(&funding_output) {