diff options
Diffstat (limited to 'btc-wire/src/rpc.rs')
-rw-r--r-- | btc-wire/src/rpc.rs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs index 8121e1e..bac9a6b 100644 --- a/btc-wire/src/rpc.rs +++ b/btc-wire/src/rpc.rs @@ -206,7 +206,13 @@ impl BtcRpc { inputs: impl IntoIterator<Item = &'a Txid>, outputs: impl IntoIterator<Item = (&'b Address, &'c Amount)>, data: Option<&[u8]>, + subtract_fee: bool, ) -> Result<Txid> { + let mut outputs: Vec<Value> = outputs + .into_iter() + .map(|(addr, amount)| json!({&addr.to_string(): amount.as_btc()})) + .collect(); + let len = outputs.len(); let hex: String = self.call( "createrawtransaction", &[ @@ -218,18 +224,26 @@ impl BtcRpc { .collect(), ), Value::Array({ - let mut vec: Vec<Value> = outputs - .into_iter() - .map(|(addr, amount)| json!({&addr.to_string(): amount.as_btc()})) - .collect(); if let Some(data) = data { - vec.push(json!({ "data".to_string(): data.to_hex() })); + outputs.push(json!({ "data".to_string(): data.to_hex() })); } - vec + outputs }), ], )?; - let funded: HexWrapper = self.call("fundrawtransaction", &[hex])?; + let funded: HexWrapper = self.call( + "fundrawtransaction", + &( + hex, + FundOption { + subtract_fee_from_outputs: if subtract_fee { + (0..len).into_iter().collect() + } else { + vec![] + }, + }, + ), + )?; let signed: HexWrapper = self.call("signrawtransactionwithwallet", &[&funded.hex])?; self.call("sendrawtransaction", &[&signed.hex]) } @@ -252,7 +266,13 @@ impl BtcRpc { } } -#[derive(Debug, serde::Deserialize, serde::Serialize)] +#[derive(Debug, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct FundOption { + pub subtract_fee_from_outputs: Vec<usize>, +} + +#[derive(Debug, serde::Deserialize)] pub struct Wallet { pub name: String, pub warning: Option<String>, |