Skip to content

Commit face30a

Browse files
committed
Merge #267: Add missing return fields in v20 and v21
51ebe64 Run the formatter (Jamil Lambert, PhD) 4c32f09 Add missing fields to getnetworkinfo, getpeerinfo (Jamil Lambert, PhD) 56ffb4f Add missing fields to getmempoolinfo (Jamil Lambert, PhD) 0e97a48 Add missing fields to getblockchaininfo (Jamil Lambert, PhD) d65d26c Add missing return fields to createmultisig (Jamil Lambert, PhD) Pull request description: Some of the types in v20 and v21 had missing return fields. For each of the following RPCs that were missing a return field in v20 or v21 check for further changes up to v29 and implement them: - `createmultisig` - `getblockchaininfo` - `getmempoolinfo` - `getnetworkinfo` - `getpeerinfo` Add all of the missing fields update the models, into function and reexports accordingly. Redefinitions of the types and into functions are modified copies of the most recent version of the RPC that had fields added. Run the formatter in a separate commit to make the changes to the reexports easier to review. ACKs for top commit: tcharding: ACK 51ebe64 Tree-SHA512: c24cd5eea554e01fa78aad4fdbafc2206ad3b0999b8f5e45b984c3900e7e6e8a49638972803318793fb450c8fbfa400a007a756da425f39efe84334404e2ca8c
2 parents 4e2a3f8 + 51ebe64 commit face30a

File tree

40 files changed

+1570
-236
lines changed

40 files changed

+1570
-236
lines changed

types/src/model/blockchain.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub struct GetBlockchainInfo {
8484
pub target: Option<Target>, // Only from v29 onwards
8585
/// The current difficulty.
8686
pub difficulty: f64,
87+
/// The block time expressed in UNIX epoch time. v23 and later only.
88+
pub time: Option<u32>,
8789
/// Median time for the current best block.
8890
pub median_time: u32,
8991
/// Estimate of verification progress (between 0 and 1).
@@ -151,6 +153,8 @@ pub struct Bip9SoftforkInfo {
151153
pub timeout: u32,
152154
/// Height of the first block to which the status applies.
153155
pub since: u32,
156+
/// Minimum height of blocks for which the rules may be enforced. v0.21 and later only.
157+
pub min_activation_height: Option<i64>,
154158
/// Numeric statistics about BIP-9 signalling for a softfork (only for "started" status).
155159
pub statistics: Option<Bip9SoftforkStatistics>,
156160
}
@@ -450,6 +454,9 @@ pub struct GetMempoolInfo {
450454
pub bytes: u32,
451455
/// Total memory usage for the mempool.
452456
pub usage: u32,
457+
/// Total fees for the mempool in BTC, ignoring modified fees through prioritisetransaction. v23
458+
/// and later only.
459+
pub total_fee: Option<f64>,
453460
/// Maximum memory usage for the mempool.
454461
pub max_mempool: u32,
455462
/// Minimum fee rate in BTC/kB for a transaction to be accepted.
@@ -458,6 +465,13 @@ pub struct GetMempoolInfo {
458465
pub mempool_min_fee: Option<FeeRate>,
459466
/// Current minimum relay fee for transactions.
460467
pub min_relay_tx_fee: Option<FeeRate>,
468+
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kvB. v24 and later only.
469+
pub incremental_relay_fee: Option<FeeRate>,
470+
/// Current number of transactions that haven't passed initial broadcast yet. v21 and later only.
471+
pub unbroadcast_count: Option<u32>,
472+
/// True if the mempool accepts RBF without replaceability signaling inspection. v24 and later
473+
/// only.
474+
pub full_rbf: Option<bool>,
461475
}
462476

463477
/// Models the result of JSON-RPC method `getrawmempool` with verbose set to false.

types/src/model/network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub struct GetNetworkInfo {
2828
pub time_offset: isize,
2929
/// The total number of connections.
3030
pub connections: usize,
31+
/// The number of inbound connections. v28 and later only.
32+
pub connections_in: Option<usize>,
33+
/// The number of outbound connections. v28 and later only.
34+
pub connections_out: Option<usize>,
3135
/// Whether p2p networking is enabled.
3236
pub network_active: bool,
3337
/// Information per network.

types/src/model/util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub struct CreateMultisig {
1616
pub address: Address<NetworkUnchecked>,
1717
/// The string value of the hex-encoded redemption script.
1818
pub redeem_script: ScriptBuf,
19+
/// The descriptor for this multisig. v0.20 and later only.
20+
pub descriptor: Option<String>,
21+
/// Any warnings resulting from the creation of this multisig. v23 and later only.
22+
pub warnings: Option<Vec<String>>,
1923
}
2024

2125
/// Models the result of JSON-RPC method `estimatesmartfee`.

types/src/v17/blockchain/into.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl GetBlockchainInfo {
104104
bits: None,
105105
target: None,
106106
difficulty: self.difficulty,
107+
time: None,
107108
median_time: crate::to_u32(self.median_time, "median_time")?,
108109
verification_progress: self.verification_progress,
109110
initial_block_download: self.initial_block_download,
@@ -462,9 +463,13 @@ impl GetMempoolInfo {
462463
size,
463464
bytes,
464465
usage,
466+
total_fee: None,
465467
max_mempool,
466468
mempool_min_fee,
467469
min_relay_tx_fee,
470+
incremental_relay_fee: None,
471+
unbroadcast_count: None,
472+
full_rbf: None,
468473
})
469474
}
470475
}

types/src/v17/network/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ impl GetNetworkInfo {
2121
local_relay: self.local_relay,
2222
time_offset: self.time_offset,
2323
connections: self.connections,
24+
connections_in: None,
25+
connections_out: None,
2426
network_active: self.network_active,
2527
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
2628
relay_fee,

types/src/v17/util/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl CreateMultisig {
1717
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
1818
let redeem_script = ScriptBuf::from_hex(&self.redeem_script).map_err(E::RedeemScript)?;
1919

20-
Ok(model::CreateMultisig { address, redeem_script })
20+
Ok(model::CreateMultisig { address, redeem_script, descriptor: None, warnings: None })
2121
}
2222
}
2323

types/src/v19/blockchain/into.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl GetBlockchainInfo {
3939
bits: None,
4040
target: None,
4141
difficulty: self.difficulty,
42+
time: None,
4243
median_time: crate::to_u32(self.median_time, "median_time")?,
4344
verification_progress: self.verification_progress,
4445
initial_block_download: self.initial_block_download,
@@ -225,9 +226,13 @@ impl GetMempoolInfo {
225226
size,
226227
bytes,
227228
usage,
229+
total_fee: None,
228230
max_mempool,
229231
mempool_min_fee,
230232
min_relay_tx_fee,
233+
incremental_relay_fee: None,
234+
unbroadcast_count: None,
235+
full_rbf: None,
231236
})
232237
}
233238
}

types/src/v19/network/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ impl GetNetworkInfo {
2020
local_relay: self.local_relay,
2121
time_offset: self.time_offset,
2222
connections: self.connections,
23+
connections_in: None,
24+
connections_out: None,
2325
network_active: self.network_active,
2426
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
2527
relay_fee,

types/src/v20/mod.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,46 +228,48 @@
228228
// JSON-RPC types by API section.
229229
mod control;
230230
mod network;
231+
mod util;
231232

232233
#[doc(inline)]
233234
pub use self::{
234235
control::Logging,
235236
network::{Banned, ListBanned},
237+
util::CreateMultisig,
236238
};
237239
#[doc(inline)]
238240
pub use crate::{
239241
v17::{
240242
AbortRescan, AddMultisigAddress, AddMultisigAddressError, AddedNode, AddedNodeAddress,
241243
AddressInformation, BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus,
242-
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisig, CreateMultisigError,
243-
CreatePsbt, CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError,
244-
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet,
245-
EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
246-
FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo, GetAddressInfo,
247-
GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
248-
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash, GetBlockCount,
249-
GetBlockHash, GetBlockHeader, GetBlockHeaderError, GetBlockHeaderVerbose,
250-
GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError, GetBlockTemplate,
251-
GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError, GetBlockVerboseZero,
252-
GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats,
253-
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
254-
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
255-
GetRawMempool, GetRawMempoolVerbose, GetRawTransaction, GetRawTransactionVerbose,
256-
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransaction, GetTransactionDetail,
257-
GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo,
258-
GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError,
259-
GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError,
260-
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
261-
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
262-
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
263-
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
264-
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked,
265-
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
266-
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
267-
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
268-
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
269-
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
270-
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
244+
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisigError, CreatePsbt,
245+
CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError, DecodeRawTransaction,
246+
DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee,
247+
FinalizePsbt, FinalizePsbtError, FundRawTransaction, FundRawTransactionError, Generate,
248+
GenerateToAddress, GetAddedNodeInfo, GetAddressInfo, GetAddressInfoEmbedded,
249+
GetAddressInfoEmbeddedError, GetAddressInfoError, GetAddressInfoLabel, GetAddressesByLabel,
250+
GetBalance, GetBestBlockHash, GetBlockCount, GetBlockHash, GetBlockHeader,
251+
GetBlockHeaderError, GetBlockHeaderVerbose, GetBlockHeaderVerboseError, GetBlockStats,
252+
GetBlockStatsError, GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne,
253+
GetBlockVerboseOneError, GetBlockVerboseZero, GetChainTips, GetChainTxStatsError,
254+
GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo,
255+
GetNetTotals, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
256+
GetNewAddress, GetRawChangeAddress, GetRawMempool, GetRawMempoolVerbose, GetRawTransaction,
257+
GetRawTransactionVerbose, GetRawTransactionVerboseError, GetReceivedByAddress,
258+
GetTransaction, GetTransactionDetail, GetTransactionDetailError, GetTransactionError,
259+
GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
260+
GetWalletInfo, GetWalletInfoError, GetZmqNotifications, ListAddressGroupings,
261+
ListAddressGroupingsError, ListAddressGroupingsItem, ListLabels, ListLockUnspent,
262+
ListLockUnspentItem, ListLockUnspentItemError, ListReceivedByAddress,
263+
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
264+
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
265+
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
266+
LoadWallet, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
267+
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
268+
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
269+
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
270+
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
271+
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
272+
WitnessUtxo,
271273
},
272274
v18::{
273275
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,

types/src/v20/util/into.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+
use bitcoin::{Address, ScriptBuf};
4+
5+
use super::{CreateMultisig, CreateMultisigError};
6+
use crate::model;
7+
8+
impl CreateMultisig {
9+
/// Converts version specific type to a version nonspecific, more strongly typed type.
10+
pub fn into_model(self) -> Result<model::CreateMultisig, CreateMultisigError> {
11+
use CreateMultisigError as E;
12+
13+
let address = self.address.parse::<Address<_>>().map_err(E::Address)?;
14+
let redeem_script = ScriptBuf::from_hex(&self.redeem_script).map_err(E::RedeemScript)?;
15+
16+
Ok(model::CreateMultisig {
17+
address,
18+
redeem_script,
19+
descriptor: Some(self.descriptor),
20+
warnings: None,
21+
})
22+
}
23+
}

types/src/v20/util/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v0.20` - util.
4+
//!
5+
//! Types for methods found under the `== Util ==` section of the API docs.
6+
7+
mod into;
8+
9+
use serde::{Deserialize, Serialize};
10+
11+
pub use super::CreateMultisigError;
12+
13+
/// Result of JSON-RPC method `createmultisig`.
14+
///
15+
/// > createmultisig nrequired ["key",...] ( "address_type" )
16+
/// >
17+
/// > Creates a multi-signature address with n signature of m keys required.
18+
/// > It returns a json object with the address and redeemScript.
19+
/// >
20+
/// > Arguments:
21+
/// > 1. nrequired (numeric, required) The number of required signatures out of the n keys.
22+
/// > 2. "keys" (string, required) A json array of hex-encoded public keys
23+
/// > [
24+
/// > "key" (string) The hex-encoded public key
25+
/// > ,...
26+
/// > ]
27+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
28+
pub struct CreateMultisig {
29+
/// The value of the new multisig address.
30+
pub address: String,
31+
/// The string value of the hex-encoded redemption script.
32+
#[serde(rename = "redeemScript")]
33+
pub redeem_script: String,
34+
/// The descriptor for this multisig.
35+
pub descriptor: String,
36+
}

types/src/v21/blockchain/into.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
11
// SPDX-License-Identifier: CC0-1.0
22

3-
use bitcoin::{Txid, Wtxid};
3+
use alloc::collections::BTreeMap;
44

5-
use super::{GetMempoolEntry, MempoolEntry, MempoolEntryError};
5+
use bitcoin::{BlockHash, Network, Txid, Work, Wtxid};
6+
7+
use super::{
8+
GetBlockchainInfo, GetBlockchainInfoError, GetMempoolEntry, GetMempoolInfo,
9+
GetMempoolInfoError, MempoolEntry, MempoolEntryError,
10+
};
611
use crate::model;
712

13+
impl GetBlockchainInfo {
14+
/// Converts version specific type to a version nonspecific, more strongly typed type.
15+
pub fn into_model(self) -> Result<model::GetBlockchainInfo, GetBlockchainInfoError> {
16+
use GetBlockchainInfoError as E;
17+
18+
let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
19+
let best_block_hash =
20+
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
21+
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
22+
let prune_height =
23+
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
24+
let prune_target_size =
25+
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
26+
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
27+
28+
Ok(model::GetBlockchainInfo {
29+
chain,
30+
blocks: crate::to_u32(self.blocks, "blocks")?,
31+
headers: crate::to_u32(self.headers, "headers")?,
32+
best_block_hash,
33+
bits: None,
34+
target: None,
35+
difficulty: self.difficulty,
36+
time: None,
37+
median_time: crate::to_u32(self.median_time, "median_time")?,
38+
verification_progress: self.verification_progress,
39+
initial_block_download: self.initial_block_download,
40+
chain_work,
41+
size_on_disk: self.size_on_disk,
42+
pruned: self.pruned,
43+
prune_height,
44+
automatic_pruning: self.automatic_pruning,
45+
prune_target_size,
46+
softforks,
47+
signet_challenge: None,
48+
warnings: vec![self.warnings],
49+
})
50+
}
51+
}
52+
853
impl GetMempoolEntry {
954
/// Converts version specific type to a version nonspecific, more strongly typed type.
1055
pub fn into_model(self) -> Result<model::GetMempoolEntry, MempoolEntryError> {
@@ -60,3 +105,30 @@ impl MempoolEntry {
60105
})
61106
}
62107
}
108+
109+
impl GetMempoolInfo {
110+
/// Converts version specific type to a version nonspecific, more strongly typed type.
111+
pub fn into_model(self) -> Result<model::GetMempoolInfo, GetMempoolInfoError> {
112+
let size = crate::to_u32(self.size, "size")?;
113+
let bytes = crate::to_u32(self.bytes, "bytes")?;
114+
let usage = crate::to_u32(self.usage, "usage")?;
115+
let max_mempool = crate::to_u32(self.max_mempool, "max_mempool")?;
116+
let mempool_min_fee = crate::btc_per_kb(self.mempool_min_fee)?;
117+
let min_relay_tx_fee = crate::btc_per_kb(self.min_relay_tx_fee)?;
118+
let unbroadcast_count = Some(crate::to_u32(self.unbroadcast_count, "unbroadcast_count")?);
119+
120+
Ok(model::GetMempoolInfo {
121+
loaded: Some(self.loaded),
122+
size,
123+
bytes,
124+
usage,
125+
total_fee: None,
126+
max_mempool,
127+
mempool_min_fee,
128+
min_relay_tx_fee,
129+
incremental_relay_fee: None,
130+
unbroadcast_count,
131+
full_rbf: None,
132+
})
133+
}
134+
}

0 commit comments

Comments
 (0)