Skip to content
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
2 changes: 1 addition & 1 deletion integration_test/tests/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 5 additions & 1 deletion types/src/v17/blockchain/into.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
2 changes: 0 additions & 2 deletions types/src/v17/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion types/src/v19/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl GetTransaction {
.into_iter()
.map(|d| d.into_model().map_err(E::Details))
.collect::<Result<Vec<_>, _>>()?;
let decoded = self
.decoded
.map(|tx| encode::deserialize_hex::<Transaction>(&tx).map_err(E::Tx))
.transpose()?;

Ok(model::GetTransaction {
amount,
Expand All @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions types/src/v19/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod error;
mod into;

use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use self::error::GetBalancesError;
Expand Down Expand Up @@ -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<Transaction>,
pub decoded: Option<String>,
}

/// Result of the JSON-RPC method `getwalletinfo`.
Expand Down
6 changes: 5 additions & 1 deletion types/src/v20/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ impl GetTransaction {
.into_iter()
.map(|d| d.into_model().map_err(E::Details))
.collect::<Result<Vec<_>, _>>()?;
let decoded = self
.decoded
.map(|tx| encode::deserialize_hex::<Transaction>(&tx).map_err(E::Tx))
.transpose()?;

Ok(model::GetTransaction {
amount,
Expand All @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions types/src/v20/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod error;
mod into;

use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use self::error::{ListSinceBlockError, TransactionItemError};
Expand Down Expand Up @@ -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<Transaction>,
pub decoded: Option<String>,
}

/// Transaction detail. Part of the `gettransaction`.
Expand Down
6 changes: 5 additions & 1 deletion types/src/v23/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl GetTransaction {
.into_iter()
.map(|d| d.into_model().map_err(E::Details))
.collect::<Result<Vec<_>, _>>()?;
let decoded = self
.decoded
.map(|tx| encode::deserialize_hex::<Transaction>(&tx).map_err(E::Tx))
.transpose()?;

Ok(model::GetTransaction {
amount,
Expand All @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions types/src/v23/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod error;
mod into;

use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use self::error::{GetTransactionError, ListSinceBlockError, TransactionItemError};
Expand Down Expand Up @@ -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<Transaction>,
pub decoded: Option<String>,
}

/// Result of the JSON-RPC method `getwalletinfo`.
Expand Down
6 changes: 5 additions & 1 deletion types/src/v24/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ impl GetTransaction {
.into_iter()
.map(|d| d.into_model().map_err(E::Details))
.collect::<Result<Vec<_>, _>>()?;
let decoded = self
.decoded
.map(|tx| encode::deserialize_hex::<Transaction>(&tx).map_err(E::Tx))
.transpose()?;

Ok(model::GetTransaction {
amount,
Expand All @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions types/src/v24/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod error;
mod into;

use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use self::error::{
Expand Down Expand Up @@ -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<Transaction>,
pub decoded: Option<String>,
}

/// Transaction detail. Part of the `gettransaction`.
Expand Down
6 changes: 5 additions & 1 deletion types/src/v26/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl GetTransaction {
.into_iter()
.map(|d| d.into_model().map_err(E::Details))
.collect::<Result<Vec<_>, _>>()?;
let decoded = self
.decoded
.map(|tx| encode::deserialize_hex::<Transaction>(&tx).map_err(E::Tx))
.transpose()?;
let last_processed_block = self
.last_processed_block
.map(|l| l.into_model())
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions types/src/v26/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod error;
mod into;

use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use self::error::{
Expand Down Expand Up @@ -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<Transaction>,
pub decoded: Option<String>,
/// Hash and height of the block this information was generated on.
#[serde(rename = "lastprocessedblock")]
pub last_processed_block: Option<LastProcessedBlock>,
Expand Down
50 changes: 48 additions & 2 deletions types/src/v28/blockchain/into.rs
Original file line number Diff line number Diff line change
@@ -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<model::GetBlockchainInfo, GetBlockchainInfoError> {
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::<BlockHash>().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<model::ScanTxOutSetStart, ScanTxOutSetError> {
Expand Down
43 changes: 0 additions & 43 deletions types/src/v28/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -65,47 +63,6 @@ pub struct GetBlockchainInfo {
pub warnings: Vec<String>,
}

impl GetBlockchainInfo {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetBlockchainInfo, GetBlockchainInfoError> {
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::<BlockHash>().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,...] )
Expand Down
6 changes: 5 additions & 1 deletion types/src/v28/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ impl GetTransaction {
.into_iter()
.map(|d| d.into_model().map_err(E::Details))
.collect::<Result<Vec<_>, _>>()?;
let decoded = self
.decoded
.map(|tx| encode::deserialize_hex::<Transaction>(&tx).map_err(E::Tx))
.transpose()?;
let last_processed_block = self
.last_processed_block
.map(|l| l.into_model())
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions types/src/v28/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod error;
mod into;

use bitcoin::Transaction;
use serde::{Deserialize, Serialize};

pub use self::error::{GetHdKeysError, ListSinceBlockError, TransactionItemError};
Expand Down Expand Up @@ -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<Transaction>,
pub decoded: Option<String>,
/// Hash and height of the block this information was generated on.
#[serde(rename = "lastprocessedblock")]
pub last_processed_block: Option<LastProcessedBlock>,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v29/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 0 additions & 2 deletions types/src/v29/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading