Skip to content

Implement setnetworkactive method and test #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ crate::impl_client_v17__get_network_info!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v17__combine_psbt!();
Expand Down
12 changes: 12 additions & 0 deletions client/src/client_sync/v17/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,15 @@ macro_rules! impl_client_v17__set_ban {
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `setnetworkactive`
#[macro_export]
macro_rules! impl_client_v17__set_network_active {
() => {
impl Client {
pub fn set_network_active(&self, state: bool) -> Result<SetNetworkActive> {
self.call("setnetworkactive", &[into_json(state)?])
}
}
};
}
1 change: 1 addition & 0 deletions client/src/client_sync/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ crate::impl_client_v18__get_node_addresses!();
crate::impl_client_v17__get_peer_info!();
crate::impl_client_v17__ping!();
crate::impl_client_v17__set_ban!();
crate::impl_client_v17__set_network_active!();

// == Rawtransactions ==
crate::impl_client_v18__analyze_psbt!();
Expand Down
10 changes: 10 additions & 0 deletions integration_test/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ fn network__set_ban() {
node.client.set_ban(dummy_subnet, SetBanCommand::Add).expect("setban add");
node.client.set_ban(dummy_subnet, SetBanCommand::Remove).expect("setban remove");
}

#[test]
fn network__set_network_active() {
let node = Node::with_wallet(Wallet::None, &[]);
let json: SetNetworkActive = node.client.set_network_active(false).expect("setnetworkactive false");
assert!(json.0 == false);

let json: SetNetworkActive = node.client.set_network_active(true).expect("setnetworkactive true");
assert!(json.0 == true);
}
4 changes: 2 additions & 2 deletions types/src/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -255,7 +255,7 @@ pub use self::{
network::{
AddedNode, AddedNodeAddress, Banned, GetAddedNodeInfo, GetConnectionCount, GetNetTotals,
GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
GetPeerInfo, ListBanned, PeerInfo, UploadTarget,
GetPeerInfo, ListBanned, PeerInfo, SetNetworkActive, UploadTarget,
},
raw_transactions::{
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreatePsbt, CreateRawTransaction,
Expand Down
8 changes: 8 additions & 0 deletions types/src/v17/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,11 @@ pub struct ListBanned(pub Vec<Banned>);
/// An item from the list returned by the JSON-RPC method `listbanned`
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Banned(String); // FIXME: The docs are empty so I don't know what shape this is.

/// Result of JSON-RPC method `setnetworkactive`.
///
/// > setnetworkactive
/// >
/// > Disable/enable all p2p network activity.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct SetNetworkActive(pub bool);
4 changes: 2 additions & 2 deletions types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -270,7 +270,7 @@ pub use crate::v17::{
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript, RawTransaction, RawTransactionError,
RawTransactionInput, RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction,
SendToAddress, SignFail, SignFailError, SignMessage, SignMessageWithPrivKey,
SendToAddress, SetNetworkActive, SignFail, SignFailError, SignMessage, SignMessageWithPrivKey,
SignRawTransaction, SignRawTransactionError, Softfork, SoftforkReject, TestMempoolAccept,
TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain,
VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -267,7 +267,7 @@ pub use crate::v17::{
ListTransactions, ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError,
ListWallets, LoadWallet, Locked, Logging, PeerInfo, PruneBlockchain, RawTransactionError,
RawTransactionInput, RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction,
SendToAddress, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SendToAddress, SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget,
ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof,
WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
Expand Down
8 changes: 4 additions & 4 deletions types/src/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -260,9 +260,9 @@ pub use crate::{
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked, PeerInfo,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SoftforkReject,
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
},
Expand Down
8 changes: 4 additions & 4 deletions types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -266,9 +266,9 @@ pub use crate::{
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked, PeerInfo,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SoftforkReject,
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
},
Expand Down
8 changes: 4 additions & 4 deletions types/src/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -277,9 +277,9 @@ pub use crate::{
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked, PeerInfo,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SoftforkReject,
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
},
Expand Down
11 changes: 6 additions & 5 deletions types/src/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -276,10 +276,11 @@ pub use crate::{
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, Locked, PeerInfo, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
WitnessUtxo,
},
v18::{
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
Expand Down
11 changes: 6 additions & 5 deletions types/src/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -277,10 +277,11 @@ pub use crate::{
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, Locked, PeerInfo, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
WitnessUtxo,
},
v18::{
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
Expand Down
8 changes: 4 additions & 4 deletions types/src/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
//! | listbanned | returns string | |
//! | ping | returns nothing | |
//! | setban | returns nothing | |
//! | setnetworkactive | returns nothing | |
//! | setnetworkactive | version | |
//!
//! </details>
//!
Expand Down Expand Up @@ -273,9 +273,9 @@ pub use crate::{
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets, Locked,
PeerInfo, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SignMessage,
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SoftforkReject,
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
},
Expand Down
Loading