Skip to content

Commit b7bb07f

Browse files
committed
Merge #255: Add missing return fields in v19
7f5827b Run the formatter (Jamil Lambert, PhD) 2e040f2 Add missing return fields in v19 (Jamil Lambert, PhD) c4cd67c Remove redundant v29 type (Jamil Lambert, PhD) Pull request description: Some of the types in v19 had missing return fields. - Remove a redundant v29 `network::GetNetworkInfo` method that is already defined the same in v28. - Add all of the missing fields from v19 and update the models, into function and reexports accordingly. Redefinitions of the types and into functions are copies of the v17 versions with the missing field added. - Run the formatter in a separate commit to make the changes to the reexports easier to review. ACKs for top commit: tcharding: ACK 7f5827b Tree-SHA512: ecb84767221d733e9656cb44a7c8d40e42f7b65f5dfd7646e02b5846bab73a010ace253deaf79546f103775da4cef4dd448a66fb6cf8f75e6e8ffb983657d81a
2 parents 7ab5633 + 7f5827b commit b7bb07f

File tree

22 files changed

+593
-340
lines changed

22 files changed

+593
-340
lines changed

types/src/model/blockchain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ pub struct GetChainTxStats {
346346
pub tx_count: u32,
347347
/// The hash of the final block in the window.
348348
pub window_final_block_hash: BlockHash,
349+
/// The height of the final block in the window. v0.19 and later only.
350+
pub window_final_block_height: Option<u32>,
349351
/// Size of the window in number of blocks.
350352
pub window_block_count: u32,
351353
/// The number of transactions in the window. Only returned if "window_block_count" is > 0.
@@ -438,6 +440,8 @@ pub struct MempoolEntryFees {
438440
/// Models the result of JSON-RPC method `getmempoolinfo` with verbose set to true.
439441
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
440442
pub struct GetMempoolInfo {
443+
/// True if the mempool is fully loaded. v0.19 and later only.
444+
pub loaded: Option<bool>,
441445
/// Current transaction count.
442446
pub size: u32,
443447
/// Sum of all virtual transaction sizes as defined in BIP 141.

types/src/model/network.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct GetNetworkInfo {
2020
pub protocol_version: usize,
2121
/// The services we offer to the network (hex string).
2222
pub local_services: String,
23+
/// The services we offer to the network. v0.19 and later only.
24+
pub local_services_names: Option<Vec<String>>,
2325
/// `true` if transaction relay is requested from peers.
2426
pub local_relay: bool,
2527
/// The time offset.

types/src/v17/blockchain/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ impl GetChainTxStats {
318318
time: crate::to_u32(self.time, "time")?,
319319
tx_count: crate::to_u32(self.tx_count, "tx_count")?,
320320
window_final_block_hash,
321+
window_final_block_height: None,
321322
window_block_count: crate::to_u32(self.window_block_count, "window_block_count")?,
322323
window_tx_count,
323324
window_interval,
@@ -457,6 +458,7 @@ impl GetMempoolInfo {
457458
let min_relay_tx_fee = crate::btc_per_kb(self.min_relay_tx_fee)?;
458459

459460
Ok(model::GetMempoolInfo {
461+
loaded: None,
460462
size,
461463
bytes,
462464
usage,

types/src/v17/network/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ impl GetNetworkInfo {
1717
subversion: self.subversion,
1818
protocol_version: self.protocol_version,
1919
local_services: self.local_services,
20+
local_services_names: None,
2021
local_relay: self.local_relay,
2122
time_offset: self.time_offset,
2223
connections: self.connections,

types/src/v19/blockchain/into.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use super::error::{
1010
MempoolEntryFeesError,
1111
};
1212
use super::{
13-
GetBlockFilter, GetBlockchainInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose,
14-
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, MempoolEntry,
15-
MempoolEntryFees,
13+
GetBlockFilter, GetBlockchainInfo, GetChainTxStats, GetChainTxStatsError, GetMempoolAncestors,
14+
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
15+
GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError, MempoolEntry, MempoolEntryFees,
1616
};
1717
use crate::model;
1818

@@ -66,6 +66,34 @@ impl GetBlockFilter {
6666
}
6767
}
6868

69+
impl GetChainTxStats {
70+
/// Converts version specific type to a version nonspecific, more strongly typed type.
71+
pub fn into_model(self) -> Result<model::GetChainTxStats, GetChainTxStatsError> {
72+
use GetChainTxStatsError as E;
73+
74+
let window_final_block_hash =
75+
self.window_final_block_hash.parse::<BlockHash>().map_err(E::WindowFinalBlockHash)?;
76+
let window_final_block_height =
77+
crate::to_u32(self.window_final_block_height, "window_final_block_height")?;
78+
let window_tx_count =
79+
self.window_tx_count.map(|h| crate::to_u32(h, "window_tx_count")).transpose()?;
80+
let window_interval =
81+
self.window_interval.map(|h| crate::to_u32(h, "window_interval")).transpose()?;
82+
let tx_rate = self.tx_rate.map(|h| crate::to_u32(h, "tx_rate")).transpose()?;
83+
84+
Ok(model::GetChainTxStats {
85+
time: crate::to_u32(self.time, "time")?,
86+
tx_count: crate::to_u32(self.tx_count, "tx_count")?,
87+
window_final_block_hash,
88+
window_final_block_height: Some(window_final_block_height),
89+
window_block_count: crate::to_u32(self.window_block_count, "window_block_count")?,
90+
window_tx_count,
91+
window_interval,
92+
tx_rate,
93+
})
94+
}
95+
}
96+
6997
impl GetMempoolAncestors {
7098
/// Converts version specific type to a version nonspecific, more strongly typed type.
7199
pub fn into_model(self) -> Result<model::GetMempoolAncestors, hex::HexToArrayError> {
@@ -181,3 +209,25 @@ impl MempoolEntryFees {
181209
})
182210
}
183211
}
212+
213+
impl GetMempoolInfo {
214+
/// Converts version specific type to a version nonspecific, more strongly typed type.
215+
pub fn into_model(self) -> Result<model::GetMempoolInfo, GetMempoolInfoError> {
216+
let size = crate::to_u32(self.size, "size")?;
217+
let bytes = crate::to_u32(self.bytes, "bytes")?;
218+
let usage = crate::to_u32(self.usage, "usage")?;
219+
let max_mempool = crate::to_u32(self.max_mempool, "max_mempool")?;
220+
let mempool_min_fee = crate::btc_per_kb(self.mempool_min_fee)?;
221+
let min_relay_tx_fee = crate::btc_per_kb(self.min_relay_tx_fee)?;
222+
223+
Ok(model::GetMempoolInfo {
224+
loaded: Some(self.loaded),
225+
size,
226+
bytes,
227+
usage,
228+
max_mempool,
229+
mempool_min_fee,
230+
min_relay_tx_fee,
231+
})
232+
}
233+
}

types/src/v19/blockchain/mod.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
1313

1414
// TODO: Remove wildcard, use explicit types.
1515
pub use self::error::*;
16+
use super::{GetChainTxStatsError, GetMempoolInfoError};
1617

1718
/// Result of JSON-RPC method `getblockchaininfo`.
1819
///
@@ -155,6 +156,33 @@ pub struct GetBlockFilter {
155156
pub header: String,
156157
}
157158

159+
/// Result of JSON-RPC method `getchaintxstats`.
160+
///
161+
/// > getchaintxstats ( nblocks blockhash )
162+
/// >
163+
/// > Compute statistics about the total number and rate of transactions in the chain.
164+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
165+
pub struct GetChainTxStats {
166+
/// The timestamp for the final block in the window in UNIX format.
167+
pub time: i64,
168+
/// The total number of transactions in the chain up to that point.
169+
#[serde(rename = "txcount")]
170+
pub tx_count: i64,
171+
/// The hash of the final block in the window.
172+
pub window_final_block_hash: String,
173+
/// The height of the final block in the window.
174+
pub window_final_block_height: i64,
175+
/// Size of the window in number of blocks.
176+
pub window_block_count: i64,
177+
/// The number of transactions in the window. Only returned if "window_block_count" is > 0.
178+
pub window_tx_count: Option<i64>,
179+
/// The elapsed time in the window in seconds. Only returned if "window_block_count" is > 0.
180+
pub window_interval: Option<i64>,
181+
/// The average rate of transactions per second in the window. Only returned if "window_interval" is > 0.
182+
#[serde(rename = "txrate")]
183+
pub tx_rate: Option<i64>,
184+
}
185+
158186
/// Result of JSON-RPC method `getmempoolancestors` with verbose set to `false`.
159187
///
160188
/// > getmempoolancestors txid (verbose)
@@ -269,3 +297,33 @@ pub struct MempoolEntryFees {
269297
/// Modified fees (see above) of in-mempool descendants (including this one) in BTC.
270298
pub descendant: f64,
271299
}
300+
301+
/// Result of JSON-RPC method `getmempoolinfo` with verbose set to `true`.
302+
///
303+
/// > getmempoolinfo
304+
/// >
305+
/// > Returns details on the active state of the TX memory pool.
306+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
307+
pub struct GetMempoolInfo {
308+
/// True if the mempool is fully loaded. v0.19 and later only.
309+
pub loaded: bool,
310+
/// Current transaction count.
311+
pub size: i64,
312+
/// Sum of all virtual transaction sizes as defined in BIP 141.
313+
///
314+
/// Differs from actual serialized size because witness data is discounted.
315+
pub bytes: i64,
316+
/// Total memory usage for the mempool.
317+
pub usage: i64,
318+
/// Maximum memory usage for the mempool.
319+
#[serde(rename = "maxmempool")]
320+
pub max_mempool: i64,
321+
/// Minimum fee rate in BTC/kB for a transaction to be accepted.
322+
///
323+
/// This is the maximum of `minrelaytxfee` and the minimum mempool fee.
324+
#[serde(rename = "mempoolminfee")]
325+
pub mempool_min_fee: f64,
326+
/// Current minimum relay fee for transactions.
327+
#[serde(rename = "minrelaytxfee")]
328+
pub min_relay_tx_fee: f64,
329+
}

types/src/v19/control.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v0.19` - control.
4+
//!
5+
//! Types for methods found under the `== Control ==` section of the API docs.
6+
7+
use serde::{Deserialize, Serialize};
8+
9+
use super::ActiveCommand;
10+
11+
/// Result of JSON-RPC method `getrpcinfo`.
12+
///
13+
/// > getrpcinfo
14+
/// >
15+
/// > Returns details of the RPC server.
16+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
17+
pub struct GetRpcInfo {
18+
/// All active commands
19+
pub active_commands: Vec<ActiveCommand>,
20+
/// The complete file path to the debug log
21+
#[serde(rename = "logpath")]
22+
pub log_path: String,
23+
}

types/src/v19/mod.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,23 @@
226226
227227
// JSON-RPC types by API section.
228228
mod blockchain;
229+
mod control;
230+
mod network;
229231
mod util;
230232
mod wallet;
231233

232234
#[doc(inline)]
233235
pub use self::{
234236
blockchain::{
235237
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockFilter,
236-
GetBlockFilterError, GetBlockchainInfo, GetBlockchainInfoError, GetMempoolAncestors,
237-
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
238-
GetMempoolEntry, MapMempoolEntryError, MempoolEntry, MempoolEntryError, MempoolEntryFees,
239-
MempoolEntryFeesError, Softfork, SoftforkType,
238+
GetBlockFilterError, GetBlockchainInfo, GetBlockchainInfoError, GetChainTxStats,
239+
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
240+
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, MapMempoolEntryError,
241+
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, Softfork,
242+
SoftforkType,
240243
},
244+
control::GetRpcInfo,
245+
network::{GetNetworkInfo, GetPeerInfo, PeerInfo},
241246
util::GetDescriptorInfo,
242247
wallet::{GetBalances, GetBalancesMine, GetBalancesWatchOnly},
243248
};
@@ -254,16 +259,15 @@ pub use crate::v17::{
254259
GetBalance, GetBestBlockHash, GetBlockCount, GetBlockHash, GetBlockHeader, GetBlockHeaderError,
255260
GetBlockHeaderVerbose, GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError,
256261
GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError,
257-
GetBlockVerboseZero, GetChainTips, GetChainTxStats, GetChainTxStatsError, GetConnectionCount,
258-
GetDifficulty, GetMemoryInfoStats, GetMempoolInfo, GetMempoolInfoError, GetMiningInfo,
259-
GetNetTotals, GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoError,
260-
GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, GetRawMempool, GetRawMempoolVerbose,
261-
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
262-
GetReceivedByAddress, GetTransaction, GetTransactionDetail, GetTransactionDetailError,
263-
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
264-
GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError, GetZmqNotifications,
265-
ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem, ListBanned,
266-
ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
262+
GetBlockVerboseZero, GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty,
263+
GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
264+
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress, GetRawMempool,
265+
GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
266+
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransaction, GetTransactionDetail,
267+
GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
268+
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError,
269+
GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem,
270+
ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
267271
ListReceivedByAddress, ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock,
268272
ListSinceBlockError, ListSinceBlockTransaction, ListSinceBlockTransactionError,
269273
ListTransactions, ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError,
@@ -277,8 +281,7 @@ pub use crate::v17::{
277281
#[doc(inline)]
278282
pub use crate::v18::{
279283
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
280-
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetPeerInfo,
281-
GetReceivedByLabel, GetRpcInfo, JoinPsbts, ListReceivedByLabel, ListReceivedByLabelError,
282-
ListUnspent, ListUnspentItem, ListWalletDir, ListWalletDirWallet, NodeAddress, PeerInfo,
283-
UtxoUpdatePsbt,
284+
AnalyzePsbtInputMissingError, DeriveAddresses, GetNodeAddresses, GetReceivedByLabel, JoinPsbts,
285+
ListReceivedByLabel, ListReceivedByLabelError, ListUnspent, ListUnspentItem, ListWalletDir,
286+
ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
284287
};

types/src/v19/network/into.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
use super::{GetNetworkInfo, GetNetworkInfoError};
4+
use crate::model;
5+
6+
impl GetNetworkInfo {
7+
/// Converts version specific type to a version nonspecific, more strongly typed type.
8+
pub fn into_model(self) -> Result<model::GetNetworkInfo, GetNetworkInfoError> {
9+
use GetNetworkInfoError as E;
10+
11+
let relay_fee = crate::btc_per_kb(self.relay_fee).map_err(E::RelayFee)?;
12+
let incremental_fee = crate::btc_per_kb(self.incremental_fee).map_err(E::IncrementalFee)?;
13+
14+
Ok(model::GetNetworkInfo {
15+
version: self.version,
16+
subversion: self.subversion,
17+
protocol_version: self.protocol_version,
18+
local_services: self.local_services,
19+
local_services_names: Some(self.local_services_names),
20+
local_relay: self.local_relay,
21+
time_offset: self.time_offset,
22+
connections: self.connections,
23+
network_active: self.network_active,
24+
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
25+
relay_fee,
26+
incremental_fee,
27+
local_addresses: self.local_addresses.into_iter().map(|a| a.into_model()).collect(),
28+
warnings: vec![self.warnings],
29+
})
30+
}
31+
}

0 commit comments

Comments
 (0)