Skip to content

Commit 60f8e75

Browse files
committed
Add missing getblocktemplate fields to v17
There are return fields in v17 onwards that are undocumented until v29 Add the fields to v17. Remove the redefinition in v29 since it is now the same as v17, only the help output changed.
1 parent 09d0f90 commit 60f8e75

File tree

7 files changed

+33
-207
lines changed

7 files changed

+33
-207
lines changed

types/src/model/mining.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub struct GetBlockTemplate {
2424
/// Map of rules name to bit number - identifies the bit number as indicating acceptance and
2525
/// readiness for the named softfork rule.
2626
pub version_bits_available: BTreeMap<String, u32>,
27+
/// Client side supported features.
28+
pub capabilities: Vec<String>,
2729
/// Bit mask of versionbits the server requires set in submissions.
2830
pub version_bits_required: u32,
2931
/// The hash of current highest block.
@@ -37,6 +39,8 @@ pub struct GetBlockTemplate {
3739
/// Maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis).
3840
#[serde(with = "bitcoin::amount::serde::as_sat")]
3941
pub coinbase_value: SignedAmount,
42+
/// An id to include with a request to longpoll on an update to this template.
43+
pub long_poll_id: Option<String>,
4044
/// The hash target.
4145
pub target: Vec<u8>,
4246
/// The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT).
@@ -59,6 +63,10 @@ pub struct GetBlockTemplate {
5963
pub bits: CompactTarget,
6064
/// The height of the next block,
6165
pub height: u32,
66+
/// Optional signet challenge
67+
pub signet_challenge: Option<String>,
68+
/// A valid witness commitment for the unmodified block template.
69+
pub default_witness_commitment: Option<String>,
6270
}
6371

6472
/// Contents of non-coinbase transactions that should be included in the next block.

types/src/v17/mining/into.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ impl GetBlockTemplate {
1717
use GetBlockTemplateError as E;
1818

1919
let version = block::Version::from_consensus(self.version);
20+
let capabilities = self
21+
.capabilities
22+
.into_iter()
23+
.map(|s| s.to_string())
24+
.collect::<Vec<_>>();
2025
let version_bits_required =
2126
crate::to_u32(self.version_bits_required, "version_bits_required")?;
2227
let previous_block_hash =
@@ -39,11 +44,13 @@ impl GetBlockTemplate {
3944
version,
4045
rules: self.rules,
4146
version_bits_available: self.version_bits_available,
47+
capabilities,
4248
version_bits_required,
4349
previous_block_hash,
4450
transactions,
4551
coinbase_aux: self.coinbase_aux,
4652
coinbase_value,
53+
long_poll_id: self.long_poll_id,
4754
target,
4855
min_time: self.min_time,
4956
mutable: self.mutable,
@@ -54,6 +61,8 @@ impl GetBlockTemplate {
5461
current_time: self.current_time,
5562
bits,
5663
height,
64+
signet_challenge: self.signet_challenge,
65+
default_witness_commitment: self.default_witness_commitment,
5766
})
5867
}
5968
}

types/src/v17/mining/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub struct GetBlockTemplate {
5353
/// readiness for the named softfork rule.
5454
#[serde(rename = "vbavailable")]
5555
pub version_bits_available: BTreeMap<String, u32>,
56+
/// Client side supported features.
57+
pub capabilities: Vec<String>,
5658
/// Bit mask of versionbits the server requires set in submissions.
5759
#[serde(rename = "vbrequired")]
5860
pub version_bits_required: i64,
@@ -69,6 +71,9 @@ pub struct GetBlockTemplate {
6971
/// Maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis).
7072
#[serde(rename = "coinbasevalue")]
7173
pub coinbase_value: i64,
74+
/// An id to include with a request to longpoll on an update to this template.
75+
#[serde(rename = "longpollid")]
76+
pub long_poll_id: Option<String>,
7277
// This is in the docs but not actually returned (for v0.17 and v0.18 at least).
7378
// coinbase_txn: ???, // Also I don't know what the JSON object represents: `{ ... }`
7479
/// The hash target.
@@ -78,7 +83,7 @@ pub struct GetBlockTemplate {
7883
pub min_time: u32,
7984
/// List of ways the block template may be changed.
8085
///
81-
/// A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'
86+
/// A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'.
8287
pub mutable: Vec<String>,
8388
/// A range of valid nonces.
8489
#[serde(rename = "noncerange")]
@@ -97,8 +102,12 @@ pub struct GetBlockTemplate {
97102
pub current_time: u64,
98103
/// Compressed target of next block.
99104
pub bits: String,
100-
/// The height of the next block,
105+
/// The height of the next block.
101106
pub height: i64,
107+
/// Optional signet challenge.
108+
pub signet_challenge: Option<String>,
109+
/// A valid witness commitment for the unmodified block template.
110+
pub default_witness_commitment: Option<String>,
102111
}
103112

104113
/// Contents of non-coinbase transactions that should be included in the next block.

types/src/v29/mining/error.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,11 @@ use core::fmt;
44

55
use bitcoin::amount::ParseAmountError;
66
use bitcoin::error::UnprefixedHexError;
7-
use bitcoin::hex::HexToBytesError;
87
use bitcoin::{consensus, hex};
98

109
use crate::error::write_err;
1110
use crate::NumericError;
1211

13-
/// Error when converting a `GetBlockTemplate` type into the model type.
14-
#[derive(Debug)]
15-
pub enum GetBlockTemplateError {
16-
/// Conversion of numeric type to expected type failed.
17-
Numeric(NumericError),
18-
/// Conversion of the `previous_block_hash` field failed.
19-
PreviousBlockHash(hex::HexToArrayError),
20-
/// Conversion of the `transactions` field failed.
21-
Transactions(BlockTemplateTransactionError),
22-
/// Conversion of the `target` field failed.
23-
Target(HexToBytesError),
24-
/// Conversion of the `bits` field failed.
25-
Bits(UnprefixedHexError),
26-
}
27-
28-
impl fmt::Display for GetBlockTemplateError {
29-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30-
use GetBlockTemplateError as E;
31-
32-
match *self {
33-
E::Numeric(ref e) => write_err!(f, "numeric"; e),
34-
E::PreviousBlockHash(ref e) =>
35-
write_err!(f, "conversion of the `previous_block_hash` field failed"; e),
36-
E::Transactions(ref e) =>
37-
write_err!(f, "conversion of the `transactions` field failed"; e),
38-
E::Target(ref e) => write_err!(f, "conversion of the `target` field failed"; e),
39-
E::Bits(ref e) => write_err!(f, "conversion of the `bits` field failed"; e),
40-
}
41-
}
42-
}
43-
44-
#[cfg(feature = "std")]
45-
impl std::error::Error for GetBlockTemplateError {
46-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
47-
use GetBlockTemplateError as E;
48-
49-
match *self {
50-
E::Numeric(ref e) => Some(e),
51-
E::PreviousBlockHash(ref e) => Some(e),
52-
E::Transactions(ref e) => Some(e),
53-
E::Target(ref e) => Some(e),
54-
E::Bits(ref e) => Some(e),
55-
}
56-
}
57-
}
58-
59-
impl From<NumericError> for GetBlockTemplateError {
60-
fn from(e: NumericError) -> Self { Self::Numeric(e) }
61-
}
62-
6312
/// Error when converting a `BlockTemplateTransaction` type into the model type.
6413
#[derive(Debug)]
6514
pub enum BlockTemplateTransactionError {

types/src/v29/mining/into.rs

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

3-
use bitcoin::hex::FromHex as _;
43
use bitcoin::{
5-
block, consensus, BlockHash, CompactTarget, SignedAmount, Target, Transaction, Txid, Weight,
4+
consensus, CompactTarget, SignedAmount, Target, Transaction, Txid, Weight,
65
Wtxid,
76
};
87

98
use super::{
10-
BlockTemplateTransaction, BlockTemplateTransactionError, GetBlockTemplate,
11-
GetBlockTemplateError, GetMiningInfo, GetMiningInfoError, NextBlockInfo, NextBlockInfoError,
9+
BlockTemplateTransaction, BlockTemplateTransactionError, GetMiningInfo, GetMiningInfoError, NextBlockInfo, NextBlockInfoError,
1210
};
1311
use crate::model;
1412

15-
impl GetBlockTemplate {
16-
/// Converts version specific type to a version nonspecific, more strongly typed type.
17-
pub fn into_model(self) -> Result<model::GetBlockTemplate, GetBlockTemplateError> {
18-
use GetBlockTemplateError as E;
19-
20-
let version = block::Version::from_consensus(self.version);
21-
let version_bits_required =
22-
crate::to_u32(self.version_bits_required, "version_bits_required")?;
23-
let previous_block_hash =
24-
self.previous_block_hash.parse::<BlockHash>().map_err(E::PreviousBlockHash)?;
25-
let transactions = self
26-
.transactions
27-
.into_iter()
28-
.map(|t| t.into_model())
29-
.collect::<Result<Vec<_>, _>>()
30-
.map_err(E::Transactions)?;
31-
let coinbase_value = SignedAmount::from_sat(self.coinbase_value);
32-
let target = Vec::from_hex(&self.target).map_err(E::Target)?;
33-
let sigop_limit = crate::to_u32(self.sigop_limit, "sigop_limit")?;
34-
let weight_limit = crate::to_u32(self.weight_limit, "weight_limit")?;
35-
let size_limit = crate::to_u32(self.size_limit, "size_limit")?;
36-
let bits = CompactTarget::from_unprefixed_hex(&self.bits).map_err(E::Bits)?;
37-
let height = crate::to_u32(self.height, "height")?;
38-
39-
Ok(model::GetBlockTemplate {
40-
version,
41-
rules: self.rules,
42-
version_bits_available: self.version_bits_available,
43-
version_bits_required,
44-
previous_block_hash,
45-
transactions,
46-
coinbase_aux: self.coinbase_aux,
47-
coinbase_value,
48-
target,
49-
min_time: self.min_time,
50-
mutable: self.mutable,
51-
nonce_range: self.nonce_range,
52-
sigop_limit,
53-
weight_limit,
54-
size_limit,
55-
current_time: self.current_time,
56-
bits,
57-
height,
58-
})
59-
}
60-
}
61-
6213
impl BlockTemplateTransaction {
6314
/// Converts version specific type to a version nonspecific, more strongly typed type.
6415
pub fn into_model(

types/src/v29/mining/mod.rs

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7,112 +7,12 @@
77
mod error;
88
mod into;
99

10-
use std::collections::BTreeMap;
11-
1210
use serde::{Deserialize, Serialize};
1311

1412
pub use self::error::{
15-
BlockTemplateTransactionError, GetBlockTemplateError, GetMiningInfoError, NextBlockInfoError,
13+
BlockTemplateTransactionError, GetMiningInfoError, NextBlockInfoError,
1614
};
1715

18-
/// Result of the JSON-RPC method `getblocktemplate`.
19-
///
20-
/// > getblocktemplate {"mode":"str","capabilities":["str",...],"rules":["segwit","str",...],"longpollid":"str","data":"hex"}
21-
/// >
22-
/// > If the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.
23-
/// > It returns data needed to construct a block to work on.
24-
/// > For full specification, see BIPs 22, 23, 9, and 145:
25-
/// > <https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki>
26-
/// > <https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki>
27-
/// > <https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes>
28-
/// > <https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki>
29-
/// >
30-
/// > Arguments:
31-
/// > 1. template_request (json object, required) Format of the template
32-
/// > {
33-
/// > "mode": "str", (string, optional) This must be set to "template", "proposal" (see BIP 23), or omitted
34-
/// > "capabilities": [ (json array, optional) A list of strings
35-
/// > "str", (string) client side supported feature, 'longpoll', 'coinbasevalue', 'proposal', 'serverlist', 'workid'
36-
/// > ...
37-
/// > ],
38-
/// > "rules": [ (json array, required) A list of strings
39-
/// > "segwit", (string, required) (literal) indicates client side segwit support
40-
/// > "str", (string) other client side supported softfork deployment
41-
/// > ...
42-
/// > ],
43-
/// > "longpollid": "str", (string, optional) delay processing request until the result would vary significantly from the "longpollid" of a prior template
44-
/// > "data": "hex", (string, optional) proposed block data to check, encoded in hexadecimal; valid only for mode="proposal"
45-
/// > }
46-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
47-
pub struct GetBlockTemplate {
48-
/// The preferred block version.
49-
pub version: i32,
50-
/// Specific block rules that are to be enforced.
51-
pub rules: Vec<String>,
52-
/// Set of pending, supported versionbit (BIP 9) softfork deployments.
53-
///
54-
/// Map of rules name to bit number - identifies the bit number as indicating acceptance and
55-
/// readiness for the named softfork rule.
56-
#[serde(rename = "vbavailable")]
57-
pub version_bits_available: BTreeMap<String, u32>,
58-
/// Bit mask of versionbits the server requires set in submissions.
59-
#[serde(rename = "vbrequired")]
60-
pub version_bits_required: i64,
61-
/// The hash of current highest block.
62-
#[serde(rename = "previousblockhash")]
63-
pub previous_block_hash: String,
64-
/// Contents of non-coinbase transactions that should be included in the next block.
65-
pub transactions: Vec<BlockTemplateTransaction>,
66-
/// Data that should be included in the coinbase's scriptSig content.
67-
///
68-
/// Key name is to be ignored, and value included in scriptSig.
69-
#[serde(rename = "coinbaseaux")]
70-
pub coinbase_aux: BTreeMap<String, String>,
71-
/// Maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis).
72-
#[serde(rename = "coinbasevalue")]
73-
pub coinbase_value: i64,
74-
/// A list of supported features,for example `proposal`
75-
pub capabilities: Vec<String>,
76-
/// ID to include with a request to longpoll on an update to this template.
77-
#[serde(rename = "longpollid")]
78-
pub long_poll_id: String,
79-
// This is in the docs but not actually returned (for v0.17 and v0.18 at least).
80-
// coinbase_txn: ???, // Also I don't know what the JSON object represents: `{ ... }`
81-
/// The hash target.
82-
pub target: String,
83-
/// The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT).
84-
#[serde(rename = "mintime")]
85-
pub min_time: u32,
86-
/// List of ways the block template may be changed.
87-
///
88-
/// A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'
89-
pub mutable: Vec<String>,
90-
/// A range of valid nonces.
91-
#[serde(rename = "noncerange")]
92-
pub nonce_range: String,
93-
/// Limit of sigops in blocks.
94-
#[serde(rename = "sigoplimit")]
95-
pub sigop_limit: i64,
96-
/// Limit of block size.
97-
#[serde(rename = "sizelimit")]
98-
pub size_limit: i64,
99-
/// Limit of block weight.
100-
#[serde(rename = "weightlimit")]
101-
pub weight_limit: i64,
102-
/// Current timestamp in seconds since epoch (Jan 1 1970 GMT).
103-
#[serde(rename = "curtime")]
104-
pub current_time: u64,
105-
/// Compressed target of next block.
106-
pub bits: String,
107-
/// The height of the next block,
108-
pub height: i64,
109-
/// Optional signet challenge
110-
#[serde(rename = "signet_challenge")]
111-
pub signet_challenge: Option<String>,
112-
#[serde(rename = "defaultwitnesscommitment")]
113-
pub default_witness_commitment: Option<String>,
114-
}
115-
11616
/// Contents of non-coinbase transactions that should be included in the next block.
11717
///
11818
/// Returned as part of `getblocktemplate`.

types/src/v29/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub use self::{
265265
SpendActivity,
266266
},
267267
mining::{
268-
BlockTemplateTransaction, GetBlockTemplate, GetBlockTemplateError, GetMiningInfo,
268+
BlockTemplateTransaction, GetMiningInfo,
269269
GetMiningInfoError, NextBlockInfo, NextBlockInfoError,
270270
},
271271
network::GetNetworkInfo,
@@ -302,7 +302,7 @@ pub use crate::{
302302
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
303303
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
304304
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
305-
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
305+
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, GetBlockTemplate, GetBlockTemplateError,
306306
},
307307
v18::{
308308
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,

0 commit comments

Comments
 (0)