Skip to content

Add addmultisigaddress test and update structs #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions integration_test/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ fn wallet__abort_rescan() {
}

#[test]
#[cfg(feature = "TODO")]
fn wallet__add_multisig_address__modelled() {
let nrequired = 1; // 1-of-2 multisig.
let nrequired = 2;

let add1: Address<NetworkChecked> =
"32iVBEu4dxkUQk9dJbZUiBiQdmypcEyJRf".parse::<Address<_>>().unwrap().assume_checked();
let add2: Address<NetworkChecked> =
"132F25rTsvBdp9JzLLBHP5mvGY66i1xdiM".parse::<Address<_>>().unwrap().assume_checked();
let node = match () {
#[cfg(feature = "v22_and_below")]
() => Node::with_wallet(Wallet::Default, &[]),
#[cfg(not(feature = "v22_and_below"))]
() => {
let node = Node::with_wallet(Wallet::None, &["-deprecatedrpc=create_bdb"]);
node.client.create_legacy_wallet("wallet_name").expect("createlegacywallet");
node
}
};

let addr1 = node.client.new_address().expect("new_address");
let addr2 = node.client.new_address().expect("new_address");

let node = Node::with_wallet(Wallet::Default, &[]);
let json: AddMultisigAddress = node
.client
.add_multisig_address_with_addresses(nrequired, vec![add1, add2])
.add_multisig_address_with_addresses(nrequired, vec![addr1, addr2])
.expect("addmultisigaddress");

let model: Result<mtype::AddMultisigAddress, AddMultisigAddressError> = json.into_model();
model.unwrap();
}
Expand Down
4 changes: 4 additions & 0 deletions types/src/model/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub struct AddMultisigAddress {
pub address: Address<NetworkUnchecked>,
/// The redemption script.
pub redeem_script: ScriptBuf,
/// The descriptor for this multisig.
pub descriptor: Option<String>,
/// Any warnings resulting from the creation of this multisig.
pub warnings: Option<Vec<String>>,
}

/// Models the result of JSON-RPC method `bumpfee`.
Expand Down
2 changes: 1 addition & 1 deletion types/src/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
//! |:-----------------------------------|:---------------:|:--------------------------------------:|
//! | abandontransaction | returns nothing | |
//! | abortrescan | version | |
//! | addmultisigaddress | version + model | UNTESTED |
//! | addmultisigaddress | version + model | |
//! | backupwallet | returns nothing | |
//! | bumpfee | version + model | |
//! | createwallet | version + model | |
Expand Down
7 changes: 6 additions & 1 deletion types/src/v17/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ impl AddMultisigAddress {
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
let redeem_script = ScriptBuf::from_hex(&self.redeem_script).map_err(E::RedeemScript)?;

Ok(model::AddMultisigAddress { address, redeem_script })
Ok(model::AddMultisigAddress {
address,
redeem_script,
descriptor: None, // v20 and later only.
warnings: None, // v23 and later only.
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
//! |:-----------------------------------|:---------------:|:--------------------------------------:|
//! | abandontransaction | returns nothing | |
//! | abortrescan | version | |
//! | addmultisigaddress | version + model | UNTESTED |
//! | addmultisigaddress | version + model | |
//! | backupwallet | returns nothing | |
//! | bumpfee | version + model | |
//! | createwallet | version + model | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
//! |:-----------------------------------|:---------------:|:--------------------------------------:|
//! | abandontransaction | returns nothing | |
//! | abortrescan | version | |
//! | addmultisigaddress | version + model | UNTESTED |
//! | addmultisigaddress | version + model | |
//! | backupwallet | returns nothing | |
//! | bumpfee | version + model | |
//! | createwallet | version + model | |
Expand Down
67 changes: 35 additions & 32 deletions types/src/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
//! |:-----------------------------------|:---------------:|:--------------------------------------:|
//! | abandontransaction | returns nothing | |
//! | abortrescan | version | |
//! | addmultisigaddress | version + model | UNTESTED |
//! | addmultisigaddress | version + model | |
//! | backupwallet | returns nothing | |
//! | bumpfee | version + model | |
//! | createwallet | version + model | |
Expand Down Expand Up @@ -238,41 +238,44 @@ pub use self::{
generating::GenerateToDescriptor,
network::{Banned, ListBanned},
util::CreateMultisig,
wallet::{GetAddressInfo, GetAddressInfoEmbedded, GetTransaction, GetTransactionDetail},
wallet::{
AddMultisigAddress, GetAddressInfo, GetAddressInfoEmbedded, GetTransaction,
GetTransactionDetail,
},
};
#[doc(inline)]
pub use crate::{
v17::{
AbortRescan, AddMultisigAddress, AddMultisigAddressError, AddedNode, AddedNodeAddress,
AddressInformation, Bip125Replaceable, BumpFee, BumpFeeError, ChainTips, ChainTipsError,
ChainTipsStatus, CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisigError,
CreatePsbt, CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError,
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet,
EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo,
GetAddressInfoEmbeddedError, GetAddressesByLabel, GetBalance, GetBestBlockHash,
GetBlockCount, GetBlockHash, GetBlockHeader, GetBlockHeaderError, GetBlockHeaderVerbose,
GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError, GetBlockTemplate,
GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError, GetBlockVerboseZero,
GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats,
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
GetRawMempool, GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetailError,
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError, GetZmqNotifications,
ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem, ListLabels,
ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddress,
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, ScriptType, SendMany, SendRawTransaction,
SendToAddress, SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey,
SignRawTransaction, SignRawTransactionError, SoftforkReject, TestMempoolAccept,
TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain,
VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
WalletProcessPsbt, WitnessUtxo,
AbortRescan, AddMultisigAddressError, AddedNode, AddedNodeAddress, AddressInformation,
Bip125Replaceable, BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus,
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisigError, CreatePsbt,
CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError, DecodeRawTransaction,
DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee,
FinalizePsbt, FinalizePsbtError, FundRawTransaction, FundRawTransactionError, Generate,
GenerateToAddress, GetAddedNodeInfo, GetAddressInfoEmbeddedError, GetAddressesByLabel,
GetBalance, GetBestBlockHash, GetBlockCount, GetBlockHash, GetBlockHeader,
GetBlockHeaderError, GetBlockHeaderVerbose, GetBlockHeaderVerboseError, GetBlockStats,
GetBlockStatsError, GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne,
GetBlockVerboseOneError, GetBlockVerboseZero, GetChainTips, GetChainTxStatsError,
GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo,
GetNetTotals, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
GetNewAddress, GetRawChangeAddress, GetRawMempool, GetRawMempoolVerbose, GetRawTransaction,
GetRawTransactionVerbose, GetRawTransactionVerboseError, GetReceivedByAddress,
GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError,
GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError,
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
WitnessUtxo,
},
v18::{
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
Expand Down
22 changes: 20 additions & 2 deletions types/src/v20/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@ use bitcoin::{
};

use super::{
GetAddressInfo, GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetTransaction, GetTransactionDetail, GetTransactionDetailError, GetTransactionError,
AddMultisigAddress, AddMultisigAddressError, GetAddressInfo, GetAddressInfoEmbedded,
GetAddressInfoEmbeddedError, GetAddressInfoError, GetTransaction, GetTransactionDetail,
GetTransactionDetailError, GetTransactionError,
};
use crate::model;

impl AddMultisigAddress {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::AddMultisigAddress, AddMultisigAddressError> {
use AddMultisigAddressError as E;

let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
let redeem_script = ScriptBuf::from_hex(&self.redeem_script).map_err(E::RedeemScript)?;

Ok(model::AddMultisigAddress {
address,
redeem_script,
descriptor: Some(self.descriptor),
warnings: None, // v23 and later only.
})
}
}

impl GetAddressInfo {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetAddressInfo, GetAddressInfoError> {
Expand Down
29 changes: 27 additions & 2 deletions types/src/v20/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,35 @@ use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use super::{
Bip125Replaceable, GetAddressInfoEmbeddedError, GetAddressInfoError, GetTransactionDetailError,
GetTransactionError, ScriptType, TransactionCategory,
AddMultisigAddressError, Bip125Replaceable, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetTransactionDetailError, GetTransactionError, ScriptType, TransactionCategory,
};

/// Result of the JSON-RPC method `addmultisigaddress`.
///
/// > addmultisigaddress nrequired ["key",...] ( "label" "address_type" )
/// >
/// > Add a nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.
/// > Each key is a Bitcoin address or hex-encoded public key.
/// > This functionality is only intended for use with non-watchonly addresses.
/// > See `importaddress` for watchonly p2sh address support.
/// > If 'label' is specified, assign address to that label.
///
/// > Arguments:
/// > 1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.
/// > 2. "keys" (string, required) A json array of bitcoin addresses or hex-encoded public keys
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct AddMultisigAddress {
/// The value of the new multisig address.
pub address: String,
/// The string value of the hex-encoded redemption script.
#[serde(rename = "redeemScript")]
pub redeem_script: String,
/// The descriptor for this multisig.
pub descriptor: String,
}

/// Result of the JSON-RPC method `getaddressinfo`.
///
/// > getaddressinfo "address"
Expand Down
12 changes: 6 additions & 6 deletions types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
//! |:-----------------------------------|:---------------:|:--------------------------------------:|
//! | abandontransaction | returns nothing | |
//! | abortrescan | version | |
//! | addmultisigaddress | version + model | UNTESTED |
//! | addmultisigaddress | version + model | |
//! | backupwallet | returns nothing | |
//! | bumpfee | version + model | |
//! | createwallet | version + model | |
Expand Down Expand Up @@ -260,9 +260,9 @@ pub use self::{
#[doc(inline)]
pub use crate::{
v17::{
AbortRescan, AddMultisigAddress, AddMultisigAddressError, AddedNode, AddedNodeAddress,
AddressInformation, BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus,
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisigError, CreatePsbt,
AbortRescan, AddMultisigAddressError, AddedNode, AddedNodeAddress, AddressInformation,
BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus, CombinePsbt,
CombineRawTransaction, ConvertToPsbt, CreateMultisigError, CreatePsbt,
CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError, DecodeRawTransaction,
DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee,
FinalizePsbt, FinalizePsbtError, FundRawTransaction, FundRawTransactionError, Generate,
Expand Down Expand Up @@ -304,7 +304,7 @@ pub use crate::{
MempoolEntryFees, MempoolEntryFeesError, SetWalletFlag,
},
v20::{
Banned, CreateMultisig, GenerateToDescriptor, GetAddressInfo, GetAddressInfoEmbedded,
GetTransaction, GetTransactionDetail, ListBanned, Logging,
AddMultisigAddress, Banned, CreateMultisig, GenerateToDescriptor, GetAddressInfo,
GetAddressInfoEmbedded, GetTransaction, GetTransactionDetail, ListBanned, Logging,
},
};
13 changes: 8 additions & 5 deletions types/src/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
//! |:-----------------------------------|:---------------:|:--------------------------------------:|
//! | abandontransaction | returns nothing | |
//! | abortrescan | version | |
//! | addmultisigaddress | version + model | UNTESTED |
//! | addmultisigaddress | version + model | |
//! | backupwallet | returns nothing | |
//! | bumpfee | version + model | |
//! | createwallet | version + model | |
Expand Down Expand Up @@ -265,9 +265,9 @@ pub use self::{
#[doc(inline)]
pub use crate::{
v17::{
AbortRescan, AddMultisigAddress, AddMultisigAddressError, AddedNode, AddedNodeAddress,
AddressInformation, BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus,
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisigError, CreatePsbt,
AbortRescan, AddMultisigAddressError, AddedNode, AddedNodeAddress, AddressInformation,
BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus, CombinePsbt,
CombineRawTransaction, ConvertToPsbt, CreateMultisigError, CreatePsbt,
CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError, DecodeRawTransaction,
DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError,
FundRawTransaction, FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo,
Expand Down Expand Up @@ -308,7 +308,10 @@ pub use crate::{
GetChainTxStats, GetDescriptorInfo, GetRpcInfo, MapMempoolEntryError, MempoolEntryError,
MempoolEntryFees, MempoolEntryFeesError, SetWalletFlag,
},
v20::{CreateMultisig, GenerateToDescriptor, GetTransaction, GetTransactionDetail},
v20::{
AddMultisigAddress, CreateMultisig, GenerateToDescriptor, GetTransaction,
GetTransactionDetail,
},
v21::{
Bip9SoftforkInfo, GenerateBlock, GetBlockchainInfo, GetIndexInfo, GetIndexInfoName,
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
Expand Down
Loading