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 client/src/client_sync/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ macro_rules! impl_client_v17__get_raw_mempool {
// Equivalent to self.call("getrawmempool", &[into_json(false)?])
self.call("getrawmempool", &[])
}
pub fn get_raw_mempool_verbose(&self) -> Result<GetRawMempool> {
pub fn get_raw_mempool_verbose(&self) -> Result<GetRawMempoolVerbose> {
self.call("getrawmempool", &[into_json(true)?])
}
}
Expand Down
12 changes: 6 additions & 6 deletions integration_test/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,13 @@ fn blockchain__get_raw_mempool__modelled() {
// Sanity check.
assert_eq!(mempool.0.len(), 1);

// FIXME: Fails: JsonRpc(Json(Error("invalid type: map, expected a sequence", line: 1, column: 0)))
// verbose = true
// let json: GetRawMempoolVerbose = node.client.get_raw_mempool_verbose().expect("getrawmempool verbose");
// let model: Result<mtype::GetRawMempoolVerbose, GetRawMempoolVerboseError> = json.into_model();
// let mempool = model.unwrap();
// // Sanity check.
// assert_eq!(mempool.0.len(), 1);
let json: GetRawMempoolVerbose =
node.client.get_raw_mempool_verbose().expect("getrawmempool verbose");
let model: Result<mtype::GetRawMempoolVerbose, MapMempoolEntryError> = json.into_model();
let mempool = model.unwrap();
// Sanity check.
assert_eq!(mempool.0.len(), 1);
}

#[test]
Expand Down
27 changes: 25 additions & 2 deletions types/src/v18/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bitcoin::{hex, Txid, Wtxid};

use super::{
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, MapMempoolEntryError, MempoolEntry,
MempoolEntryError,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetRawMempool, GetRawMempoolVerbose,
MapMempoolEntryError, MempoolEntry, MempoolEntryError,
};
use crate::model;

Expand Down Expand Up @@ -111,3 +111,26 @@ impl MempoolEntry {
})
}
}

impl GetRawMempool {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetRawMempool, hex::HexToArrayError> {
let v = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::GetRawMempool(v))
}
}

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

let mut map = BTreeMap::new();
for (k, v) in self.0.into_iter() {
let txid = k.parse::<Txid>().map_err(E::Txid)?;
let relative = v.into_model().map_err(E::MempoolEntry)?;
map.insert(txid, relative);
}
Ok(model::GetRawMempoolVerbose(map))
}
}
17 changes: 17 additions & 0 deletions types/src/v18/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,20 @@ pub struct MempoolEntry {
#[serde(rename = "bip125-replaceable")]
pub bip125_replaceable: bool,
}

/// Result of JSON-RPC method `getrawmempool` with verbose set to `false`.
/// > getrawmempool ( verbose )
/// >
/// > Returns all transaction ids in memory pool as a json array of string transaction ids.
/// >
/// > Hint: use getmempoolentry to fetch a specific transaction from the mempool.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawMempool(pub Vec<String>);

/// Result of JSON-RPC method `getrawmempool` with verbose set to `true`.
///
/// Map of txid to [`MempoolEntry`].
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawMempoolVerbose(pub BTreeMap<String, MempoolEntry>);
25 changes: 13 additions & 12 deletions types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ mod zmq;
pub use self::{
blockchain::{
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, MempoolEntry,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetRawMempool, GetRawMempoolVerbose,
MempoolEntry,
},
control::{ActiveCommand, GetRpcInfo},
network::{GetNodeAddresses, GetPeerInfo, NodeAddress, PeerInfo},
Expand Down Expand Up @@ -268,17 +269,17 @@ pub use crate::v17::{
GetBlockVerboseZero, GetBlockchainInfo, GetBlockchainInfoError, GetChainTips, GetChainTxStats,
GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolInfo,
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfo, GetNetworkInfoAddress,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, GetRawMempool,
GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransaction, GetTransactionDetail,
GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings,
ListAddressGroupingsError, ListAddressGroupingsItem, ListBanned, ListLabels, ListLockUnspent,
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError, ListSinceBlock,
ListSinceBlockError, ListTransactions, ListUnspentItemError, ListWallets, LoadWallet,
LockUnspent, Locked, Logging, MapMempoolEntryError, MempoolAcceptance, MempoolEntryError,
MempoolEntryFees, MempoolEntryFeesError, NumericError, PruneBlockchain, PsbtInput, PsbtOutput,
PsbtScript, RawTransaction, RawTransactionError, RawTransactionInput, RawTransactionOutput,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
GetReceivedByAddress, GetTransaction, GetTransactionDetail, GetTransactionDetailError,
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
ListAddressGroupingsItem, ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem,
ListLockUnspentItemError, ListReceivedByAddressError, ListSinceBlock, ListSinceBlockError,
ListTransactions, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked, Logging,
MapMempoolEntryError, MempoolAcceptance, MempoolEntryError, MempoolEntryFees,
MempoolEntryFeesError, NumericError, PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript,
RawTransaction, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SetTxFee, SignFail, SignFailError, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, Softfork,
Expand Down
26 changes: 25 additions & 1 deletion types/src/v19/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use super::error::{
use super::{
GetBlockFilter, GetBlockchainInfo, GetChainTxStats, GetChainTxStatsError, GetMempoolAncestors,
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError, MempoolEntry, MempoolEntryFees,
GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError, GetRawMempool, GetRawMempoolVerbose,
MempoolEntry, MempoolEntryFees,
};
use crate::model;

Expand Down Expand Up @@ -236,3 +237,26 @@ impl GetMempoolInfo {
})
}
}

impl GetRawMempool {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetRawMempool, hex::HexToArrayError> {
let v = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::GetRawMempool(v))
}
}

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

let mut map = BTreeMap::new();
for (k, v) in self.0.into_iter() {
let txid = k.parse::<Txid>().map_err(E::Txid)?;
let relative = v.into_model().map_err(E::MempoolEntry)?;
map.insert(txid, relative);
}
Ok(model::GetRawMempoolVerbose(map))
}
}
17 changes: 17 additions & 0 deletions types/src/v19/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,20 @@ pub struct GetMempoolInfo {
#[serde(rename = "minrelaytxfee")]
pub min_relay_tx_fee: f64,
}

/// Result of JSON-RPC method `getrawmempool` with verbose set to `false`.
/// > getrawmempool ( verbose )
/// >
/// > Returns all transaction ids in memory pool as a json array of string transaction ids.
/// >
/// > Hint: use getmempoolentry to fetch a specific transaction from the mempool.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawMempool(pub Vec<String>);

/// Result of JSON-RPC method `getrawmempool` with verbose set to `true`.
///
/// Map of txid to [`MempoolEntry`].
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawMempoolVerbose(pub BTreeMap<String, MempoolEntry>);
35 changes: 17 additions & 18 deletions types/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ pub use self::{
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockFilter,
GetBlockFilterError, GetBlockchainInfo, GetBlockchainInfoError, GetChainTxStats,
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, MapMempoolEntryError,
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, Softfork,
SoftforkType,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetRawMempool,
GetRawMempoolVerbose, MapMempoolEntryError, MempoolEntry, MempoolEntryError,
MempoolEntryFees, MempoolEntryFeesError, Softfork, SoftforkType,
},
control::GetRpcInfo,
network::{GetNetworkInfo, GetPeerInfo, PeerInfo},
Expand All @@ -264,21 +264,20 @@ pub use crate::v17::{
GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError,
GetBlockVerboseZero, GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty,
GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, GetRawMempool,
GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetail,
GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings,
ListAddressGroupingsError, ListAddressGroupingsItem, ListBanned, ListLabels, ListLockUnspent,
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError, ListSinceBlock,
ListSinceBlockError, ListTransactions, ListUnspentItemError, ListWallets, LoadWallet,
LockUnspent, Locked, Logging, NumericError, PruneBlockchain, RawTransactionError,
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType, SendMany,
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey,
SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept, TransactionCategory,
TransactionItem, TransactionItemError, UploadTarget, ValidateAddress, ValidateAddressError,
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
GetReceivedByAddress, GetTransactionDetail, GetTransactionDetailError, GetTransactionError,
GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem,
ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
ListReceivedByAddressError, ListSinceBlock, ListSinceBlockError, ListTransactions,
ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked, Logging, NumericError,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept,
TransactionCategory, TransactionItem, TransactionItemError, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
};
#[doc(inline)]
Expand Down
34 changes: 17 additions & 17 deletions types/src/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,20 @@ pub use crate::{
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, GetWalletInfoError, ListAddressGroupings,
ListAddressGroupingsError, ListAddressGroupingsItem, ListLabels, ListLockUnspent,
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError,
ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked, NumericError,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
GetNewAddress, GetRawChangeAddress, GetRawTransaction, GetRawTransactionVerbose,
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetailError,
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
ListLockUnspentItemError, ListReceivedByAddressError, ListUnspentItemError, ListWallets,
LoadWallet, LockUnspent, Locked, NumericError, PruneBlockchain, RawTransactionError,
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType, SendMany,
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept,
TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain,
VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
WalletProcessPsbt, WitnessUtxo,
},
v18::{
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
Expand All @@ -289,8 +289,8 @@ pub use crate::{
GetBlockFilterError, GetBlockchainInfo, GetBlockchainInfoError, GetChainTxStats,
GetDescriptorInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetNetworkInfo, GetPeerInfo,
GetRpcInfo, GetWalletInfo, GetWalletInfoScanning, MapMempoolEntryError, MempoolEntry,
MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo, SetWalletFlag,
Softfork, SoftforkType,
GetRawMempool, GetRawMempoolVerbose, GetRpcInfo, GetWalletInfo, GetWalletInfoScanning,
MapMempoolEntryError, MempoolEntry, MempoolEntryError, MempoolEntryFees,
MempoolEntryFeesError, PeerInfo, SetWalletFlag, Softfork, SoftforkType,
},
};
26 changes: 25 additions & 1 deletion types/src/v21/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use bitcoin::{hex, BlockHash, Network, Txid, Work, Wtxid};
use super::{
GetBlockchainInfo, GetBlockchainInfoError, GetMempoolAncestors, GetMempoolAncestorsVerbose,
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo,
GetMempoolInfoError, MapMempoolEntryError, MempoolEntry, MempoolEntryError,
GetMempoolInfoError, GetRawMempool, GetRawMempoolVerbose, MapMempoolEntryError, MempoolEntry,
MempoolEntryError,
};
use crate::model;

Expand Down Expand Up @@ -179,3 +180,26 @@ impl GetMempoolInfo {
})
}
}

impl GetRawMempool {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetRawMempool, hex::HexToArrayError> {
let v = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::GetRawMempool(v))
}
}

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

let mut map = BTreeMap::new();
for (k, v) in self.0.into_iter() {
let txid = k.parse::<Txid>().map_err(E::Txid)?;
let relative = v.into_model().map_err(E::MempoolEntry)?;
map.insert(txid, relative);
}
Ok(model::GetRawMempoolVerbose(map))
}
}
17 changes: 17 additions & 0 deletions types/src/v21/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,20 @@ pub struct GetMempoolInfo {
#[serde(rename = "unbroadcastcount")]
pub unbroadcast_count: i64,
}

/// Result of JSON-RPC method `getrawmempool` with verbose set to `false`.
/// > getrawmempool ( verbose )
/// >
/// > Returns all transaction ids in memory pool as a json array of string transaction ids.
/// >
/// > Hint: use getmempoolentry to fetch a specific transaction from the mempool.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawMempool(pub Vec<String>);

/// Result of JSON-RPC method `getrawmempool` with verbose set to `true`.
///
/// Map of txid to [`MempoolEntry`].
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawMempoolVerbose(pub BTreeMap<String, MempoolEntry>);
Loading