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
19 changes: 17 additions & 2 deletions types/src/v24/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use bitcoin::{hex, OutPoint, Txid, Wtxid};
use super::{
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError,
GetTxSpendingPrevout, GetTxSpendingPrevoutError, GetTxSpendingPrevoutItem,
MapMempoolEntryError, MempoolEntry, MempoolEntryError,
GetRawMempoolVerbose, GetTxSpendingPrevout, GetTxSpendingPrevoutError,
GetTxSpendingPrevoutItem, MapMempoolEntryError, MempoolEntry, MempoolEntryError,
};
use crate::model;

Expand Down Expand Up @@ -114,6 +114,21 @@ impl MempoolEntry {
}
}

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))
}
}

impl GetMempoolInfo {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetMempoolInfo, GetMempoolInfoError> {
Expand Down
7 changes: 7 additions & 0 deletions types/src/v24/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ pub struct GetMempoolDescendantsVerbose(pub BTreeMap<String, MempoolEntry>);
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetMempoolEntry(pub MempoolEntry);

/// 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>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks man. Can you add an into_model method too please. Copy from v17 also, or here it is.

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))
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a5f9033


/// Mempool data. Part of `getmempoolentry`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
Expand Down
23 changes: 11 additions & 12 deletions types/src/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ mod wallet;
pub use self::{
blockchain::{
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetTxSpendingPrevout,
GetTxSpendingPrevoutError, GetTxSpendingPrevoutItem, MempoolEntry,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetRawMempoolVerbose,
GetTxSpendingPrevout, GetTxSpendingPrevoutError, GetTxSpendingPrevoutItem, MempoolEntry,
},
network::{GetPeerInfo, PeerInfo},
raw_transactions::{
Expand Down Expand Up @@ -279,16 +279,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,
GetRawMempool, 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,
Expand Down
3 changes: 2 additions & 1 deletion types/src/v24/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ impl ListUnspentItem {
let vout = crate::to_u32(self.vout, "vout")?;
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
let script_pubkey = ScriptBuf::from_hex(&self.script_pubkey).map_err(E::ScriptPubkey)?;
let label = self.label.unwrap_or_default();

let amount = SignedAmount::from_btc(self.amount).map_err(E::Amount)?;
let confirmations = crate::to_u32(self.confirmations, "confirmations")?;
Expand All @@ -228,7 +229,7 @@ impl ListUnspentItem {
txid,
vout,
address,
label: self.label,
label,
script_pubkey,
amount,
confirmations,
Expand Down
2 changes: 1 addition & 1 deletion types/src/v24/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub struct ListUnspentItem {
/// The bitcoin address of the transaction.
pub address: String,
/// The associated label, or "" for the default label.
pub label: String,
pub label: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The need for this change proves what we suspect, our test coverage is not good enough (see #58).

cc @jamillambert

/// The script key.
#[serde(rename = "scriptPubKey")]
pub script_pubkey: String,
Expand Down
3 changes: 2 additions & 1 deletion types/src/v28/raw_transactions/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ impl SubmitPackageTxResultFees {
.flatten();
let effective_includes = self
.effective_includes
.iter()
.unwrap_or_default()
.into_iter()
.map(|s| s.parse::<Wtxid>().map_err(E::EffectiveIncludes))
.collect::<Result<Vec<_>, _>>()?;

Expand Down
2 changes: 1 addition & 1 deletion types/src/v28/raw_transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ pub struct SubmitPackageTxResultFees {
/// If [`Self::effective_fee_rate`] is provided, this holds the wtxid's of the transactions
/// whose fees and vsizes are included in effective-feerate.
#[serde(rename = "effective-includes")]
pub effective_includes: Vec<String>,
pub effective_includes: Option<Vec<String>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one too. Thanks for finding and fixing these for us @storopoli.

}