Skip to content

Commit

Permalink
Merge pull request #29 from zoedberg/fix_electrum_input_match
Browse files Browse the repository at this point in the history
electrum: fix wrong input value calculation
  • Loading branch information
dr-orlovsky authored May 23, 2024
2 parents 1db8159 + a90b0df commit e993e46
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/indexers/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl From<VinExtended> for TxCredit {
let vin = vine.vin;
let txid = Txid::from_str(&vin.txid).expect("input txid should deserialize");
TxCredit {
outpoint: Outpoint::new(txid, vin.vout as u32),
outpoint: Outpoint::new(txid, vin.vout),
sequence: SeqNo::from_consensus_u32(vin.sequence),
coinbase: txid.is_coinbase(),
script_sig: vine.sig_script,
Expand All @@ -55,12 +55,6 @@ impl From<VinExtended> for TxCredit {
}
}

#[derive(Clone, Debug, Deserialize)]
#[serde(crate = "serde_crate", rename_all = "camelCase")]
struct ScriptSig {
hex: String,
}

#[derive(Deserialize)]
#[serde(crate = "serde_crate", rename_all = "camelCase")]
struct Pubkey {
Expand All @@ -70,10 +64,9 @@ struct Pubkey {
#[derive(Clone, Debug, Deserialize)]
#[serde(crate = "serde_crate", rename_all = "camelCase")]
struct Vin {
script_sig: ScriptSig,
sequence: u32,
txid: String,
vout: u64,
vout: u32,
}

#[derive(Debug)]
Expand Down Expand Up @@ -188,7 +181,10 @@ impl Indexer for Client {
let input = bp_tx
.inputs
.iter()
.find(|i| i.sig_script.to_hex() == v.script_sig.hex)
.find(|i| {
i.prev_output.txid.to_string() == v.txid
&& i.prev_output.vout.to_u32() == v.vout
})
.expect("input should be present");
let witness = input.witness.clone();
// get value from previous output tx
Expand Down

0 comments on commit e993e46

Please sign in to comment.