Skip to content

Commit 51beca6

Browse files
committed
Implement version specific types for network - methods
1 parent 905d962 commit 51beca6

File tree

42 files changed

+312
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+312
-152
lines changed

client/src/client_sync/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,41 @@ pub struct LockUnspentOutput {
288288
/// The output number
289289
pub vout: u32,
290290
}
291+
292+
/// Args for the `scantxoutset`
293+
///
294+
/// Represents the action for the `scantxoutset` RPC call.
295+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
296+
#[serde(rename_all = "lowercase")]
297+
pub enum ScanAction {
298+
Start,
299+
Abort,
300+
Status,
301+
}
302+
303+
/// Represents the range for HD descriptor scanning.
304+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
305+
#[serde(untagged)]
306+
pub enum ScanRange {
307+
Single(u64),
308+
Range([u64; 2]),
309+
}
310+
311+
// Helper function for serde default
312+
fn default_scan_range() -> ScanRange {
313+
// Default range is 1000 as per Bitcoin Core docs
314+
ScanRange::Single(1000)
315+
}
316+
317+
/// Represents a scan object for scantxoutset, either a descriptor string
318+
/// or an object with descriptor and range.
319+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
320+
#[serde(untagged)]
321+
pub enum ScanObject {
322+
Descriptor(String),
323+
WithRange {
324+
desc: String,
325+
#[serde(default = "default_scan_range")]
326+
range: ScanRange,
327+
},
328+
}

client/src/client_sync/v17/network.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ macro_rules! impl_client_v17__getpeerinfo {
6464
macro_rules! impl_client_v17__addnode {
6565
() => {
6666
impl Client {
67-
pub fn add_node(&self, node: &str, command: AddNodeCommand) -> Result<()> {
67+
pub fn add_node(&self, node: &str, command: AddNodeCommand) -> Result<AddNode> {
6868
let params = &[node.into(), serde_json::to_value(command)?];
6969

7070
match self.call("addnode", params) {
71-
Ok(serde_json::Value::Null) => Ok(()),
72-
Ok(ref val) if val.is_null() => Ok(()),
71+
Ok(serde_json::Value::Null) => Ok(AddNode),
72+
Ok(ref val) if val.is_null() => Ok(AddNode),
7373
Ok(other) => {
74-
Err(crate::client_sync::Error::Returned(format!(
74+
Err(Error::Returned(format!(
7575
"addnode expected null, got: {}", other
7676
)))
7777
},
@@ -87,11 +87,11 @@ macro_rules! impl_client_v17__addnode {
8787
macro_rules! impl_client_v17__clearbanned {
8888
() => {
8989
impl Client {
90-
pub fn clear_banned(&self) -> Result<()> {
90+
pub fn clear_banned(&self) -> Result<ClearBanned> {
9191
match self.call("clearbanned", &[]) {
92-
Ok(serde_json::Value::Null) => Ok(()),
93-
Ok(ref val) if val.is_null() => Ok(()),
94-
Ok(other) => Err(crate::client_sync::Error::Returned(format!("clearbanned expected null, got: {}", other))),
92+
Ok(serde_json::Value::Null) => Ok(ClearBanned),
93+
Ok(ref val) if val.is_null() => Ok(ClearBanned),
94+
Ok(other) => Err(Error::Returned(format!("clearbanned expected null, got: {}", other))),
9595
Err(e) => Err(e.into()),
9696
}
9797
}
@@ -110,7 +110,7 @@ macro_rules! impl_client_v17__setban {
110110
command: SetBanCommand,
111111
bantime: Option<i64>,
112112
absolute: Option<bool>,
113-
) -> Result<()> {
113+
) -> Result<SetBan> {
114114
let mut params: Vec<serde_json::Value> = vec![subnet.into(), serde_json::to_value(command)?,];
115115

116116
if bantime.is_some() || absolute.is_some() {
@@ -122,10 +122,10 @@ macro_rules! impl_client_v17__setban {
122122
}
123123

124124
match self.call("setban", &params) {
125-
Ok(serde_json::Value::Null) => Ok(()),
126-
Ok(ref val) if val.is_null() => Ok(()),
125+
Ok(serde_json::Value::Null) => Ok(SetBan),
126+
Ok(ref val) if val.is_null() => Ok(SetBan),
127127
Ok(other) => {
128-
Err(crate::client_sync::Error::Returned(format!("setban expected null, got: {}", other)))
128+
Err(Error::Returned(format!("setban expected null, got: {}", other)))
129129
},
130130
Err(e) => Err(e.into()),
131131
}
@@ -155,7 +155,7 @@ macro_rules! impl_client_v17__disconnectnode {
155155
&self,
156156
address: Option<&str>,
157157
nodeid: Option<u64>,
158-
) -> Result<()> {
158+
) -> Result<DisconnectNode> {
159159
let params: Vec<serde_json::Value> = match (address, nodeid) {
160160
(Some(addr), None) => {
161161
vec![addr.into()]
@@ -164,18 +164,18 @@ macro_rules! impl_client_v17__disconnectnode {
164164
vec![serde_json::Value::String(String::new()), id.into()]
165165
}
166166
(Some(_), Some(_)) => {
167-
return Err(crate::client_sync::Error::DisconnectNodeArgsBoth);
167+
return Err(Error::DisconnectNodeArgsBoth);
168168
}
169169
(None, None) => {
170-
return Err(crate::client_sync::Error::DisconnectNodeArgsNone);
170+
return Err(Error::DisconnectNodeArgsNone);
171171
}
172172
};
173173

174174
match self.call("disconnectnode", &params) {
175-
Ok(serde_json::Value::Null) => Ok(()),
176-
Ok(ref val) if val.is_null() => Ok(()),
175+
Ok(serde_json::Value::Null) => Ok(DisconnectNode),
176+
Ok(ref val) if val.is_null() => Ok(DisconnectNode),
177177
Ok(other) => {
178-
Err(crate::client_sync::Error::Returned(format!("disconnectnode expected null, got: {}", other)))
178+
Err(Error::Returned(format!("disconnectnode expected null, got: {}", other)))
179179
}
180180
Err(e) => Err(e.into()),
181181
}
@@ -189,7 +189,7 @@ macro_rules! impl_client_v17__disconnectnode {
189189
macro_rules! impl_client_v17__getconnectioncount {
190190
() => {
191191
impl Client {
192-
pub fn get_connection_count(&self) -> Result<u64> {
192+
pub fn get_connection_count(&self) -> Result<GetConnectionCount> {
193193
self.call("getconnectioncount", &[])
194194
}
195195
}
@@ -201,12 +201,12 @@ macro_rules! impl_client_v17__getconnectioncount {
201201
macro_rules! impl_client_v17__ping {
202202
() => {
203203
impl Client {
204-
pub fn ping(&self) -> Result<()> {
204+
pub fn ping(&self) -> Result<Ping> {
205205
match self.call("ping", &[]) {
206-
Ok(serde_json::Value::Null) => Ok(()),
207-
Ok(ref val) if val.is_null() => Ok(()),
206+
Ok(serde_json::Value::Null) => Ok(Ping),
207+
Ok(ref val) if val.is_null() => Ok(Ping),
208208
Ok(other) => {
209-
Err(crate::client_sync::Error::Returned(format!("ping expected null, got: {}", other)))
209+
Err(Error::Returned(format!("ping expected null, got: {}", other)))
210210
}
211211
Err(e) => Err(e.into()),
212212
}
@@ -220,12 +220,12 @@ macro_rules! impl_client_v17__ping {
220220
macro_rules! impl_client_v17__setnetworkactive {
221221
() => {
222222
impl Client {
223-
pub fn set_network_active(&self, state: bool) -> Result<()> {
223+
pub fn set_network_active(&self, state: bool) -> Result<SetNetworkActive> {
224224
match self.call("setnetworkactive", &[state.into()]) {
225-
Ok(serde_json::Value::Null) => Ok(()),
226-
Ok(ref val) if val.is_null() => Ok(()),
225+
Ok(serde_json::Value::Null) => Ok(SetNetworkActive),
226+
Ok(ref val) if val.is_null() => Ok(SetNetworkActive),
227227
Ok(other) => {
228-
Err(crate::client_sync::Error::Returned(format!("setnetworkactive expected null, got: {}", other)))
228+
Err(Error::Returned(format!("setnetworkactive expected null, got: {}", other)))
229229
}
230230
Err(e) => Err(e.into()),
231231
}
@@ -245,7 +245,7 @@ macro_rules! impl_client_v17__importprivkey {
245245
privkey: &PrivateKey,
246246
label: Option<&str>,
247247
rescan: Option<bool>,
248-
) -> Result<()> {
248+
) -> Result<ImportPrivKey> {
249249
let privkey_wif = privkey.to_wif();
250250
let mut params = vec![privkey_wif.into()];
251251

@@ -258,9 +258,9 @@ macro_rules! impl_client_v17__importprivkey {
258258
}
259259

260260
match self.call("importprivkey", &params) {
261-
Ok(serde_json::Value::Null) => Ok(()),
262-
Ok(ref val) if val.is_null() => Ok(()),
263-
Ok(other) => Err(crate::client_sync::Error::Returned(format!("importprivkey expected null, got: {}", other))),
261+
Ok(serde_json::Value::Null) => Ok(ImportPrivKey),
262+
Ok(ref val) if val.is_null() => Ok(ImportPrivKey),
263+
Ok(other) => Err(Error::Returned(format!("importprivkey expected null, got: {}", other))),
264264
Err(e) => Err(e.into()),
265265
}
266266
}

client/src/client_sync/v18/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1414

1515
use crate::client_sync::into_json;
1616
use crate::client_sync::{AddNodeCommand, SetBanCommand};
17+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, SetNetworkActive, ImportPrivKey, GetConnectionCount};
1718
use crate::types::v18::*;
1819

1920
#[rustfmt::skip] // Keep public re-exports separate.

client/src/client_sync/v19/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1515

1616
use crate::client_sync::into_json;
1717
use crate::client_sync::{AddNodeCommand, SetBanCommand};
18+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, SetNetworkActive, ImportPrivKey, GetConnectionCount};
1819
use crate::types::v19::*;
1920

2021
#[rustfmt::skip] // Keep public re-exports separate.

client/src/client_sync/v20/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1414

1515
use crate::client_sync::into_json;
1616
use crate::client_sync::{AddNodeCommand, SetBanCommand};
17+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, ImportPrivKey, GetConnectionCount};
1718
use crate::types::v20::*;
1819

1920
#[rustfmt::skip] // Keep public re-exports separate.

client/src/client_sync/v20/network.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
macro_rules! impl_client_v20__setnetworkactive {
1515
() => {
1616
impl Client {
17-
pub fn set_network_active(&self, state: bool) -> Result<bool> {
17+
pub fn set_network_active(&self, state: bool) -> Result<SetNetworkActive> {
1818
self.call("setnetworkactive", &[state.into()])
1919
}
2020
}
2121
};
2222
}
23-

client/src/client_sync/v21/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1414

1515
use crate::client_sync::into_json;
1616
use crate::client_sync::{AddNodeCommand, SetBanCommand};
17+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, SetNetworkActive, ImportPrivKey, GetConnectionCount};
1718
use crate::types::v21::*;
1819

1920
#[rustfmt::skip] // Keep public re-exports separate.

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1515

1616
use crate::client_sync::into_json;
1717
use crate::client_sync::{AddNodeCommand, SetBanCommand};
18+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, SetNetworkActive, ImportPrivKey, GetConnectionCount};
1819
use crate::types::v22::*;
1920

2021
#[rustfmt::skip] // Keep public re-exports separate.

client/src/client_sync/v23/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize};
1616

1717
use crate::client_sync::into_json;
1818
use crate::client_sync::{AddNodeCommand, SetBanCommand};
19+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, SetNetworkActive, ImportPrivKey, GetConnectionCount};
1920
use crate::types::v23::*;
2021

2122
#[rustfmt::skip] // Keep public re-exports separate.

client/src/client_sync/v24.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1212

1313
use crate::client_sync::into_json;
1414
use crate::client_sync::{AddNodeCommand, SetBanCommand};
15+
use crate::types::v17::{AddNode, ClearBanned, SetBan, DisconnectNode, Ping, SetNetworkActive, ImportPrivKey, GetConnectionCount};
1516
use crate::types::v24::*;
1617

1718
#[rustfmt::skip] // Keep public re-exports separate.

0 commit comments

Comments
 (0)