Skip to content

Commit 6bfbda2

Browse files
committed
createpsbt
1 parent 9186b66 commit 6bfbda2

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)