Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 9d71d32

Browse files
authored
Do a bunch of minor improvements (#31)
Remove `FIXME`s and things like that, non of this is controversial.
2 parents d4301fc + e14093a commit 9d71d32

File tree

9 files changed

+13
-46
lines changed

9 files changed

+13
-46
lines changed

client/src/client_sync/v17/blockchain.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,21 @@ macro_rules! impl_client_v17__getblock {
3333
() => {
3434
impl Client {
3535
/// Gets a block by blockhash.
36-
pub fn get_block(&self, hash: &BlockHash) -> Result<Block> {
36+
pub fn get_block(&self, hash: BlockHash) -> Result<Block> {
3737
let json = self.get_block_verbosity_zero(hash)?;
3838
Ok(json.block()?)
3939
}
4040

41-
// FIXME(getblock): This handling of optional args is ugly as hell but because the returned json
42-
// is different for each verbosity these are functionally different methods. Is there a better way?
43-
4441
pub fn get_block_verbosity_zero(
4542
&self,
46-
hash: &BlockHash,
43+
hash: BlockHash,
4744
) -> Result<GetBlockVerbosityZero> {
4845
self.call("getblock", &[into_json(hash)?, 0.into()])
4946
}
5047

5148
pub fn get_block_verbosity_one(
5249
&self,
53-
hash: &BlockHash,
50+
hash: BlockHash,
5451
) -> Result<GetBlockVerbosityOne> {
5552
self.call("getblock", &[into_json(hash)?, 1.into()])
5653
}

integration_test/src/v17/blockchain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! impl_test_v17__getblock_verbosity_0 {
3232
let bitcoind = $crate::bitcoind_no_wallet();
3333
let block_hash = best_block_hash();
3434

35-
let json = bitcoind.client.get_block_verbosity_zero(&block_hash).expect("getblock 0");
35+
let json = bitcoind.client.get_block_verbosity_zero(block_hash).expect("getblock 0");
3636
json.into_model().unwrap();
3737
}
3838
};
@@ -47,7 +47,7 @@ macro_rules! impl_test_v17__getblock_verbosity_1 {
4747
let bitcoind = $crate::bitcoind_no_wallet();
4848
let block_hash = best_block_hash();
4949

50-
let json = bitcoind.client.get_block_verbosity_one(&block_hash).expect("getblock 1");
50+
let json = bitcoind.client.get_block_verbosity_one(block_hash).expect("getblock 1");
5151
json.into_model().unwrap();
5252
}
5353
};
@@ -62,7 +62,7 @@ macro_rules! impl_test_v17__getblock_verbosity_2 {
6262
let bitcoind = $crate::bitcoind_no_wallet();
6363
let block_hash = best_block_hash();
6464

65-
let json = client.get_block_verbosity_two(&block_hash).expect("getblock 2");
65+
let json = client.get_block_verbosity_two(block_hash).expect("getblock 2");
6666
json.into_model().unwrap();
6767
}
6868
};

json/src/model/network.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ pub struct GetNetworkInfo {
2727
pub time_offset: isize,
2828
/// The total number of connections.
2929
pub connections: usize,
30-
/// The number of inbound connections.
31-
pub connections_in: usize,
32-
/// The number of outbound connections.
33-
pub connections_out: usize,
3430
/// Whether p2p networking is enabled.
3531
pub network_active: bool,
3632
/// Information per network.
@@ -42,7 +38,7 @@ pub struct GetNetworkInfo {
4238
/// List of local addresses.
4339
pub local_addresses: Vec<GetNetworkInfoAddress>,
4440
/// Any network and blockchain warnings.
45-
pub warnings: String, // FIXME: I rekon this is wrong.
41+
pub warnings: String,
4642
}
4743

4844
/// Part of the result of the JSON-RPC method `getnetworkinfo` (information per network).

json/src/model/wallet.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ pub struct GetNewAddress(pub Address<NetworkUnchecked>);
8383
pub struct SendToAddress {
8484
/// The transaction id.
8585
pub txid: Txid,
86-
/// The transaction fee reason.
87-
pub fee_reason: String,
8886
}
8987

9088
/// Models the result of JSON-RPC method `gettransaction`.

json/src/v17/blockchain.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,12 @@ impl GetBlockVerbosityOne {
117117
let weight = Weight::from_wu(self.weight); // TODO: Confirm this uses weight units.
118118
let version = block::Version::from_consensus(self.version);
119119

120-
// FIXME: Is there a better way to handle the error without type annotations on `collect`?
121120
let tx = self
122121
.tx
123122
.iter()
124123
.map(|t| encode::deserialize_hex::<Txid>(t).map_err(E::Tx))
125124
.collect::<Result<Vec<_>, _>>()?;
126125

127-
// FIXME: Is unprefixed correct?
128126
let bits = CompactTarget::from_unprefixed_hex(&self.bits).map_err(E::Bits)?;
129127
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
130128

@@ -161,7 +159,7 @@ impl GetBlockVerbosityOne {
161159
}
162160
}
163161

164-
/// Error when converting a `GetBlockVerbasityOne` type into the model type.
162+
/// Error when converting a `GetBlockVerbosityOne` type into the model type.
165163
#[derive(Debug)]
166164
pub enum GetBlockVerbosityOneError {
167165
/// Conversion of the transaction `hash` field failed.
@@ -317,7 +315,6 @@ impl GetBlockchainInfo {
317315
let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
318316
let best_block_hash =
319317
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
320-
// FIXME: Is unprefixed correct?
321318
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
322319

323320
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
@@ -343,7 +340,6 @@ impl GetBlockchainInfo {
343340
}
344341
}
345342

346-
// FIXME: Me mightn't need this.
347343
impl Bip9SoftforkStatus {
348344
/// Converts version specific type to a version in-specific, more strongly typed type.
349345
pub fn into_model(self) -> model::Bip9SoftforkStatus {

json/src/v17/network.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ impl GetNetworkInfo {
9999
local_relay: self.local_relay,
100100
time_offset: self.time_offset,
101101
connections: self.connections,
102-
connections_in: 0, // FIXME: Can we do better than this?
103-
connections_out: 0, // FIXME: Can we do better than this?
104102
network_active: self.network_active,
105103
networks: self.networks.into_iter().map(|j| j.into_model()).collect(),
106104
relay_fee,

json/src/v17/wallet.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ impl SendToAddress {
146146
/// Converts version specific type to a version in-specific, more strongly typed type.
147147
pub fn into_model(self) -> Result<model::SendToAddress, hex::HexToArrayError> {
148148
let txid = self.0.parse::<Txid>()?;
149-
Ok(model::SendToAddress {
150-
txid,
151-
// FIXME: Is this acceptable?
152-
fee_reason: "".to_string(),
153-
})
149+
Ok(model::SendToAddress { txid })
154150
}
155151

156152
/// Converts json straight to a `bitcoin::Txid`.
@@ -171,13 +167,8 @@ pub struct GetTransaction {
171167
pub amount: f64,
172168
pub fee: Option<f64>,
173169
pub confirmations: u32,
174-
// FIXME: The docs say these two fields should be here but it is not returned.
175-
// Is it worth patching Core for a version this old?
176-
//
177-
// #[serde(rename = "blockhash")]
178-
// pub block_hash: String,
179-
// #[serde(rename = "blockindex")]
180-
// pub block_index: u64,
170+
// The docs say there should be two more fields: `blockhash` and `blockindex` but integration
171+
// test fails if we add them i.e., they are not returned by `v0.17.1`.
181172
pub txid: String,
182173
pub time: u64,
183174
#[serde(rename = "timereceived")]

json/src/v19/blockchain.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ impl GetBlockchainInfo {
148148
let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
149149
let best_block_hash =
150150
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
151-
// FIXME: Is unprefixed correct?
152151
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
153152

154153
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.

json/src/v19/wallet.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ impl GetBalances {
5353
/// Converts version specific type to a version in-specific, more strongly typed type.
5454
pub fn into_model(self) -> Result<model::GetBalances, ParseAmountError> {
5555
let mine = self.mine.into_model()?;
56-
// FIXME: Use combinators instead of matching like a noob.
57-
let watch_only = match self.watch_only {
58-
Some(watch_only) => Some(watch_only.into_model()?),
59-
None => None,
60-
};
56+
let watch_only = self.watch_only.map(|watch_only| watch_only.into_model()).transpose()?;
6157

6258
Ok(model::GetBalances { mine, watch_only })
6359
}
@@ -69,11 +65,7 @@ impl GetBalancesMine {
6965
let trusted = Amount::from_btc(self.trusted)?;
7066
let untrusted_pending = Amount::from_btc(self.untrusted_pending)?;
7167
let immature = Amount::from_btc(self.immature)?;
72-
// FIXME: Use combinators instead of matching like a noob.
73-
let used = match self.used {
74-
Some(used) => Some(Amount::from_btc(used)?),
75-
None => None,
76-
};
68+
let used = self.used.map(Amount::from_btc).transpose()?;
7769

7870
Ok(model::GetBalancesMine { trusted, untrusted_pending, immature, used })
7971
}

0 commit comments

Comments
 (0)