Skip to content

Commit 3ebec0f

Browse files
authored
Merge pull request #156 from tcharding/05-11-client-types
client: Move types to version specific module
2 parents 28238e0 + 1c8f746 commit 3ebec0f

File tree

20 files changed

+77
-98
lines changed

20 files changed

+77
-98
lines changed

client/src/client_sync/mod.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ pub mod v26;
1616
pub mod v27;
1717
pub mod v28;
1818

19-
use std::collections::HashMap;
2019
use std::fs::File;
2120
use std::io::{BufRead, BufReader};
2221
use std::path::PathBuf;
2322

24-
use bitcoin::{Address, Amount, Txid};
25-
use serde::{Deserialize, Serialize};
26-
2723
pub use crate::client_sync::error::Error;
2824

2925
/// Crate-specific Result type.
@@ -224,38 +220,3 @@ fn log_response(method: &str, resp: &Result<jsonrpc::Response>) {
224220
}
225221
}
226222
}
227-
228-
/// Input used as parameter to `create_raw_transaction`.
229-
#[derive(Debug, Serialize)]
230-
pub struct Input {
231-
/// The txid of the transaction that contains the UTXO.
232-
pub txid: bitcoin::Txid,
233-
/// The vout for the UTXO.
234-
pub vout: u64,
235-
/// Sequence number if needed.
236-
pub sequence: Option<bitcoin::Sequence>,
237-
}
238-
239-
/// Output used as parameter to `create_raw_transaction`.
240-
// Abuse `HashMap` so we can derive serialize to get the correct JSON object.
241-
#[derive(Debug, Serialize)]
242-
pub struct Output(
243-
/// Map of address to value. Always only has a single item in it.
244-
HashMap<String, f64>,
245-
);
246-
247-
impl Output {
248-
/// Creates a single output that serializes as Core expects.
249-
pub fn new(addr: Address, value: Amount) -> Self {
250-
let mut map = HashMap::new();
251-
map.insert(addr.to_string(), value.to_btc());
252-
Output(map)
253-
}
254-
}
255-
256-
/// An element in the `inputs` argument of method `walletcreatefundedpsbt`.
257-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
258-
pub struct WalletCreateFundedPsbtInput {
259-
txid: Txid,
260-
vout: u32,
261-
}

client/src/client_sync/v17/mod.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod network;
1212
pub mod raw_transactions;
1313
pub mod wallet;
1414

15-
use std::collections::BTreeMap;
15+
use std::collections::{BTreeMap, HashMap};
1616
use std::path::Path;
1717

1818
use bitcoin::address::{Address, NetworkChecked};
@@ -22,9 +22,6 @@ use serde::{Deserialize, Serialize};
2222
use crate::client_sync::into_json;
2323
use crate::types::v17::*;
2424

25-
#[rustfmt::skip] // Keep public re-exports separate.
26-
pub use crate::client_sync::WalletCreateFundedPsbtInput;
27-
2825
crate::define_jsonrpc_minreq_client!("v17");
2926
crate::impl_client_check_expected_server_version!({ [170200] });
3027

@@ -174,3 +171,38 @@ pub enum TemplateRules {
174171
/// Taproot supported.
175172
Taproot,
176173
}
174+
175+
/// Input used as parameter to `create_raw_transaction`.
176+
#[derive(Debug, Serialize)]
177+
pub struct Input {
178+
/// The txid of the transaction that contains the UTXO.
179+
pub txid: bitcoin::Txid,
180+
/// The vout for the UTXO.
181+
pub vout: u64,
182+
/// Sequence number if needed.
183+
pub sequence: Option<bitcoin::Sequence>,
184+
}
185+
186+
/// Output used as parameter to `create_raw_transaction`.
187+
// Abuse `HashMap` so we can derive serialize to get the correct JSON object.
188+
#[derive(Debug, Serialize)]
189+
pub struct Output(
190+
/// Map of address to value. Always only has a single item in it.
191+
HashMap<String, f64>,
192+
);
193+
194+
impl Output {
195+
/// Creates a single output that serializes as Core expects.
196+
pub fn new(addr: Address, value: Amount) -> Self {
197+
let mut map = HashMap::new();
198+
map.insert(addr.to_string(), value.to_btc());
199+
Output(map)
200+
}
201+
}
202+
203+
/// An element in the `inputs` argument of method `walletcreatefundedpsbt`.
204+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
205+
pub struct WalletCreateFundedPsbtInput {
206+
txid: Txid,
207+
vout: u32,
208+
}

client/src/client_sync/v17/raw_transactions.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ macro_rules! impl_client_v17__converttopsbt {
5959
macro_rules! impl_client_v17__createpsbt {
6060
() => {
6161
impl Client {
62-
pub fn create_psbt(
63-
&self,
64-
inputs: &[$crate::client_sync::Input],
65-
outputs: &[$crate::client_sync::Output],
66-
) -> Result<CreatePsbt> {
62+
pub fn create_psbt(&self, inputs: &[Input], outputs: &[Output]) -> Result<CreatePsbt> {
6763
self.call("createpsbt", &[into_json(inputs)?, into_json(outputs)?])
6864
}
6965
}
@@ -77,8 +73,8 @@ macro_rules! impl_client_v17__createrawtransaction {
7773
impl Client {
7874
pub fn create_raw_transaction(
7975
&self,
80-
inputs: &[$crate::client_sync::Input],
81-
outputs: &[$crate::client_sync::Output],
76+
inputs: &[Input],
77+
outputs: &[Output],
8278
) -> Result<CreateRawTransaction> {
8379
self.call("createrawtransaction", &[into_json(inputs)?, into_json(outputs)?])
8480
}

client/src/client_sync/v17/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ macro_rules! impl_client_v17__walletcreatefundedpsbt {
446446
impl Client {
447447
pub fn wallet_create_funded_psbt(
448448
&self,
449-
inputs: Vec<$crate::client_sync::WalletCreateFundedPsbtInput>,
449+
inputs: Vec<WalletCreateFundedPsbtInput>,
450450
outputs: Vec<BTreeMap<Address, Amount>>,
451451
) -> Result<WalletCreateFundedPsbt> {
452452
self.call("walletcreatefundedpsbt", &[into_json(inputs)?, into_json(outputs)?])

client/src/client_sync/v18/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use crate::types::v18::*;
1818

1919
#[rustfmt::skip] // Keep public re-exports separate.
2020
pub use crate::client_sync::{
21-
v17::{AddressType, TemplateRequest, TemplateRules},
22-
WalletCreateFundedPsbtInput
21+
v17::{AddressType, Input, Output, TemplateRequest, TemplateRules, WalletCreateFundedPsbtInput},
2322
};
2423

24+
// This publicly re-exports `Client`.
2525
crate::define_jsonrpc_minreq_client!("v18");
2626
crate::impl_client_check_expected_server_version!({ [180100] });
2727

client/src/client_sync/v19/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use crate::types::v19::*;
1818

1919
#[rustfmt::skip] // Keep public re-exports separate.
2020
pub use crate::client_sync::{
21-
v17::{AddressType, TemplateRequest, TemplateRules},
22-
WalletCreateFundedPsbtInput
21+
v17::{AddressType, Input, Output, TemplateRequest, TemplateRules, WalletCreateFundedPsbtInput},
2322
};
2423

2524
crate::define_jsonrpc_minreq_client!("v19");

client/src/client_sync/v20.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::types::v20::*;
1515

1616
#[rustfmt::skip] // Keep public re-exports separate.
1717
pub use crate::client_sync::{
18-
v17::{AddressType, TemplateRequest, TemplateRules},
19-
WalletCreateFundedPsbtInput
18+
v17::{AddressType, Input, Output, TemplateRequest, TemplateRules, WalletCreateFundedPsbtInput},
2019
};
2120

2221
crate::define_jsonrpc_minreq_client!("v20");

client/src/client_sync/v21/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use crate::types::v21::*;
1717

1818
#[rustfmt::skip] // Keep public re-exports separate.
1919
pub use crate::client_sync::{
20-
v17::{AddressType, TemplateRequest, TemplateRules},
21-
WalletCreateFundedPsbtInput
20+
v17::{AddressType, Input, Output, TemplateRequest, TemplateRules, WalletCreateFundedPsbtInput},
2221
};
2322

2423
crate::define_jsonrpc_minreq_client!("v21");

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use crate::types::v22::*;
1818

1919
#[rustfmt::skip] // Keep public re-exports separate.
2020
pub use crate::client_sync::{
21-
v17::{AddressType, TemplateRequest, TemplateRules},
22-
WalletCreateFundedPsbtInput
21+
v17::{AddressType, Input, Output, TemplateRequest, TemplateRules, WalletCreateFundedPsbtInput},
2322
};
2423

2524
crate::define_jsonrpc_minreq_client!("v22");

client/src/client_sync/v23/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use crate::types::v23::*;
1919

2020
#[rustfmt::skip] // Keep public re-exports separate.
2121
pub use crate::client_sync::{
22-
v17::{TemplateRequest, TemplateRules},
23-
WalletCreateFundedPsbtInput
22+
v17::{Input, Output, TemplateRequest, TemplateRules, WalletCreateFundedPsbtInput},
2423
};
2524

2625
crate::define_jsonrpc_minreq_client!("v23");

0 commit comments

Comments
 (0)