diff --git a/client/src/client_sync/v17/blockchain.rs b/client/src/client_sync/v17/blockchain.rs index be11bc2d..f0b037ca 100644 --- a/client/src/client_sync/v17/blockchain.rs +++ b/client/src/client_sync/v17/blockchain.rs @@ -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 { + pub fn get_raw_mempool_verbose(&self) -> Result { self.call("getrawmempool", &[into_json(true)?]) } } diff --git a/integration_test/tests/blockchain.rs b/integration_test/tests/blockchain.rs index 3a820e86..235b6ebe 100644 --- a/integration_test/tests/blockchain.rs +++ b/integration_test/tests/blockchain.rs @@ -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 = 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 = json.into_model(); + let mempool = model.unwrap(); + // Sanity check. + assert_eq!(mempool.0.len(), 1); } #[test] diff --git a/types/src/v18/blockchain/into.rs b/types/src/v18/blockchain/into.rs index 77bee957..2fb6d06d 100644 --- a/types/src/v18/blockchain/into.rs +++ b/types/src/v18/blockchain/into.rs @@ -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; @@ -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 { + let v = self.0.iter().map(|t| t.parse::()).collect::, _>>()?; + Ok(model::GetRawMempool(v)) + } +} + +impl GetRawMempoolVerbose { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use MapMempoolEntryError as E; + + let mut map = BTreeMap::new(); + for (k, v) in self.0.into_iter() { + let txid = k.parse::().map_err(E::Txid)?; + let relative = v.into_model().map_err(E::MempoolEntry)?; + map.insert(txid, relative); + } + Ok(model::GetRawMempoolVerbose(map)) + } +} diff --git a/types/src/v18/blockchain/mod.rs b/types/src/v18/blockchain/mod.rs index b4b61880..f288164c 100644 --- a/types/src/v18/blockchain/mod.rs +++ b/types/src/v18/blockchain/mod.rs @@ -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); + +/// 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); diff --git a/types/src/v18/mod.rs b/types/src/v18/mod.rs index 24cc75fe..9f719e05 100644 --- a/types/src/v18/mod.rs +++ b/types/src/v18/mod.rs @@ -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}, @@ -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, diff --git a/types/src/v19/blockchain/into.rs b/types/src/v19/blockchain/into.rs index d90b6b97..5e697695 100644 --- a/types/src/v19/blockchain/into.rs +++ b/types/src/v19/blockchain/into.rs @@ -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; @@ -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 { + let v = self.0.iter().map(|t| t.parse::()).collect::, _>>()?; + Ok(model::GetRawMempool(v)) + } +} + +impl GetRawMempoolVerbose { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use MapMempoolEntryError as E; + + let mut map = BTreeMap::new(); + for (k, v) in self.0.into_iter() { + let txid = k.parse::().map_err(E::Txid)?; + let relative = v.into_model().map_err(E::MempoolEntry)?; + map.insert(txid, relative); + } + Ok(model::GetRawMempoolVerbose(map)) + } +} diff --git a/types/src/v19/blockchain/mod.rs b/types/src/v19/blockchain/mod.rs index faac2230..ac757941 100644 --- a/types/src/v19/blockchain/mod.rs +++ b/types/src/v19/blockchain/mod.rs @@ -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); + +/// 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); diff --git a/types/src/v19/mod.rs b/types/src/v19/mod.rs index fbeeb23a..81f8cd73 100644 --- a/types/src/v19/mod.rs +++ b/types/src/v19/mod.rs @@ -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}, @@ -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)] diff --git a/types/src/v20/mod.rs b/types/src/v20/mod.rs index 38236039..0e20fd37 100644 --- a/types/src/v20/mod.rs +++ b/types/src/v20/mod.rs @@ -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, @@ -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, }, }; diff --git a/types/src/v21/blockchain/into.rs b/types/src/v21/blockchain/into.rs index e0b1bd80..6fe372af 100644 --- a/types/src/v21/blockchain/into.rs +++ b/types/src/v21/blockchain/into.rs @@ -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; @@ -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 { + let v = self.0.iter().map(|t| t.parse::()).collect::, _>>()?; + Ok(model::GetRawMempool(v)) + } +} + +impl GetRawMempoolVerbose { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use MapMempoolEntryError as E; + + let mut map = BTreeMap::new(); + for (k, v) in self.0.into_iter() { + let txid = k.parse::().map_err(E::Txid)?; + let relative = v.into_model().map_err(E::MempoolEntry)?; + map.insert(txid, relative); + } + Ok(model::GetRawMempoolVerbose(map)) + } +} diff --git a/types/src/v21/blockchain/mod.rs b/types/src/v21/blockchain/mod.rs index 47cef32c..18b86551 100644 --- a/types/src/v21/blockchain/mod.rs +++ b/types/src/v21/blockchain/mod.rs @@ -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); + +/// 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); diff --git a/types/src/v21/mod.rs b/types/src/v21/mod.rs index a03aa47c..a42db85c 100644 --- a/types/src/v21/mod.rs +++ b/types/src/v21/mod.rs @@ -245,7 +245,7 @@ pub use self::{ blockchain::{ Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, - MempoolEntry, Softfork, SoftforkType, + GetRawMempool, GetRawMempoolVerbose, MempoolEntry, Softfork, SoftforkType, }, generating::GenerateBlock, hidden::AddPeerAddress, @@ -276,16 +276,16 @@ 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, SendRawTransaction, SendToAddress, SetNetworkActive, - SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, + 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, + SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage, + SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, diff --git a/types/src/v22/mod.rs b/types/src/v22/mod.rs index 512189fd..a1b6193f 100644 --- a/types/src/v22/mod.rs +++ b/types/src/v22/mod.rs @@ -278,10 +278,10 @@ pub use crate::{ 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, + 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, @@ -315,10 +315,10 @@ pub use crate::{ v21::{ AddPeerAddress, Bip9SoftforkInfo, GenerateBlock, GetBlockchainInfo, GetIndexInfo, GetIndexInfoName, GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants, - GetMempoolDescendantsVerbose, GetMempoolEntry, GetNetworkInfo, GetWalletInfo, - GetWalletInfoScanning, ImportDescriptors, ImportDescriptorsResult, MempoolEntry, - PsbtBumpFee, PsbtBumpFeeError, Send, SendError, SendMany, SendManyVerbose, Softfork, - SoftforkType, UnloadWallet, UpgradeWallet, + GetMempoolDescendantsVerbose, GetMempoolEntry, GetNetworkInfo, GetRawMempool, + GetRawMempoolVerbose, GetWalletInfo, GetWalletInfoScanning, ImportDescriptors, + ImportDescriptorsResult, MempoolEntry, PsbtBumpFee, PsbtBumpFeeError, Send, SendError, + SendMany, SendManyVerbose, Softfork, SoftforkType, UnloadWallet, UpgradeWallet, }, ScriptPubkey, }; diff --git a/types/src/v23/blockchain/into.rs b/types/src/v23/blockchain/into.rs index 34959c84..7a6814d3 100644 --- a/types/src/v23/blockchain/into.rs +++ b/types/src/v23/blockchain/into.rs @@ -7,8 +7,8 @@ use bitcoin::{hex, BlockHash, Network, Txid, Work, Wtxid}; use super::{ Bip9Info, Bip9Statistics, DeploymentInfo, GetBlockchainInfo, GetBlockchainInfoError, GetDeploymentInfo, GetDeploymentInfoError, GetMempoolAncestors, GetMempoolAncestorsVerbose, - GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, MapMempoolEntryError, - MempoolEntry, MempoolEntryError, + GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetRawMempool, + GetRawMempoolVerbose, MapMempoolEntryError, MempoolEntry, MempoolEntryError, }; use crate::model; @@ -211,3 +211,26 @@ impl MempoolEntry { }) } } + +impl GetRawMempool { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + let v = self.0.iter().map(|t| t.parse::()).collect::, _>>()?; + Ok(model::GetRawMempool(v)) + } +} + +impl GetRawMempoolVerbose { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use MapMempoolEntryError as E; + + let mut map = BTreeMap::new(); + for (k, v) in self.0.into_iter() { + let txid = k.parse::().map_err(E::Txid)?; + let relative = v.into_model().map_err(E::MempoolEntry)?; + map.insert(txid, relative); + } + Ok(model::GetRawMempoolVerbose(map)) + } +} diff --git a/types/src/v23/blockchain/mod.rs b/types/src/v23/blockchain/mod.rs index a1c12bf6..0b88668f 100644 --- a/types/src/v23/blockchain/mod.rs +++ b/types/src/v23/blockchain/mod.rs @@ -249,6 +249,23 @@ pub struct MempoolEntry { pub unbroadcast: 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); + +/// 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); + /// Result of JSON-RPC method `savemempool`. /// /// > savemempool diff --git a/types/src/v23/mod.rs b/types/src/v23/mod.rs index 2be1b0a9..292c8917 100644 --- a/types/src/v23/mod.rs +++ b/types/src/v23/mod.rs @@ -248,8 +248,8 @@ pub use self::{ blockchain::{ Bip9Info, Bip9Statistics, DeploymentInfo, GetBlockchainInfo, GetDeploymentInfo, GetDeploymentInfoError, GetMempoolAncestors, GetMempoolAncestorsVerbose, - GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, MempoolEntry, - SaveMempool, + GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetRawMempool, + GetRawMempoolVerbose, MempoolEntry, SaveMempool, }, control::Logging, network::{GetPeerInfo, PeerInfo}, @@ -280,16 +280,15 @@ pub use crate::{ GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, - GetRawMempool, GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose, - GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetailError, 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, - SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage, - SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, + GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError, + GetReceivedByAddress, GetTransactionDetailError, 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, SendRawTransaction, SendToAddress, SetNetworkActive, + SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,