summaryrefslogtreecommitdiff
path: root/btc-wire/src/rpc.rs
diff options
context:
space:
mode:
authorAntoine A <>2021-12-28 19:43:39 +0100
committerAntoine A <>2021-12-28 19:43:39 +0100
commit80005a6b383eeaf4593a25173727ba5c03fa2e74 (patch)
tree3f629166073fd747fc294f597b77199375f7c506 /btc-wire/src/rpc.rs
parent976967b98ec4120382e981f0d029cca30d68c908 (diff)
downloaddepolymerization-80005a6b383eeaf4593a25173727ba5c03fa2e74.tar.gz
depolymerization-80005a6b383eeaf4593a25173727ba5c03fa2e74.tar.bz2
depolymerization-80005a6b383eeaf4593a25173727ba5c03fa2e74.zip
btc-wire: add and test bouncing
Diffstat (limited to 'btc-wire/src/rpc.rs')
-rw-r--r--btc-wire/src/rpc.rs36
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>,