Skip to content

Commit 0965a24

Browse files
committed
add walletprocesspsbt
1 parent ac1e31e commit 0965a24

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

client/src/client.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,25 @@ pub trait RpcApi: Sized {
959959
)
960960
}
961961

962+
fn wallet_process_psbt(
963+
&self,
964+
psbt: &str,
965+
sign: Option<bool>,
966+
sighash_type: Option<json::SigHashType>,
967+
bip32derivs: Option<bool>,
968+
) -> Result<json::WalletProcessPsbtResult> {
969+
let mut args = [
970+
into_json(psbt)?,
971+
opt_into_json(sign)?,
972+
opt_into_json(sighash_type)?,
973+
opt_into_json(bip32derivs)?,
974+
];
975+
self.call(
976+
"walletprocesspsbt",
977+
handle_defaults(&mut args, &[true.into(), null(), true.into()]),
978+
)
979+
}
980+
962981
fn get_descriptor_info(&self, desc: &str) -> Result<json::GetDescriptorInfoResult> {
963982
self.call("getdescriptorinfo", &[desc.to_string().into()])
964983
}

integration_test/src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ fn main() {
156156
test_fund_raw_transaction(&cl);
157157
test_test_mempool_accept(&cl);
158158
test_wallet_create_funded_psbt(&cl);
159+
test_wallet_process_psbt(&cl);
159160
test_combine_psbt(&cl);
160161
test_finalize_psbt(&cl);
161162
test_list_received_by_address(&cl);
@@ -702,6 +703,30 @@ fn test_wallet_create_funded_psbt(cl: &Client) {
702703
assert!(!psbt.psbt.is_empty());
703704
}
704705

706+
fn test_wallet_process_psbt(cl: &Client) {
707+
let options = json::ListUnspentQueryOptions {
708+
minimum_amount: Some(btc(2)),
709+
..Default::default()
710+
};
711+
let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap();
712+
let unspent = unspent.into_iter().nth(0).unwrap();
713+
let input = json::CreateRawTransactionInput {
714+
txid: unspent.txid,
715+
vout: unspent.vout,
716+
sequence: None,
717+
};
718+
let mut output = HashMap::new();
719+
output.insert(RANDOM_ADDRESS.to_string(), btc(1));
720+
let psbt = cl
721+
.wallet_create_funded_psbt(&[input.clone()], &output, Some(500_000), None, Some(true))
722+
.unwrap();
723+
724+
let res = cl
725+
.wallet_process_psbt(&psbt.psbt, Some(true), Some(SigHashType::All.into()), Some(true))
726+
.unwrap();
727+
assert!(res.complete);
728+
}
729+
705730
fn test_combine_psbt(cl: &Client) {
706731
let options = json::ListUnspentQueryOptions {
707732
minimum_amount: Some(btc(2)),

json/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,13 @@ pub struct WalletCreateFundedPsbtResult {
10191019
pub change_position: i32,
10201020
}
10211021

1022+
/// Models the result of "walletprocesspsbt"
1023+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1024+
pub struct WalletProcessPsbtResult {
1025+
pub psbt: String,
1026+
pub complete: bool,
1027+
}
1028+
10221029
/// Models the request for "walletcreatefundedpsbt"
10231030
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, Default)]
10241031
pub struct WalletCreateFundedPsbtOptions {

0 commit comments

Comments
 (0)