Skip to content

Commit fc3a12d

Browse files
committed
Merge #265: Add create_psbt
6bfbda2 createpsbt (thesimplekid) Pull request description: ACKs for top commit: apoelstra: ACK 6bfbda2 Tree-SHA512: a4f83f5d79120011c96cc275c5fc81a26b90cb2c724eba92a86302683280c2a6bc922ab1a70d905c957cef150623c915c1f813415bd8145f3a0fe44596729b60
2 parents bdc9f9b + 6bfbda2 commit fc3a12d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

client/src/client.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,27 @@ pub trait RpcApi: Sized {
725725
self.call("listreceivedbyaddress", handle_defaults(&mut args, &defaults))
726726
}
727727

728+
fn create_psbt(
729+
&self,
730+
inputs: &[json::CreateRawTransactionInput],
731+
outputs: &HashMap<String, Amount>,
732+
locktime: Option<i64>,
733+
replaceable: Option<bool>,
734+
) -> Result<String> {
735+
let outs_converted = serde_json::Map::from_iter(
736+
outputs.iter().map(|(k, v)| (k.clone(), serde_json::Value::from(v.to_btc()))),
737+
);
738+
self.call(
739+
"createpsbt",
740+
&[
741+
into_json(inputs)?,
742+
into_json(outs_converted)?,
743+
into_json(locktime)?,
744+
into_json(replaceable)?,
745+
],
746+
)
747+
}
748+
728749
fn create_raw_transaction_hex(
729750
&self,
730751
utxos: &[json::CreateRawTransactionInput],

integration_test/src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ fn main() {
175175
test_wallet_process_psbt(&cl);
176176
test_join_psbt(&cl);
177177
test_combine_psbt(&cl);
178+
test_create_psbt(&cl);
178179
test_finalize_psbt(&cl);
179180
test_list_received_by_address(&cl);
180181
test_scantxoutset(&cl);
@@ -848,6 +849,25 @@ fn test_combine_psbt(cl: &Client) {
848849
assert!(!psbt.is_empty());
849850
}
850851

852+
fn test_create_psbt(cl: &Client) {
853+
let options = json::ListUnspentQueryOptions {
854+
minimum_amount: Some(btc(2)),
855+
..Default::default()
856+
};
857+
let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap();
858+
let unspent = unspent.into_iter().nth(0).unwrap();
859+
860+
let input = json::CreateRawTransactionInput {
861+
txid: unspent.txid,
862+
vout: unspent.vout,
863+
sequence: None,
864+
};
865+
let mut output = HashMap::new();
866+
output.insert(RANDOM_ADDRESS.to_string(), btc(1));
867+
868+
let _ = cl.create_psbt(&[input], &output, Some(500_000), Some(true)).unwrap();
869+
}
870+
851871
fn test_finalize_psbt(cl: &Client) {
852872
let options = json::ListUnspentQueryOptions {
853873
minimum_amount: Some(btc(2)),

0 commit comments

Comments
 (0)