Skip to content

Commit 9266a31

Browse files
committed
client: Move types to version specific module
Currently we have a bit of confusion around types that are defined and used by the various client version modules. - Some currently don't change e.g., `Input` - Some are due to change in v29 e.g., `TemplateRequest` - Some change already e.g. `AddressVersion` And to make matters worse, I did 'custom' re-exports in `node` which is very confusing when one is reading code in `client`. Put all `client` defined types in the version module they first appear in and re-export them as we do for types from `types`. Then use the type naked (without qualifying the path).
1 parent 257b445 commit 9266a31

File tree

20 files changed

+73
-91
lines changed

20 files changed

+73
-91
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ macro_rules! impl_client_v17__createpsbt {
6161
impl Client {
6262
pub fn create_psbt(
6363
&self,
64-
inputs: &[$crate::client_sync::Input],
65-
outputs: &[$crate::client_sync::Output],
64+
inputs: &[Input],
65+
outputs: &[Output],
6666
) -> Result<CreatePsbt> {
6767
self.call("createpsbt", &[into_json(inputs)?, into_json(outputs)?])
6868
}
@@ -77,8 +77,8 @@ macro_rules! impl_client_v17__createrawtransaction {
7777
impl Client {
7878
pub fn create_raw_transaction(
7979
&self,
80-
inputs: &[$crate::client_sync::Input],
81-
outputs: &[$crate::client_sync::Output],
80+
inputs: &[Input],
81+
outputs: &[Output],
8282
) -> Result<CreateRawTransaction> {
8383
self.call("createrawtransaction", &[into_json(inputs)?, into_json(outputs)?])
8484
}

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ 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

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

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");

client/src/client_sync/v24.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::types::v24::*;
1515

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

2222
crate::define_jsonrpc_minreq_client!("v24");

client/src/client_sync/v25.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::types::v25::*;
1515

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

2222
crate::define_jsonrpc_minreq_client!("v25");

client/src/client_sync/v26/mod.rs

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

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

2726
crate::define_jsonrpc_minreq_client!("v26");

client/src/client_sync/v27.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::types::v27::*;
1515

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

2222
crate::define_jsonrpc_minreq_client!("v27");

client/src/client_sync/v28/mod.rs

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

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

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

integration_test/tests/mining.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use bitcoin::SignedAmount;
88
use integration_test::{Node, NodeExt as _, Wallet};
9-
use node::{TemplateRequest, TemplateRules};
109
use node::vtype::*; // All the version specific types.
1110
use node::mtype;
1211

integration_test/tests/raw_transactions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use bitcoin::hex::FromHex as _;
99
use bitcoin::opcodes::all::*;
1010
use bitcoin::{absolute, transaction, consensus, script, Amount, TxOut, Transaction, ScriptBuf};
1111
use integration_test::{Node, NodeExt as _, Wallet};
12-
use node::client::client_sync::{Input, Output};
1312
use node::vtype::*; // All the version specific types.
1413
use node::mtype;
1514

integration_test/tests/wallet.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use bitcoin::address::{Address, NetworkChecked};
99
use bitcoin::Amount;
1010
use integration_test::{Node, NodeExt as _, Wallet};
11-
use node::AddressType;
1211
use node::vtype::*; // All the version specific types.
1312
use node::mtype;
1413

node/src/client_versions.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,52 @@
77
#![allow(unused_imports)] // Not all users need the json types.
88

99
#[cfg(feature = "28_0")]
10-
pub use corepc_client::{client_sync::v28::{Client, AddressType, TemplateRequest, TemplateRules}, types::v28 as vtype};
10+
pub use corepc_client::{client_sync::v28::{Client}, types::v28 as vtype};
1111

1212
#[cfg(all(feature = "27_2", not(feature = "28_0")))]
13-
pub use corepc_client::{client_sync::v27::{Client, AddressType, TemplateRequest, TemplateRules}, types::v27 as vtype};
13+
pub use corepc_client::{client_sync::v27::{Client}, types::v27 as vtype};
1414

1515
#[cfg(all(feature = "27_1", not(feature = "27_2")))]
16-
pub use corepc_client::{client_sync::v27::{Client, AddressType, TemplateRequest, TemplateRules}, types::v27 as vtype};
16+
pub use corepc_client::{client_sync::v27::{Client}, types::v27 as vtype};
1717

1818
#[cfg(all(feature = "27_0", not(feature = "27_1")))]
19-
pub use corepc_client::{client_sync::v27::{Client, AddressType, TemplateRequest, TemplateRules}, types::v27 as vtype};
19+
pub use corepc_client::{client_sync::v27::{Client}, types::v27 as vtype};
2020

2121
#[cfg(all(feature = "26_2", not(feature = "27_0")))]
22-
pub use corepc_client::{client_sync::v26::{Client, AddressType, TemplateRequest, TemplateRules}, types::v26 as vtype};
22+
pub use corepc_client::{client_sync::v26::{Client}, types::v26 as vtype};
2323

2424
#[cfg(all(feature = "26_1", not(feature = "26_2")))]
25-
pub use corepc_client::{client_sync::v26::{Client, AddressType, TemplateRequest, TemplateRules}, types::v26 as vtype};
25+
pub use corepc_client::{client_sync::v26::{Client}, types::v26 as vtype};
2626

2727
#[cfg(all(feature = "26_0", not(feature = "26_1")))]
28-
pub use corepc_client::{client_sync::v26::{Client, AddressType, TemplateRequest, TemplateRules}, types::v26 as vtype};
28+
pub use corepc_client::{client_sync::v26::{Client}, types::v26 as vtype};
2929

3030
#[cfg(all(feature = "25_2", not(feature = "26_0")))]
31-
pub use corepc_client::{client_sync::v25::{Client, AddressType, TemplateRequest, TemplateRules}, types::v25 as vtype};
31+
pub use corepc_client::{client_sync::v25::{Client}, types::v25 as vtype};
3232

3333
#[cfg(all(feature = "24_2", not(feature = "25_2")))]
34-
pub use corepc_client::{client_sync::v24::{Client, AddressType, TemplateRequest, TemplateRules}, types::v24 as vtype};
34+
pub use corepc_client::{client_sync::v24::{Client}, types::v24 as vtype};
3535

3636
#[cfg(all(feature = "23_2", not(feature = "24_2")))]
37-
pub use corepc_client::{client_sync::v23::{Client, AddressType, TemplateRequest, TemplateRules}, types::v23 as vtype};
37+
pub use corepc_client::{client_sync::v23::{Client}, types::v23 as vtype};
3838

3939
#[cfg(all(feature = "22_1", not(feature = "23_2")))]
40-
pub use corepc_client::{client_sync::v22::{Client, AddressType, TemplateRequest, TemplateRules}, types::v22 as vtype};
40+
pub use corepc_client::{client_sync::v22::{Client}, types::v22 as vtype};
4141

4242
#[cfg(all(feature = "0_21_2", not(feature = "22_1")))]
43-
pub use corepc_client::{client_sync::v21::{Client, AddressType, TemplateRequest, TemplateRules}, types::v21 as vtype};
43+
pub use corepc_client::{client_sync::v21::{Client}, types::v21 as vtype};
4444

4545
#[cfg(all(feature = "0_20_2", not(feature = "0_21_2")))]
46-
pub use corepc_client::{client_sync::v20::{Client, AddressType, TemplateRequest, TemplateRules}, types::v20 as vtype};
46+
pub use corepc_client::{client_sync::v20::{Client}, types::v20 as vtype};
4747

4848
#[cfg(all(feature = "0_19_1", not(feature = "0_20_2")))]
49-
pub use corepc_client::{client_sync::v19::{Client, AddressType, TemplateRequest, TemplateRules}, types::v19 as vtype};
49+
pub use corepc_client::{client_sync::v19::{Client}, types::v19 as vtype};
5050

5151
#[cfg(all(feature = "0_18_1", not(feature = "0_19_1")))]
52-
pub use corepc_client::{client_sync::v18::{Client, AddressType, TemplateRequest, TemplateRules}, types::v18 as vtype};
52+
pub use corepc_client::{client_sync::v18::{Client}, types::v18 as vtype};
5353

5454
#[cfg(all(feature = "0_17_2", not(feature = "0_18_1")))]
55-
pub use corepc_client::{client_sync::v17::{Client, AddressType, TemplateRequest, TemplateRules}, types::v17 as vtype};
55+
pub use corepc_client::{client_sync::v17::{Client}, types::v17 as vtype};
5656

5757
/// This is meaningless but we need it otherwise we can't get far enough into
5858
/// the build process to trigger the `compile_error!` in `./versions.rs`.
@@ -74,4 +74,4 @@ pub use corepc_client::{client_sync::v17::{Client, AddressType, TemplateRequest,
7474
not(feature = "0_18_1"),
7575
not(feature = "0_17_2"),
7676
))]
77-
pub use corepc_client::{client_sync::v28::{Client, AddressType, TemplateRequest, TemplateRules}, types::v28 as vtype};
77+
pub use corepc_client::{client_sync::v28::{Client}, types::v28 as vtype};

node/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use {anyhow, serde_json, tempfile, which};
2424
#[doc(inline)]
2525
pub use self::{
2626
// Re-export `vtype` - the version specific types.
27-
client_versions::{vtype, Client, AddressType, TemplateRequest, TemplateRules},
27+
client_versions::{vtype, Client},
2828
// Re-export the version string e.g., "28.0".
2929
versions::VERSION,
3030
// Re-export the model types as `mtype` to differentiate it from `vtype`.

0 commit comments

Comments
 (0)