From 158eeaaff99e5e1e6285591e47ec3cbc0fc9b748 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 18 Feb 2026 11:38:24 +0000 Subject: [PATCH 1/4] Move GetBlockchainInfo into_model to into module To be consistent with other types move the into_model function to the into module. --- types/src/v28/blockchain/into.rs | 50 ++++++++++++++++++++++++++++++-- types/src/v28/blockchain/mod.rs | 43 --------------------------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/types/src/v28/blockchain/into.rs b/types/src/v28/blockchain/into.rs index 063c2cbdf..cb0b3ad9e 100644 --- a/types/src/v28/blockchain/into.rs +++ b/types/src/v28/blockchain/into.rs @@ -1,10 +1,56 @@ // SPDX-License-Identifier: CC0-1.0 -use bitcoin::{Amount, BlockHash, ScriptBuf, Txid}; +use alloc::collections::BTreeMap; -use super::{ScanTxOutSetError, ScanTxOutSetStart, ScanTxOutSetUnspent}; +use bitcoin::{Amount, BlockHash, Network, ScriptBuf, Txid, Work}; + +use super::{ + GetBlockchainInfo, GetBlockchainInfoError, ScanTxOutSetError, ScanTxOutSetStart, + ScanTxOutSetUnspent, +}; use crate::model; +impl GetBlockchainInfo { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use GetBlockchainInfoError as E; + + let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?; + let best_block_hash = + self.best_block_hash.parse::().map_err(E::BestBlockHash)?; + let time = Some(crate::to_u32(self.time, "time")?); + let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?; + let prune_height = + self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?; + let prune_target_size = + self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?; + let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. + + Ok(model::GetBlockchainInfo { + chain, + blocks: crate::to_u32(self.blocks, "blocks")?, + headers: crate::to_u32(self.headers, "headers")?, + best_block_hash, + bits: None, + target: None, + difficulty: self.difficulty, + time, + median_time: crate::to_u32(self.median_time, "median_time")?, + verification_progress: self.verification_progress, + initial_block_download: self.initial_block_download, + chain_work, + size_on_disk: self.size_on_disk, + pruned: self.pruned, + prune_height, + automatic_pruning: self.automatic_pruning, + prune_target_size, + softforks, + signet_challenge: None, + warnings: self.warnings, + }) + } +} + impl ScanTxOutSetStart { /// Converts version specific type to a version nonspecific, more strongly typed type. pub fn into_model(self) -> Result { diff --git a/types/src/v28/blockchain/mod.rs b/types/src/v28/blockchain/mod.rs index 2c974624c..f34dd48aa 100644 --- a/types/src/v28/blockchain/mod.rs +++ b/types/src/v28/blockchain/mod.rs @@ -8,11 +8,9 @@ mod into; use alloc::collections::BTreeMap; -use bitcoin::{BlockHash, Network, Work}; use serde::{Deserialize, Serialize}; use super::{GetBlockchainInfoError, ScanTxOutSetError, Softfork}; -use crate::model; /// Result of JSON-RPC method `getblockchaininfo`. /// @@ -65,47 +63,6 @@ pub struct GetBlockchainInfo { pub warnings: Vec, } -impl GetBlockchainInfo { - /// Converts version specific type to a version nonspecific, more strongly typed type. - pub fn into_model(self) -> Result { - use GetBlockchainInfoError as E; - - let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?; - let best_block_hash = - self.best_block_hash.parse::().map_err(E::BestBlockHash)?; - let time = Some(crate::to_u32(self.time, "time")?); - let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?; - let prune_height = - self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?; - let prune_target_size = - self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?; - let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. - - Ok(model::GetBlockchainInfo { - chain, - blocks: crate::to_u32(self.blocks, "blocks")?, - headers: crate::to_u32(self.headers, "headers")?, - best_block_hash, - bits: None, - target: None, - difficulty: self.difficulty, - time, - median_time: crate::to_u32(self.median_time, "median_time")?, - verification_progress: self.verification_progress, - initial_block_download: self.initial_block_download, - chain_work, - size_on_disk: self.size_on_disk, - pruned: self.pruned, - prune_height, - automatic_pruning: self.automatic_pruning, - prune_target_size, - softforks, - signet_challenge: None, - warnings: self.warnings, - }) - } -} - /// Result of JSON-RPC method `scantxoutset`. /// /// > scantxoutset "action" ( [scanobjects,...] ) From 4e106abfbdf4b275392f0dcc55e9bbacc617ab1c Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 18 Feb 2026 11:49:16 +0000 Subject: [PATCH 2/4] Remove concrete bitcoin type from GetOrphanTxs Use String instead of Txid in GetOrphanTxs. Add the error type for conversion into a Txid. Fix the into_model function to convert the String to a Txid. --- integration_test/tests/hidden.rs | 2 +- types/src/v29/hidden/error.rs | 24 ++++++++++++++++++++++++ types/src/v29/hidden/into.rs | 14 ++++++++++++-- types/src/v29/hidden/mod.rs | 7 ++++--- types/src/v29/mod.rs | 2 +- types/src/v30/hidden/into.rs | 14 ++++++++++++-- types/src/v30/hidden/mod.rs | 4 ++-- types/src/v30/mod.rs | 7 ++++--- 8 files changed, 60 insertions(+), 14 deletions(-) diff --git a/integration_test/tests/hidden.rs b/integration_test/tests/hidden.rs index 92d22bb86..c7bb6caac 100644 --- a/integration_test/tests/hidden.rs +++ b/integration_test/tests/hidden.rs @@ -150,7 +150,7 @@ fn hidden__get_orphan_txs__modelled() { let json_v2: GetOrphanTxsVerboseTwo = node2.client.get_orphan_txs_verbosity_2().expect("getorphantxs 2"); - let model_v0: mtype::GetOrphanTxs = json_v0.into_model(); + let model_v0: mtype::GetOrphanTxs = json_v0.into_model().unwrap(); let model_v1: mtype::GetOrphanTxsVerboseOne = json_v1.into_model().unwrap(); let model_v2: mtype::GetOrphanTxsVerboseTwo = json_v2.into_model().unwrap(); diff --git a/types/src/v29/hidden/error.rs b/types/src/v29/hidden/error.rs index 93a62dd30..c7bd896c3 100644 --- a/types/src/v29/hidden/error.rs +++ b/types/src/v29/hidden/error.rs @@ -7,6 +7,30 @@ use bitcoin::hex; use crate::error::write_err; +/// Error when converting a `GetOrphanTxs` type into the model type. +#[derive(Debug)] +pub enum GetOrphanTxsError { + /// Conversion of the `txid` field failed. + Txid(hex::HexToArrayError), +} + +impl fmt::Display for GetOrphanTxsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Self::Txid(ref e) => write_err!(f, "conversion of a txid list element failed"; e), + } + } +} + +#[cfg(feature = "std")] +impl std::error::Error for GetOrphanTxsError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match *self { + Self::Txid(ref e) => Some(e), + } + } +} + /// Error when converting a `GetOrphanTxsVerboseOneEntry` type into the model type. #[derive(Debug)] pub enum GetOrphanTxsVerboseOneEntryError { diff --git a/types/src/v29/hidden/into.rs b/types/src/v29/hidden/into.rs index 6f62dcaa9..833108163 100644 --- a/types/src/v29/hidden/into.rs +++ b/types/src/v29/hidden/into.rs @@ -5,7 +5,7 @@ use bitcoin::hashes::hex::FromHex; use bitcoin::{Transaction, Txid, Wtxid}; use super::{ - GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, + GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry, GetOrphanTxsVerboseTwoEntryError, }; @@ -13,7 +13,17 @@ use crate::model; impl GetOrphanTxs { /// Converts version specific type to a version nonspecific, more strongly typed type. - pub fn into_model(self) -> model::GetOrphanTxs { model::GetOrphanTxs(self.0) } + pub fn into_model(self) -> Result { + use GetOrphanTxsError as E; + + let txids = self + .0 + .into_iter() + .map(|t| t.parse::().map_err(E::Txid)) + .collect::, _>>()?; + + Ok(model::GetOrphanTxs(txids)) + } } impl GetOrphanTxsVerboseOneEntry { diff --git a/types/src/v29/hidden/mod.rs b/types/src/v29/hidden/mod.rs index 366a01b47..6192ba594 100644 --- a/types/src/v29/hidden/mod.rs +++ b/types/src/v29/hidden/mod.rs @@ -7,10 +7,11 @@ mod error; mod into; -use bitcoin::Txid; use serde::{Deserialize, Serialize}; -pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEntryError}; +pub use self::error::{ + GetOrphanTxsError, GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEntryError, +}; /// Result of JSON-RPC method `getorphantxs` verbosity 0. /// @@ -19,7 +20,7 @@ pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEn /// > Shows transactions in the tx orphanage. #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))] -pub struct GetOrphanTxs(pub Vec); +pub struct GetOrphanTxs(pub Vec); /// Result of JSON-RPC method `getorphantxs` verbosity 1. /// diff --git a/types/src/v29/mod.rs b/types/src/v29/mod.rs index 687585cbd..ed59ceed4 100644 --- a/types/src/v29/mod.rs +++ b/types/src/v29/mod.rs @@ -270,7 +270,7 @@ pub use self::{ SpendActivity, }, hidden::{ - GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, + GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry, GetOrphanTxsVerboseTwoEntryError, }, diff --git a/types/src/v30/hidden/into.rs b/types/src/v30/hidden/into.rs index e4ab66bc7..5c773652a 100644 --- a/types/src/v30/hidden/into.rs +++ b/types/src/v30/hidden/into.rs @@ -5,7 +5,7 @@ use bitcoin::hashes::hex::FromHex; use bitcoin::{Transaction, Txid, Wtxid}; use super::{ - GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, + GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry, GetOrphanTxsVerboseTwoEntryError, }; @@ -13,7 +13,17 @@ use crate::model; impl GetOrphanTxs { /// Converts version specific type to a version nonspecific, more strongly typed type. - pub fn into_model(self) -> model::GetOrphanTxs { model::GetOrphanTxs(self.0) } + pub fn into_model(self) -> Result { + use GetOrphanTxsError as E; + + let txids = self + .0 + .into_iter() + .map(|t| t.parse::().map_err(E::Txid)) + .collect::, _>>()?; + + Ok(model::GetOrphanTxs(txids)) + } } impl GetOrphanTxsVerboseOneEntry { diff --git a/types/src/v30/hidden/mod.rs b/types/src/v30/hidden/mod.rs index 1d899fac4..e6632d6d5 100644 --- a/types/src/v30/hidden/mod.rs +++ b/types/src/v30/hidden/mod.rs @@ -7,10 +7,10 @@ mod error; mod into; -use bitcoin::Txid; use serde::{Deserialize, Serialize}; pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEntryError}; +pub use super::GetOrphanTxsError; /// Result of JSON-RPC method `getorphantxs` verbosity 0. /// @@ -19,7 +19,7 @@ pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEn /// > Shows transactions in the tx orphanage. #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))] -pub struct GetOrphanTxs(pub Vec); +pub struct GetOrphanTxs(pub Vec); /// Result of JSON-RPC method `getorphantxs` verbosity 1. /// diff --git a/types/src/v30/mod.rs b/types/src/v30/mod.rs index a90a173c6..e685211eb 100644 --- a/types/src/v30/mod.rs +++ b/types/src/v30/mod.rs @@ -364,8 +364,9 @@ pub use crate::{ GetBlockVerboseThreePrevout, GetBlockVerboseThreeTransaction, GetBlockVerboseTwo, GetBlockVerboseTwoError, GetBlockVerboseTwoTransaction, GetBlockchainInfo, GetBlockchainInfoError, GetChainStates, GetChainStatesError, GetDescriptorActivity, - GetDescriptorActivityError, GetDescriptorInfo, GetRawTransactionVerboseWithPrevout, - MempoolAcceptance, MempoolAcceptanceFees, NextBlockInfo, NextBlockInfoError, - RawTransactionInputWithPrevout, ReceiveActivity, SpendActivity, TestMempoolAccept, + GetDescriptorActivityError, GetDescriptorInfo, GetOrphanTxsError, + GetRawTransactionVerboseWithPrevout, MempoolAcceptance, MempoolAcceptanceFees, + NextBlockInfo, NextBlockInfoError, RawTransactionInputWithPrevout, ReceiveActivity, + SpendActivity, TestMempoolAccept, }, }; From 0a565a6a778d78bbac31caad8462bde59e27980a Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 18 Feb 2026 11:49:46 +0000 Subject: [PATCH 3/4] Move bitcoin imports to into module The bitcoin types are only used in the into module. Move the imports to make it clearer that no concrete bitcoin types are used until the conversion into the modeled type. --- types/src/v17/blockchain/into.rs | 6 +++++- types/src/v17/blockchain/mod.rs | 2 -- types/src/v29/blockchain/into.rs | 4 ++-- types/src/v29/blockchain/mod.rs | 2 -- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/src/v17/blockchain/into.rs b/types/src/v17/blockchain/into.rs index 9a6497459..27ef92fb5 100644 --- a/types/src/v17/blockchain/into.rs +++ b/types/src/v17/blockchain/into.rs @@ -1,7 +1,11 @@ // SPDX-License-Identifier: CC0-1.0 use bitcoin::consensus::encode; -use bitcoin::{block, hex, Block, BlockHash, CompactTarget, ScriptBuf, Txid, Weight, Work}; +use bitcoin::hex::FromHex; +use bitcoin::{ + block, hex, Amount, Block, BlockHash, CompactTarget, FeeRate, Network, ScriptBuf, TxMerkleNode, + TxOut, Txid, Weight, Work, Wtxid, +}; // TODO: Use explicit imports? use super::*; diff --git a/types/src/v17/blockchain/mod.rs b/types/src/v17/blockchain/mod.rs index 443e81dbb..08e86c0b6 100644 --- a/types/src/v17/blockchain/mod.rs +++ b/types/src/v17/blockchain/mod.rs @@ -9,8 +9,6 @@ mod into; use alloc::collections::BTreeMap; -use bitcoin::hex::FromHex; -use bitcoin::{Amount, FeeRate, Network, TxMerkleNode, TxOut, Wtxid}; use serde::{Deserialize, Serialize}; // TODO: Remove wildcard, use explicit types. diff --git a/types/src/v29/blockchain/into.rs b/types/src/v29/blockchain/into.rs index 5525d6d84..3f60d4714 100644 --- a/types/src/v29/blockchain/into.rs +++ b/types/src/v29/blockchain/into.rs @@ -6,8 +6,8 @@ use core::str::FromStr; use bitcoin::consensus::encode; use bitcoin::hashes::hex::FromHex; use bitcoin::{ - absolute, block, hex, transaction, Amount, BlockHash, CompactTarget, ScriptBuf, Target, - Transaction, Txid, Weight, Work, + absolute, block, hex, transaction, Amount, BlockHash, CompactTarget, Network, ScriptBuf, + Target, Transaction, TxMerkleNode, Txid, Weight, Work, }; // TODO: Use explicit imports? diff --git a/types/src/v29/blockchain/mod.rs b/types/src/v29/blockchain/mod.rs index cb6a98118..5065fa0c6 100644 --- a/types/src/v29/blockchain/mod.rs +++ b/types/src/v29/blockchain/mod.rs @@ -8,8 +8,6 @@ use serde::{Deserialize, Serialize}; mod error; mod into; -use bitcoin::{Network, TxMerkleNode}; - pub use self::error::{ GetBlockHeaderError, GetBlockHeaderVerboseError, GetBlockVerboseOneError, GetBlockVerboseThreeError, GetBlockVerboseTwoError, GetBlockchainInfoError, From 825e15daff97fbb3bc5519d06d46badfba0c14e9 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 18 Feb 2026 11:32:28 +0000 Subject: [PATCH 4/4] Remove concrete bitcoin type from GetTransaction Use String instead of Transaction in GetTransaction. Fix the into_model function to convert the String into a Transaction. --- types/src/v19/wallet/into.rs | 6 +++++- types/src/v19/wallet/mod.rs | 3 +-- types/src/v20/wallet/into.rs | 6 +++++- types/src/v20/wallet/mod.rs | 3 +-- types/src/v23/wallet/into.rs | 6 +++++- types/src/v23/wallet/mod.rs | 3 +-- types/src/v24/wallet/into.rs | 6 +++++- types/src/v24/wallet/mod.rs | 3 +-- types/src/v26/wallet/into.rs | 6 +++++- types/src/v26/wallet/mod.rs | 3 +-- types/src/v28/wallet/into.rs | 6 +++++- types/src/v28/wallet/mod.rs | 3 +-- 12 files changed, 36 insertions(+), 18 deletions(-) diff --git a/types/src/v19/wallet/into.rs b/types/src/v19/wallet/into.rs index 8162336e6..3299edb96 100644 --- a/types/src/v19/wallet/into.rs +++ b/types/src/v19/wallet/into.rs @@ -73,6 +73,10 @@ impl GetTransaction { .into_iter() .map(|d| d.into_model().map_err(E::Details)) .collect::, _>>()?; + let decoded = self + .decoded + .map(|tx| encode::deserialize_hex::(&tx).map_err(E::Tx)) + .transpose()?; Ok(model::GetTransaction { amount, @@ -97,7 +101,7 @@ impl GetTransaction { bip125_replaceable: self.bip125_replaceable.into_model(), parent_descriptors: None, // v24 and later only. details, - decoded: self.decoded, + decoded, last_processed_block: None, // v26 and later only. tx, }) diff --git a/types/src/v19/wallet/mod.rs b/types/src/v19/wallet/mod.rs index 94375dcb6..dd9a5e9af 100644 --- a/types/src/v19/wallet/mod.rs +++ b/types/src/v19/wallet/mod.rs @@ -7,7 +7,6 @@ mod error; mod into; -use bitcoin::Transaction; use serde::{Deserialize, Serialize}; pub use self::error::GetBalancesError; @@ -104,7 +103,7 @@ pub struct GetTransaction { /// Raw data for transaction. pub hex: String, /// The decoded transaction (only present when `verbose` is passed). - pub decoded: Option, + pub decoded: Option, } /// Result of the JSON-RPC method `getwalletinfo`. diff --git a/types/src/v20/wallet/into.rs b/types/src/v20/wallet/into.rs index 7245350a3..66009cb64 100644 --- a/types/src/v20/wallet/into.rs +++ b/types/src/v20/wallet/into.rs @@ -198,6 +198,10 @@ impl GetTransaction { .into_iter() .map(|d| d.into_model().map_err(E::Details)) .collect::, _>>()?; + let decoded = self + .decoded + .map(|tx| encode::deserialize_hex::(&tx).map_err(E::Tx)) + .transpose()?; Ok(model::GetTransaction { amount, @@ -222,7 +226,7 @@ impl GetTransaction { bip125_replaceable: self.bip125_replaceable.into_model(), parent_descriptors: None, // v24 and later only. details, - decoded: self.decoded, + decoded, last_processed_block: None, // v26 and later only. tx, }) diff --git a/types/src/v20/wallet/mod.rs b/types/src/v20/wallet/mod.rs index a6da1b44f..4abf8d86f 100644 --- a/types/src/v20/wallet/mod.rs +++ b/types/src/v20/wallet/mod.rs @@ -7,7 +7,6 @@ mod error; mod into; -use bitcoin::Transaction; use serde::{Deserialize, Serialize}; pub use self::error::{ListSinceBlockError, TransactionItemError}; @@ -221,7 +220,7 @@ pub struct GetTransaction { /// Raw data for transaction. pub hex: String, /// The decoded transaction (only present when `verbose` is passed). - pub decoded: Option, + pub decoded: Option, } /// Transaction detail. Part of the `gettransaction`. diff --git a/types/src/v23/wallet/into.rs b/types/src/v23/wallet/into.rs index 75601a188..2261e1188 100644 --- a/types/src/v23/wallet/into.rs +++ b/types/src/v23/wallet/into.rs @@ -58,6 +58,10 @@ impl GetTransaction { .into_iter() .map(|d| d.into_model().map_err(E::Details)) .collect::, _>>()?; + let decoded = self + .decoded + .map(|tx| encode::deserialize_hex::(&tx).map_err(E::Tx)) + .transpose()?; Ok(model::GetTransaction { amount, @@ -82,7 +86,7 @@ impl GetTransaction { bip125_replaceable: self.bip125_replaceable.into_model(), parent_descriptors: None, // v24 and later only. details, - decoded: self.decoded, + decoded, last_processed_block: None, // v26 and later only. tx, }) diff --git a/types/src/v23/wallet/mod.rs b/types/src/v23/wallet/mod.rs index 8eb215332..76f4b267a 100644 --- a/types/src/v23/wallet/mod.rs +++ b/types/src/v23/wallet/mod.rs @@ -7,7 +7,6 @@ mod error; mod into; -use bitcoin::Transaction; use serde::{Deserialize, Serialize}; pub use self::error::{GetTransactionError, ListSinceBlockError, TransactionItemError}; @@ -105,7 +104,7 @@ pub struct GetTransaction { /// Raw data for transaction. pub hex: String, /// The decoded transaction (only present when `verbose` is passed). - pub decoded: Option, + pub decoded: Option, } /// Result of the JSON-RPC method `getwalletinfo`. diff --git a/types/src/v24/wallet/into.rs b/types/src/v24/wallet/into.rs index b602598f2..085cee402 100644 --- a/types/src/v24/wallet/into.rs +++ b/types/src/v24/wallet/into.rs @@ -44,6 +44,10 @@ impl GetTransaction { .into_iter() .map(|d| d.into_model().map_err(E::Details)) .collect::, _>>()?; + let decoded = self + .decoded + .map(|tx| encode::deserialize_hex::(&tx).map_err(E::Tx)) + .transpose()?; Ok(model::GetTransaction { amount, @@ -68,7 +72,7 @@ impl GetTransaction { bip125_replaceable: self.bip125_replaceable.into_model(), parent_descriptors: self.parent_descriptors, details, - decoded: self.decoded, + decoded, last_processed_block: None, // v26 and later only. tx, }) diff --git a/types/src/v24/wallet/mod.rs b/types/src/v24/wallet/mod.rs index 3903ff28c..9a214ef1f 100644 --- a/types/src/v24/wallet/mod.rs +++ b/types/src/v24/wallet/mod.rs @@ -7,7 +7,6 @@ mod error; mod into; -use bitcoin::Transaction; use serde::{Deserialize, Serialize}; pub use self::error::{ @@ -85,7 +84,7 @@ pub struct GetTransaction { /// Raw data for transaction. pub hex: String, /// The decoded transaction (only present when `verbose` is passed). - pub decoded: Option, + pub decoded: Option, } /// Transaction detail. Part of the `gettransaction`. diff --git a/types/src/v26/wallet/into.rs b/types/src/v26/wallet/into.rs index da984fa4b..dc6d4b522 100644 --- a/types/src/v26/wallet/into.rs +++ b/types/src/v26/wallet/into.rs @@ -73,6 +73,10 @@ impl GetTransaction { .into_iter() .map(|d| d.into_model().map_err(E::Details)) .collect::, _>>()?; + let decoded = self + .decoded + .map(|tx| encode::deserialize_hex::(&tx).map_err(E::Tx)) + .transpose()?; let last_processed_block = self .last_processed_block .map(|l| l.into_model()) @@ -102,7 +106,7 @@ impl GetTransaction { bip125_replaceable: self.bip125_replaceable.into_model(), parent_descriptors: self.parent_descriptors, details, - decoded: self.decoded, + decoded, last_processed_block, tx, }) diff --git a/types/src/v26/wallet/mod.rs b/types/src/v26/wallet/mod.rs index 6ce590a34..211e07269 100644 --- a/types/src/v26/wallet/mod.rs +++ b/types/src/v26/wallet/mod.rs @@ -7,7 +7,6 @@ mod error; mod into; -use bitcoin::Transaction; use serde::{Deserialize, Serialize}; pub use self::error::{ @@ -130,7 +129,7 @@ pub struct GetTransaction { /// Raw data for transaction. pub hex: String, /// The decoded transaction (only present when `verbose` is passed). - pub decoded: Option, + pub decoded: Option, /// Hash and height of the block this information was generated on. #[serde(rename = "lastprocessedblock")] pub last_processed_block: Option, diff --git a/types/src/v28/wallet/into.rs b/types/src/v28/wallet/into.rs index afb1e3d85..368372f2c 100644 --- a/types/src/v28/wallet/into.rs +++ b/types/src/v28/wallet/into.rs @@ -215,6 +215,10 @@ impl GetTransaction { .into_iter() .map(|d| d.into_model().map_err(E::Details)) .collect::, _>>()?; + let decoded = self + .decoded + .map(|tx| encode::deserialize_hex::(&tx).map_err(E::Tx)) + .transpose()?; let last_processed_block = self .last_processed_block .map(|l| l.into_model()) @@ -244,7 +248,7 @@ impl GetTransaction { bip125_replaceable: self.bip125_replaceable.into_model(), parent_descriptors: self.parent_descriptors, details, - decoded: self.decoded, + decoded, last_processed_block, tx, }) diff --git a/types/src/v28/wallet/mod.rs b/types/src/v28/wallet/mod.rs index d8a8426e8..706f76ef7 100644 --- a/types/src/v28/wallet/mod.rs +++ b/types/src/v28/wallet/mod.rs @@ -7,7 +7,6 @@ mod error; mod into; -use bitcoin::Transaction; use serde::{Deserialize, Serialize}; pub use self::error::{GetHdKeysError, ListSinceBlockError, TransactionItemError}; @@ -270,7 +269,7 @@ pub struct GetTransaction { /// Raw data for transaction. pub hex: String, /// The decoded transaction (only present when `verbose` is passed). - pub decoded: Option, + pub decoded: Option, /// Hash and height of the block this information was generated on. #[serde(rename = "lastprocessedblock")] pub last_processed_block: Option,