Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamaguchi committed Aug 12, 2024
1 parent 0bdab75 commit e55e2f1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions crates/chain/src/keychain/txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
self.inner.insert_p2c_spk(spk, payment_base);
}

/// Returns script pubkey of payment base for pay-to-contract script
pub fn p2c_spk(&self, spk: &ScriptBuf) -> Option<&ScriptBuf> {
self.inner.p2c_spk(spk)
}

/// Returns whether the spk under the `keychain`'s `index` has been used.
///
/// Here, "unused" means that after the script pubkey was stored in the index, the index has
Expand Down
5 changes: 5 additions & 0 deletions crates/chain/src/spk_txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
self.p2c_spks.insert(spk, p2c_spk);
}

/// Returns script pubkey of payment base for pay-to-contract script
pub fn p2c_spk(&self, spk: &ScriptBuf) -> Option<&ScriptBuf> {
self.p2c_spks.get(spk)
}

/// Adds a script pubkey to scan for. Returns `false` and does nothing if spk already exists in the map
///
/// the index will look for outputs spending to this spk whenever it scans new data.
Expand Down
20 changes: 14 additions & 6 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2622,15 +2622,23 @@ impl Wallet {
// Try to find the prev_script in our db to figure out if this is internal or external,
// and the derivation index
let script = if utxo.txout.script_pubkey.is_colored() {
ScriptBuf::from_bytes(utxo.txout.script_pubkey.as_bytes()[35..].to_vec())
utxo.txout.script_pubkey.remove_color()
} else {
utxo.txout.script_pubkey
};
let (keychain, child) = self
.indexed_graph
.index
.index_of_spk(&script)
.ok_or(CreateTxError::UnknownUtxo)?;
let payment_base = self.spk_index().p2c_spk(&script);

let (keychain, child) = if let Some(p) = payment_base {
self.indexed_graph
.index
.index_of_spk(p.clone().as_script())
.ok_or(CreateTxError::UnknownUtxo)?
} else {
self.indexed_graph
.index
.index_of_spk(&script)
.ok_or(CreateTxError::UnknownUtxo)?
};

let mut psbt_input = psbt::Input {
sighash_type,
Expand Down
2 changes: 1 addition & 1 deletion crates/wallet/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ pub fn get_funded_wallet_with_p2c_and_change(
}],
output: vec![TxOut {
value: Amount::from_tap(76_000),
script_pubkey: sendto_address.script_pubkey(),
script_pubkey: fund_address.script_pubkey(),
}],
};

Expand Down

0 comments on commit e55e2f1

Please sign in to comment.