Skip to content

Commit f0e8e4f

Browse files
committed
Fix walletcreatefundedpsbt macro
The client macro passed an `Amount` to the RPC which parses to the wrong format resulting in 0 BTC for that address. The `inputs` struct has private fields and no constructor. Add a constructor for `WalletCreateFundedPsbtInput`. Convert the `Amount` in the `outputs` argument to btc before calling the RPC.
1 parent 9740fae commit f0e8e4f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

client/src/client_sync/v17/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ pub struct WalletCreateFundedPsbtInput {
241241
vout: u32,
242242
}
243243

244+
impl WalletCreateFundedPsbtInput {
245+
/// Create a new walletcreatefundedpsbt input entry.
246+
pub fn new(txid: Txid, vout: u32) -> Self { Self { txid, vout } }
247+
}
248+
244249
/// Args for the `addnode` method.
245250
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
246251
#[serde(rename_all = "lowercase")]

client/src/client_sync/v17/wallet.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,16 @@ macro_rules! impl_client_v17__wallet_create_funded_psbt {
706706
inputs: Vec<WalletCreateFundedPsbtInput>,
707707
outputs: Vec<BTreeMap<Address, Amount>>,
708708
) -> Result<WalletCreateFundedPsbt> {
709-
self.call("walletcreatefundedpsbt", &[into_json(inputs)?, into_json(outputs)?])
709+
// Convert outputs: Vec<BTreeMap<Address, Amount>> to Vec<BTreeMap<String, f64>>
710+
let outputs_json: Vec<_> = outputs
711+
.into_iter()
712+
.map(|map| {
713+
map.into_iter()
714+
.map(|(addr, amt)| (addr.to_string(), amt.to_btc()))
715+
.collect::<BTreeMap<_, _>>()
716+
})
717+
.collect();
718+
self.call("walletcreatefundedpsbt", &[into_json(inputs)?, into_json(outputs_json)?])
710719
}
711720
}
712721
};

0 commit comments

Comments
 (0)