Skip to content

Commit 999089e

Browse files
committed
Implement version specific types for blockchain - methods
1 parent 51beca6 commit 999089e

File tree

28 files changed

+74
-39
lines changed

28 files changed

+74
-39
lines changed

client/src/client_sync/v17/blockchain.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ macro_rules! impl_client_v17__savemempool {
321321
() => {
322322
impl Client {
323323
// Dumps the mempool to disk (v17 - v22)
324-
pub fn save_mempool(&self) -> Result<()> {
324+
pub fn save_mempool(&self) -> Result<SaveMempool> {
325325
match self.call("savemempool", &[]) {
326-
Ok(serde_json::Value::Null) => Ok(()),
327-
Ok(_) => Ok(()),
326+
Ok(serde_json::Value::Null) => Ok(SaveMempool),
327+
Ok(_) => Ok(SaveMempool),
328328
Err(e) => Err(e.into()),
329329
}
330330
}
@@ -339,7 +339,7 @@ macro_rules! impl_client_v17__verifychain {
339339
impl Client {
340340
/// Verifies blockchain database using default checklevel and nblocks.
341341
/// Returns true if verification finised successfully.
342-
pub fn verify_chain_default(&self) -> Result<bool> {
342+
pub fn verify_chain_default(&self) -> Result<VerifyChain> {
343343
// Core returns a boolean directly
344344
self.call("verifychain", &[])
345345
}
@@ -355,7 +355,7 @@ macro_rules! impl_client_v17__verifychain {
355355
&self,
356356
checklevel: Option<u32>,
357357
nblocks: Option<u32>,
358-
) -> Result<bool> {
358+
) -> Result<VerifyChain> {
359359
// Construct params carefully for optional args
360360
// Bitcoin Core often uses positional nulls for omitted optional args
361361
let params = match (checklevel, nblocks) {

integration_test/tests/blockchain.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,18 @@ fn blockchain__verify_chain() {
351351

352352
// Test with default parameters
353353
let result_default = node.client.verify_chain_default().expect("veifychain with defaults failed");
354-
assert!(result_default, "verifychain with defaults should return true on a clean chain");
354+
let result_default_value = result_default.0;
355+
assert!(result_default_value, "verifychain with defaults should return true on a clean chain");
355356

356357
// Test with specific parameters (e.g., check first 2 blocks thoroughly)
357358
let checklevel = Some(4u32);
358359
let nblocks = Some(2u32);
359360
let result_specific = node.client.verify_chain(checklevel, nblocks).expect("verifychain with specific args failed");
360-
assert!(result_specific, "verifychain with specific args should return true on a clean chain");
361+
let result_specific_value = result_specific.0;
362+
assert!(result_specific_value, "verifychain with specific args should return true on a clean chain");
361363

362364
// Test with only nblocks (requires null for checklevel)
363365
let result_nblocks_only = node.client.verify_chain(None, Some(1)).expect("verifychain with nblocks only failed");
364-
assert!(result_nblocks_only, "verifychain with nblocks only should return true");
366+
let result_nblocks_only_value = result_nblocks_only.0;
367+
assert!(result_nblocks_only_value, "verifychain with nblocks only should return true");
365368
}

types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub mod model;
3333

3434
use core::fmt;
3535

36+
use serde::{Deserialize, Serialize};
37+
3638
use bitcoin::amount::ParseAmountError;
3739
use bitcoin::{Amount, FeeRate};
3840

types/src/v17/blockchain/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ pub struct GetTxOutSetInfo {
660660
/// > Verifies that a proof points to a transaction in a block, returning the transaction it commits to
661661
/// > and throwing an RPC error if the block is not in our best chain
662662
/// >
663+
/// > Returns null (json null)
663664
/// > Arguments:
664665
/// > 1. "proof" (string, required) The hex-encoded proof generated by gettxoutproof
665666
///
@@ -678,4 +679,33 @@ pub struct VerifyTxOutProof(pub Vec<String>);
678679
pub struct PruneBlockchain(
679680
/// The height of the last block pruned.
680681
pub i64
681-
);
682+
);
683+
684+
/// Result of JSON-RPC method `savemempool`.
685+
///
686+
/// > savemempool
687+
/// >
688+
/// > Arguments:
689+
/// > 1. "height" (numeric, required) The block height to prune up to. May be set to a discrete height, or a unix timestamp
690+
/// > to prune blocks whose block time is at least 2 hours older than the provided timestamp.
691+
/// > Returns null (json null)
692+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
693+
pub struct SaveMempool;
694+
695+
/// Result of JSON-RPC method `verifychain`.
696+
///
697+
/// > verifychain
698+
/// >
699+
/// > Arguments:
700+
/// > 1. checklevel (numeric, optional, default=3, range=0-4) How thorough the block verification is:
701+
/// - level 0 reads the blocks from disk
702+
/// - level 1 verifies block validity
703+
/// - level 2 verifies undo data
704+
/// - level 3 checks disconnection of tip blocks
705+
/// - level 4 tries to reconnect the blocks
706+
/// - each level includes the checks of the previous levels
707+
/// > 2. nblocks (numeric, optional, default=6, 0=all) The number of blocks to check.
708+
/// >
709+
/// > Returns true|false (boolean) Verification finished successfully. If false, check debug.log for reason.
710+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
711+
pub struct VerifyChain(pub bool);

types/src/v17/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub use self::{
235235
GetRawMempool, GetRawMempoolVerbose, GetTxOut, GetTxOutError, GetTxOutSetInfo,
236236
GetTxOutSetInfoError, MapMempoolEntryError, MempoolEntry, MempoolEntryError,
237237
MempoolEntryFees, MempoolEntryFeesError, ScriptPubkey, Softfork, SoftforkReject,
238-
VerifyTxOutProof, PruneBlockchain
238+
VerifyTxOutProof, PruneBlockchain, SaveMempool, VerifyChain,
239239
},
240240
control::{GetMemoryInfoStats, Locked, Logging},
241241
generating::{Generate, GenerateToAddress},

types/src/v18/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,5 @@ pub use crate::v17::{
260260
SendRawTransaction, SendToAddress, SignErrorData, SignErrorDataError, SignMessage,
261261
SignRawTransactionWithWallet, SignRawTransactionWithWalletError, Softfork, SoftforkReject,
262262
TransactionCategory, UploadTarget, VerifyTxOutProof, WalletCreateFundedPsbt,
263-
WalletCreateFundedPsbtError, WalletProcessPsbt, SetNetworkActive,
263+
WalletCreateFundedPsbtError, WalletProcessPsbt, SetNetworkActive, SaveMempool, VerifyChain,
264264
};

types/src/v19/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pub use crate::v17::{
263263
RescanBlockchain, ScriptPubkey, SendMany, SendRawTransaction, SendToAddress, SignErrorData,
264264
SignErrorDataError, SignMessage, SignRawTransactionWithWallet,
265265
SignRawTransactionWithWalletError, SoftforkReject, TransactionCategory, UploadTarget,
266-
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt, SetNetworkActive,
266+
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt, SetNetworkActive, SaveMempool, VerifyChain,
267267
};
268268
#[doc(inline)]
269269
pub use crate::v18::{ActiveCommand, GetRpcInfo};

types/src/v20/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub use crate::{
254254
PeerInfo, RescanBlockchain, ScriptPubkey, SendMany, SendRawTransaction, SendToAddress,
255255
SignErrorData, SignMessage, SignRawTransactionWithWallet, SoftforkReject,
256256
TransactionCategory, UploadTarget, VerifyTxOutProof, WalletCreateFundedPsbt,
257-
WalletProcessPsbt,
257+
WalletProcessPsbt, SaveMempool, VerifyChain,
258258
},
259259
v18::{ActiveCommand, GetRpcInfo},
260260
v19::{

types/src/v21/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pub use crate::{
259259
PeerInfo, RescanBlockchain, ScriptPubkey, SendMany, SendRawTransaction, SendToAddress,
260260
SignErrorData, SignMessage, SignRawTransactionWithWallet, SoftforkReject,
261261
TransactionCategory, UploadTarget, VerifyTxOutProof, WalletCreateFundedPsbt,
262-
WalletProcessPsbt,
262+
WalletProcessPsbt, SaveMempool, VerifyChain,
263263
},
264264
v18::{ActiveCommand, GetRpcInfo},
265265
v19::{

types/src/v22/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub use crate::{
273273
ListUnspentItem, ListWallets, LoadWallet, Locked, PeerInfo, RescanBlockchain, SendMany,
274274
SendRawTransaction, SendToAddress, SignErrorData, SignMessage,
275275
SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget,
276-
VerifyTxOutProof, WalletCreateFundedPsbt, WalletProcessPsbt,
276+
VerifyTxOutProof, WalletCreateFundedPsbt, WalletProcessPsbt, SaveMempool, VerifyChain,
277277
},
278278
v18::{ActiveCommand, GetRpcInfo},
279279
v19::{

0 commit comments

Comments
 (0)