Skip to content

Commit 827aed3

Browse files
committed
Merge #375: fix!(types): v24/v28 fixes
5bb3b31 fix(types): v24 ListUnspentItem might not have a label field (Jose Storopoli) 014e158 fix(types): v28 SubmitPackageTxResultFees might not have effective-includes (Jose Storopoli) a5f9033 fix(types): v24 GetRawMempoolVerbose should use the same version MempoolEntry (Jose Storopoli) Pull request description: A bunch of issues when porting a custom `types.rs` module from [`bitcoind-async-client`](https://github.com/alpenlabs/bitcoind-async-client) to `corepc-types`. - `v24::GetRawMempoolVerbose` should use the same version `MempoolEntry` and not the `v17`. - `v28::SubmitPackageTxResult` might not have `effective-includes` field. - `v24::ListUnspentItem` might not have a `label` field. ACKs for top commit: jamillambert: ACK 5bb3b31 tcharding: ACK 5bb3b31 Tree-SHA512: 36fc5a41990b45b37b540d6413c144fd7943a76ebbe108bf418a04e5d520c80718d41ac558cca0cd25098c0adc2e3f59342c19873ee218136da365b834640c8f
2 parents 9957f86 + 5bb3b31 commit 827aed3

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

types/src/v24/blockchain/into.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use bitcoin::{hex, OutPoint, Txid, Wtxid};
77
use super::{
88
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
99
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError,
10-
GetTxSpendingPrevout, GetTxSpendingPrevoutError, GetTxSpendingPrevoutItem,
11-
MapMempoolEntryError, MempoolEntry, MempoolEntryError,
10+
GetRawMempoolVerbose, GetTxSpendingPrevout, GetTxSpendingPrevoutError,
11+
GetTxSpendingPrevoutItem, MapMempoolEntryError, MempoolEntry, MempoolEntryError,
1212
};
1313
use crate::model;
1414

@@ -114,6 +114,21 @@ impl MempoolEntry {
114114
}
115115
}
116116

117+
impl GetRawMempoolVerbose {
118+
/// Converts version specific type to a version nonspecific, more strongly typed type.
119+
pub fn into_model(self) -> Result<model::GetRawMempoolVerbose, MapMempoolEntryError> {
120+
use MapMempoolEntryError as E;
121+
122+
let mut map = BTreeMap::new();
123+
for (k, v) in self.0.into_iter() {
124+
let txid = k.parse::<Txid>().map_err(E::Txid)?;
125+
let relative = v.into_model().map_err(E::MempoolEntry)?;
126+
map.insert(txid, relative);
127+
}
128+
Ok(model::GetRawMempoolVerbose(map))
129+
}
130+
}
131+
117132
impl GetMempoolInfo {
118133
/// Converts version specific type to a version nonspecific, more strongly typed type.
119134
pub fn into_model(self) -> Result<model::GetMempoolInfo, GetMempoolInfoError> {

types/src/v24/blockchain/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ pub struct GetMempoolDescendantsVerbose(pub BTreeMap<String, MempoolEntry>);
6464
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
6565
pub struct GetMempoolEntry(pub MempoolEntry);
6666

67+
/// Result of JSON-RPC method `getrawmempool` with verbose set to `true`.
68+
///
69+
/// Map of txid to [`MempoolEntry`].
70+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
71+
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
72+
pub struct GetRawMempoolVerbose(pub BTreeMap<String, MempoolEntry>);
73+
6774
/// Mempool data. Part of `getmempoolentry`.
6875
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
6976
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]

types/src/v24/mod.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ mod wallet;
249249
pub use self::{
250250
blockchain::{
251251
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
252-
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetTxSpendingPrevout,
253-
GetTxSpendingPrevoutError, GetTxSpendingPrevoutItem, MempoolEntry,
252+
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetRawMempoolVerbose,
253+
GetTxSpendingPrevout, GetTxSpendingPrevoutError, GetTxSpendingPrevoutItem, MempoolEntry,
254254
},
255255
network::{GetPeerInfo, PeerInfo},
256256
raw_transactions::{
@@ -279,16 +279,15 @@ pub use crate::{
279279
GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats,
280280
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
281281
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
282-
GetRawMempool, GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
283-
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetailError, GetTxOut,
284-
GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
285-
GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
286-
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
287-
ListLockUnspentItemError, ListReceivedByAddressError, ListUnspentItemError, ListWallets,
288-
LoadWallet, LockUnspent, Locked, NumericError, PruneBlockchain, RawTransactionError,
289-
RawTransactionInput, RawTransactionOutput, RescanBlockchain, ScriptType,
290-
SendRawTransaction, SendToAddress, SetNetworkActive, SetTxFee, SignMessage,
291-
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
282+
GetRawMempool, GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
283+
GetReceivedByAddress, GetTransactionDetailError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
284+
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings,
285+
ListAddressGroupingsError, ListAddressGroupingsItem, ListLabels, ListLockUnspent,
286+
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddressError,
287+
ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked, NumericError,
288+
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
289+
RescanBlockchain, ScriptType, SendRawTransaction, SendToAddress, SetNetworkActive,
290+
SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
292291
SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject,
293292
TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain,
294293
VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,

types/src/v24/wallet/into.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl ListUnspentItem {
216216
let vout = crate::to_u32(self.vout, "vout")?;
217217
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
218218
let script_pubkey = ScriptBuf::from_hex(&self.script_pubkey).map_err(E::ScriptPubkey)?;
219+
let label = self.label.unwrap_or_default();
219220

220221
let amount = SignedAmount::from_btc(self.amount).map_err(E::Amount)?;
221222
let confirmations = crate::to_u32(self.confirmations, "confirmations")?;
@@ -228,7 +229,7 @@ impl ListUnspentItem {
228229
txid,
229230
vout,
230231
address,
231-
label: self.label,
232+
label,
232233
script_pubkey,
233234
amount,
234235
confirmations,

types/src/v24/wallet/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub struct ListUnspentItem {
250250
/// The bitcoin address of the transaction.
251251
pub address: String,
252252
/// The associated label, or "" for the default label.
253-
pub label: String,
253+
pub label: Option<String>,
254254
/// The script key.
255255
#[serde(rename = "scriptPubKey")]
256256
pub script_pubkey: String,

types/src/v28/raw_transactions/into.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ impl SubmitPackageTxResultFees {
6161
.flatten();
6262
let effective_includes = self
6363
.effective_includes
64-
.iter()
64+
.unwrap_or_default()
65+
.into_iter()
6566
.map(|s| s.parse::<Wtxid>().map_err(E::EffectiveIncludes))
6667
.collect::<Result<Vec<_>, _>>()?;
6768

types/src/v28/raw_transactions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ pub struct SubmitPackageTxResultFees {
8282
/// If [`Self::effective_fee_rate`] is provided, this holds the wtxid's of the transactions
8383
/// whose fees and vsizes are included in effective-feerate.
8484
#[serde(rename = "effective-includes")]
85-
pub effective_includes: Vec<String>,
85+
pub effective_includes: Option<Vec<String>>,
8686
}

0 commit comments

Comments
 (0)