Skip to content

Commit cdec760

Browse files
author
+Sharon
committed
Add DecodeScriptSegwit struct and support in DecodeScript conversion
- Add `DecodeScriptSegwit` struct to model the `segwit` field returned by the `decodescript` RPC. - Update `DecodeScript` to include an optional `segwit` field. Add DecodeScriptSegwit struct, conversions, and model support - Add `DecodeScriptSegwit` struct to both versioned and model representations. - Implement `into_model()` for `DecodeScriptSegwit` and update `DecodeScript` accordingly. - Use `ScriptBuf` instead of `String` for `hex` to strongly type the field. - Replace `String` with `Address<NetworkUnchecked>` for `p2sh_segwit` and other fields. - Normalize and correct field comments to match Core `decodescript` RPC output. - Clean up formatting errors Add DecodeScriptSegwit into_model to v17 and refactor error handling - Add `into_model` implementation for `DecodeScriptSegwit` in v17. - Return `segwit` in v17, as it is present in RPC output despite not being documented until v19. - Add `DecodeScriptSegwitError` enum in v17, as `address` is sometimes `None` and error handling is needed. - Remove duplicate `DecodeScriptSegwitError` from v23 and reuse the one from v22 via import. - Move `descriptor` field in `DecodeScriptSegwit` model struct to match the field order in Bitcoin Core's `decodescript` RPC response. Add model test for decode_script with P2WPKH SegWit output Add model test for decode_script_segwit
1 parent 874db20 commit cdec760

File tree

9 files changed

+226
-165
lines changed

9 files changed

+226
-165
lines changed

integration_test/tests/raw_transactions.rs

Lines changed: 188 additions & 130 deletions
Large diffs are not rendered by default.

types/src/model/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ pub use self::{
4141
raw_transactions::{
4242
AnalyzePsbt, AnalyzePsbtInput, AnalyzePsbtInputMissing, CombinePsbt, CombineRawTransaction,
4343
ConvertToPsbt, CreatePsbt, CreateRawTransaction, DecodePsbt, DecodeRawTransaction,
44-
DecodeScript, DecodeScriptSegwit, DescriptorProcessPsbt, FinalizePsbt, FundRawTransaction, GetRawTransaction,
45-
GetRawTransactionVerbose, JoinPsbts, MempoolAcceptance, MempoolAcceptanceFees,
46-
SendRawTransaction, SignFail, SignRawTransaction, SignRawTransactionWithKey, SubmitPackage,
47-
SubmitPackageTxResult, SubmitPackageTxResultFees, TestMempoolAccept, UtxoUpdatePsbt,
44+
DecodeScript, DecodeScriptSegwit, DescriptorProcessPsbt, FinalizePsbt, FundRawTransaction,
45+
GetRawTransaction, GetRawTransactionVerbose, JoinPsbts, MempoolAcceptance,
46+
MempoolAcceptanceFees, SendRawTransaction, SignFail, SignRawTransaction,
47+
SignRawTransactionWithKey, SubmitPackage, SubmitPackageTxResult, SubmitPackageTxResultFees,
48+
TestMempoolAccept, UtxoUpdatePsbt,
4849
},
4950
util::{
5051
CreateMultisig, DeriveAddresses, DeriveAddressesMultipath, EstimateSmartFee,

types/src/model/raw_transactions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub struct DecodeScript {
119119
/// Result of a witness output script wrapping this redeem script (not returned for types that should not be wrapped).
120120
pub segwit: Option<DecodeScriptSegwit>,
121121
}
122+
122123
/// Models the `segwit` field returned by the `decodescript` RPC.
123124
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
124125
#[serde(deny_unknown_fields)]

types/src/v17/raw_transactions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ pub struct DecodeScript {
230230
pub addresses: Option<Vec<String>>,
231231
/// Address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).
232232
pub p2sh: Option<String>,
233+
/// Result of a witness output script wrapping this redeem script (not returned for types that should not be wrapped).
234+
pub segwit: Option<DecodeScriptSegwit>,
233235
}
234236

235237
/// Segwit data. Part of `decodescript`.

types/src/v19/mod.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -259,30 +259,29 @@ pub use crate::v17::{
259259
AddressInformation, Banned, Bip125Replaceable, BumpFee, BumpFeeError, ChainTips,
260260
ChainTipsError, ChainTipsStatus, CombinePsbt, CombineRawTransaction, ConvertToPsbt,
261261
CreateMultisig, CreateMultisigError, CreatePsbt, CreateRawTransaction, CreateWallet,
262-
DecodePsbt, DecodePsbtError, DecodeRawTransaction, DecodeScript, DecodeScriptError,
263-
DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError,
264-
FundRawTransaction, FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo,
265-
GetAddressInfoEmbeddedError, GetAddressInfoLabel, GetAddressesByLabel, GetBalance,
266-
GetBestBlockHash, GetBlockCount, GetBlockHash, GetBlockHeader, GetBlockHeaderError,
267-
GetBlockHeaderVerbose, GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError,
268-
GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError,
269-
GetBlockVerboseZero, GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty,
270-
GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
271-
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, GetRawMempool,
272-
GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
273-
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetail,
274-
GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
275-
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings,
276-
ListAddressGroupingsError, ListAddressGroupingsItem, ListBanned, ListLabels, ListLockUnspent,
277-
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError, ListSinceBlock,
278-
ListSinceBlockError, ListTransactions, ListUnspentItemError, ListWallets, LoadWallet,
279-
LockUnspent, Locked, Logging, NumericError, PruneBlockchain, RawTransactionError,
280-
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType, SendMany,
281-
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,
282-
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey,
283-
SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept, TransactionCategory,
284-
TransactionItem, TransactionItemError, UploadTarget, ValidateAddress, ValidateAddressError,
285-
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
262+
DecodePsbt, DecodePsbtError, DecodeRawTransaction, DumpPrivKey, DumpWallet, EncryptWallet,
263+
EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction, FundRawTransactionError,
264+
Generate, GenerateToAddress, GetAddedNodeInfo, GetAddressInfoEmbeddedError,
265+
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash, GetBlockCount,
266+
GetBlockHash, GetBlockHeader, GetBlockHeaderError, GetBlockHeaderVerbose,
267+
GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError, GetBlockTemplate,
268+
GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError, GetBlockVerboseZero,
269+
GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats,
270+
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress, GetNetworkInfoError,
271+
GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, GetRawMempool, GetRawMempoolVerbose,
272+
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
273+
GetReceivedByAddress, GetTransactionDetail, GetTransactionDetailError, GetTransactionError,
274+
GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
275+
GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem,
276+
ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
277+
ListReceivedByAddressError, ListSinceBlock, ListSinceBlockError, ListTransactions,
278+
ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked, Logging, NumericError,
279+
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
280+
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
281+
SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
282+
SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept,
283+
TransactionCategory, TransactionItem, TransactionItemError, UploadTarget, ValidateAddress,
284+
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
286285
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
287286
};
288287
#[doc(inline)]

types/src/v22/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ pub use self::{
256256
control::Logging,
257257
network::{Banned, GetNodeAddresses, GetPeerInfo, ListBanned, NodeAddress, PeerInfo},
258258
raw_transactions::{
259-
DecodeScript, DecodeScriptError, DecodeScriptSegwit, DecodeScriptSegwitError, MempoolAcceptance, MempoolAcceptanceError,
260-
TestMempoolAccept, TestMempoolAcceptError,
259+
DecodeScript, DecodeScriptError, DecodeScriptSegwit, DecodeScriptSegwitError,
260+
MempoolAcceptance, MempoolAcceptanceError, TestMempoolAccept, TestMempoolAcceptError,
261261
},
262262
signer::EnumerateSigners,
263263
wallet::{GetAddressInfo, GetAddressInfoEmbedded, ListDescriptors, WalletDisplayAddress},

types/src/v22/raw_transactions/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use bitcoin::amount::ParseAmountError;
77
use bitcoin::{address, hex};
88

99
use crate::error::write_err;
10-
use crate::NumericError;
1110
use crate::v19::DecodeScriptSegwitError;
11+
use crate::NumericError;
1212

1313
/// Error when converting a `DecodeScript` type into the model type.
1414
#[derive(Debug)]

types/src/v22/raw_transactions/into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use bitcoin::{Address, Amount, Txid, Wtxid};
44

55
use super::{
6-
DecodeScript, DecodeScriptError,DecodeScriptSegwit,DecodeScriptSegwitError, MempoolAcceptance, MempoolAcceptanceError, TestMempoolAccept,
7-
TestMempoolAcceptError,
6+
DecodeScript, DecodeScriptError, DecodeScriptSegwit, DecodeScriptSegwitError,
7+
MempoolAcceptance, MempoolAcceptanceError, TestMempoolAccept, TestMempoolAcceptError,
88
};
99
use crate::model;
1010

types/src/v23/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ pub use self::{
254254
control::Logging,
255255
network::{GetPeerInfo, PeerInfo},
256256
raw_transactions::{
257-
DecodePsbt, DecodePsbtError, DecodeScript, DecodeScriptError, DecodeScriptSegwit,DecodeScriptSegwitError,
258-
GlobalXpub, Proprietary, PsbtInput, PsbtOutput,
257+
DecodePsbt, DecodePsbtError, DecodeScript, DecodeScriptError, DecodeScriptSegwit,
258+
DecodeScriptSegwitError, GlobalXpub, Proprietary, PsbtInput, PsbtOutput,
259259
},
260260
util::CreateMultisig,
261261
wallet::{

0 commit comments

Comments
 (0)