Skip to content

Commit 3c9d95f

Browse files
authored
Merge pull request #152 from jharveyb/add_walletprocesspsbt
add walletprocesspsbt
2 parents 7f74bd2 + 1106a6a commit 3c9d95f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

client/src/client.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,27 @@ pub trait RpcApi: Sized {
964964
)
965965
}
966966

967+
fn wallet_process_psbt(
968+
&self,
969+
psbt: &str,
970+
sign: Option<bool>,
971+
sighash_type: Option<json::SigHashType>,
972+
bip32derivs: Option<bool>,
973+
) -> Result<json::WalletProcessPsbtResult> {
974+
let mut args = [
975+
into_json(psbt)?,
976+
opt_into_json(sign)?,
977+
opt_into_json(sighash_type)?,
978+
opt_into_json(bip32derivs)?,
979+
];
980+
let defaults = [
981+
true.into(),
982+
into_json(json::SigHashType::from(bitcoin::SigHashType::All))?,
983+
true.into(),
984+
];
985+
self.call("walletprocesspsbt", handle_defaults(&mut args, &defaults))
986+
}
987+
967988
fn get_descriptor_info(&self, desc: &str) -> Result<json::GetDescriptorInfoResult> {
968989
self.call("getdescriptorinfo", &[desc.to_string().into()])
969990
}

integration_test/src/main.rs

Lines changed: 23 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);
@@ -705,6 +706,28 @@ fn test_wallet_create_funded_psbt(cl: &Client) {
705706
assert!(!psbt.psbt.is_empty());
706707
}
707708

709+
fn test_wallet_process_psbt(cl: &Client) {
710+
let options = json::ListUnspentQueryOptions {
711+
minimum_amount: Some(btc(2)),
712+
..Default::default()
713+
};
714+
let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap();
715+
let unspent = unspent.into_iter().nth(0).unwrap();
716+
let input = json::CreateRawTransactionInput {
717+
txid: unspent.txid,
718+
vout: unspent.vout,
719+
sequence: None,
720+
};
721+
let mut output = HashMap::new();
722+
output.insert(RANDOM_ADDRESS.to_string(), btc(1));
723+
let psbt = cl
724+
.wallet_create_funded_psbt(&[input.clone()], &output, Some(500_000), None, Some(true))
725+
.unwrap();
726+
727+
let res = cl.wallet_process_psbt(&psbt.psbt, Some(true), None, Some(true)).unwrap();
728+
assert!(res.complete);
729+
}
730+
708731
fn test_combine_psbt(cl: &Client) {
709732
let options = json::ListUnspentQueryOptions {
710733
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)