@@ -1711,15 +1711,15 @@ impl Wallet {
17111711 & mut self ,
17121712 txid : Txid ,
17131713 ) -> Result < TxBuilder < ' _ , DefaultCoinSelectionAlgorithm > , BuildFeeBumpError > {
1714- let graph = self . indexed_graph . graph ( ) ;
1714+ let tx_graph = self . indexed_graph . graph ( ) ;
17151715 let txout_index = & self . indexed_graph . index ;
17161716 let chain_tip = self . chain . tip ( ) . block_id ( ) ;
1717- let chain_positions = graph
1717+ let chain_positions: HashMap < Txid , ChainPosition < _ > > = tx_graph
17181718 . list_canonical_txs ( & self . chain , chain_tip, CanonicalizationParams :: default ( ) )
17191719 . map ( |canon_tx| ( canon_tx. tx_node . txid , canon_tx. chain_position ) )
1720- . collect :: < HashMap < Txid , _ > > ( ) ;
1720+ . collect ( ) ;
17211721
1722- let mut tx = graph
1722+ let mut tx = tx_graph
17231723 . get_tx ( txid)
17241724 . ok_or ( BuildFeeBumpError :: TransactionNotFound ( txid) ) ?
17251725 . as_ref ( )
@@ -1751,68 +1751,60 @@ impl Wallet {
17511751 . map_err ( |_| BuildFeeBumpError :: FeeRateUnavailable ) ?;
17521752
17531753 // Remove the inputs from the tx and process them.
1754- let utxos = tx
1754+ let utxos: Vec < WeightedUtxo > = tx
17551755 . input
17561756 . drain ( ..)
17571757 . map ( |txin| -> Result < _ , BuildFeeBumpError > {
1758- graph
1759- // Get previous transaction.
1760- . get_tx ( txin. previous_output . txid )
1761- . ok_or ( BuildFeeBumpError :: UnknownUtxo ( txin. previous_output ) )
1762- // Get chain position.
1763- . and_then ( |prev_tx| {
1758+ let outpoint = txin. previous_output ;
1759+ let prev_txout = tx_graph. get_txout ( outpoint) . cloned ( ) ;
1760+ match prev_txout. as_ref ( ) . and_then ( |prev_txout| {
1761+ txout_index. index_of_spk ( prev_txout. script_pubkey . clone ( ) )
1762+ } ) {
1763+ // This is a local utxo.
1764+ Some ( & ( keychain, derivation_index) ) => {
1765+ let txout = prev_txout. ok_or ( BuildFeeBumpError :: UnknownUtxo ( outpoint) ) ?;
17641766 let chain_position = chain_positions
1765- . get ( & txin . previous_output . txid )
1767+ . get ( & outpoint . txid )
17661768 . cloned ( )
1767- . ok_or ( BuildFeeBumpError :: UnknownUtxo ( txin. previous_output ) ) ?;
1768- let prev_txout = prev_tx
1769- . output
1770- . get ( txin. previous_output . vout as usize )
1771- . ok_or ( BuildFeeBumpError :: InvalidOutputIndex ( txin. previous_output ) )
1772- . cloned ( ) ?;
1773- Ok ( ( prev_tx, prev_txout, chain_position) )
1774- } )
1775- . map ( |( prev_tx, prev_txout, chain_position) | {
1776- match txout_index. index_of_spk ( prev_txout. script_pubkey . clone ( ) ) {
1777- Some ( & ( keychain, derivation_index) ) => WeightedUtxo {
1778- satisfaction_weight : self
1779- . public_descriptor ( keychain)
1780- . max_weight_to_satisfy ( )
1781- . unwrap ( ) ,
1782- utxo : Utxo :: Local ( LocalOutput {
1783- outpoint : txin. previous_output ,
1784- txout : prev_txout. clone ( ) ,
1785- keychain,
1786- is_spent : true ,
1787- derivation_index,
1788- chain_position,
1789- } ) ,
1790- } ,
1791- None => {
1792- let satisfaction_weight = Weight :: from_wu_usize (
1793- serialize ( & txin. script_sig ) . len ( ) * 4
1794- + serialize ( & txin. witness ) . len ( ) ,
1795- ) ;
1796- WeightedUtxo {
1797- utxo : Utxo :: Foreign {
1798- outpoint : txin. previous_output ,
1799- sequence : txin. sequence ,
1800- psbt_input : Box :: new ( psbt:: Input {
1801- witness_utxo : prev_txout
1802- . script_pubkey
1803- . witness_version ( )
1804- . map ( |_| prev_txout. clone ( ) ) ,
1805- non_witness_utxo : Some ( prev_tx. as_ref ( ) . clone ( ) ) ,
1806- ..Default :: default ( )
1807- } ) ,
1808- } ,
1809- satisfaction_weight,
1810- }
1811- }
1812- }
1813- } )
1769+ . ok_or ( BuildFeeBumpError :: TransactionNotFound ( outpoint. txid ) ) ?;
1770+ Ok ( WeightedUtxo {
1771+ satisfaction_weight : self
1772+ . public_descriptor ( keychain)
1773+ . max_weight_to_satisfy ( )
1774+ . expect ( "descriptor should be satisfiable" ) ,
1775+ utxo : Utxo :: Local ( LocalOutput {
1776+ outpoint,
1777+ txout,
1778+ keychain,
1779+ is_spent : true ,
1780+ derivation_index,
1781+ chain_position,
1782+ } ) ,
1783+ } )
1784+ }
1785+ // This is a foreign utxo.
1786+ None => Ok ( WeightedUtxo {
1787+ satisfaction_weight : Weight :: from_wu_usize (
1788+ serialize ( & txin. script_sig ) . len ( ) * 4 + serialize ( & txin. witness ) . len ( ) ,
1789+ ) ,
1790+ utxo : Utxo :: Foreign {
1791+ outpoint,
1792+ sequence : txin. sequence ,
1793+ psbt_input : Box :: new ( psbt:: Input {
1794+ witness_utxo : prev_txout
1795+ . as_ref ( )
1796+ . and_then ( |txout| txout. script_pubkey . witness_version ( ) )
1797+ . and ( prev_txout) ,
1798+ non_witness_utxo : tx_graph
1799+ . get_tx ( outpoint. txid )
1800+ . map ( |tx| tx. as_ref ( ) . clone ( ) ) ,
1801+ ..Default :: default ( )
1802+ } ) ,
1803+ } ,
1804+ } ) ,
1805+ }
18141806 } )
1815- . collect :: < Result < Vec < WeightedUtxo > , BuildFeeBumpError > > ( ) ?;
1807+ . collect :: < Result < _ , _ > > ( ) ?;
18161808
18171809 if tx. output . len ( ) > 1 {
18181810 let mut change_index = None ;
@@ -1832,7 +1824,6 @@ impl Wallet {
18321824 }
18331825
18341826 let params = TxParams {
1835- // TODO: figure out what rbf option should be?
18361827 version : Some ( tx. version ) ,
18371828 recipients : tx
18381829 . output
0 commit comments