Skip to content

Commit 4687d2c

Browse files
committed
Move getbalances into_model functions into module
Move the into_model functions from mod.rs into the `into` module. Code move only, no other changes.
1 parent ff63089 commit 4687d2c

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

types/src/v19/wallet/into.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
// SPDX-License-Identifier: CC0-1.0
22

3+
use bitcoin::amount::ParseAmountError;
34
use bitcoin::consensus::encode;
4-
use bitcoin::{BlockHash, SignedAmount, Transaction, Txid};
5+
use bitcoin::{Amount, BlockHash, SignedAmount, Transaction, Txid};
56

6-
use super::{GetTransaction, GetTransactionError};
7+
use super::{GetBalances, GetBalancesMine, GetBalancesWatchOnly, GetTransaction, GetTransactionError};
78
use crate::model;
89

10+
impl GetBalances {
11+
/// Converts version specific type to a version nonspecific, more strongly typed type.
12+
pub fn into_model(self) -> Result<model::GetBalances, ParseAmountError> {
13+
let mine = self.mine.into_model()?;
14+
let watch_only = self.watch_only.map(|watch_only| watch_only.into_model()).transpose()?;
15+
16+
Ok(model::GetBalances { mine, watch_only })
17+
}
18+
}
19+
20+
impl GetBalancesMine {
21+
/// Converts version specific type to a version nonspecific, more strongly typed type.
22+
pub fn into_model(self) -> Result<model::GetBalancesMine, ParseAmountError> {
23+
let trusted = Amount::from_btc(self.trusted)?;
24+
let untrusted_pending = Amount::from_btc(self.untrusted_pending)?;
25+
let immature = Amount::from_btc(self.immature)?;
26+
let used = self.used.map(Amount::from_btc).transpose()?;
27+
28+
Ok(model::GetBalancesMine { trusted, untrusted_pending, immature, used })
29+
}
30+
}
31+
32+
impl GetBalancesWatchOnly {
33+
/// Converts version specific type to a version nonspecific, more strongly typed type.
34+
pub fn into_model(self) -> Result<model::GetBalancesWatchOnly, ParseAmountError> {
35+
let trusted = Amount::from_btc(self.trusted)?;
36+
let untrusted_pending = Amount::from_btc(self.untrusted_pending)?;
37+
let immature = Amount::from_btc(self.immature)?;
38+
39+
Ok(model::GetBalancesWatchOnly { trusted, untrusted_pending, immature })
40+
}
41+
}
42+
943
impl GetTransaction {
1044
/// Converts version specific type to a version nonspecific, more strongly typed type.
1145
pub fn into_model(self) -> Result<model::GetTransaction, GetTransactionError> {

types/src/v19/wallet/mod.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
77
mod into;
88

9-
use bitcoin::amount::ParseAmountError;
10-
use bitcoin::{Amount, Transaction};
9+
use bitcoin::Transaction;
1110
use serde::{Deserialize, Serialize};
1211

1312
use super::{Bip125Replaceable, GetTransactionDetail, GetTransactionError};
14-
use crate::model;
1513

1614
/// Result of the JSON-RPC method `getbalances`.
1715
///
@@ -52,39 +50,6 @@ pub struct GetBalancesWatchOnly {
5250
pub immature: f64,
5351
}
5452

55-
impl GetBalances {
56-
/// Converts version specific type to a version nonspecific, more strongly typed type.
57-
pub fn into_model(self) -> Result<model::GetBalances, ParseAmountError> {
58-
let mine = self.mine.into_model()?;
59-
let watch_only = self.watch_only.map(|watch_only| watch_only.into_model()).transpose()?;
60-
61-
Ok(model::GetBalances { mine, watch_only })
62-
}
63-
}
64-
65-
impl GetBalancesMine {
66-
/// Converts version specific type to a version nonspecific, more strongly typed type.
67-
pub fn into_model(self) -> Result<model::GetBalancesMine, ParseAmountError> {
68-
let trusted = Amount::from_btc(self.trusted)?;
69-
let untrusted_pending = Amount::from_btc(self.untrusted_pending)?;
70-
let immature = Amount::from_btc(self.immature)?;
71-
let used = self.used.map(Amount::from_btc).transpose()?;
72-
73-
Ok(model::GetBalancesMine { trusted, untrusted_pending, immature, used })
74-
}
75-
}
76-
77-
impl GetBalancesWatchOnly {
78-
/// Converts version specific type to a version nonspecific, more strongly typed type.
79-
pub fn into_model(self) -> Result<model::GetBalancesWatchOnly, ParseAmountError> {
80-
let trusted = Amount::from_btc(self.trusted)?;
81-
let untrusted_pending = Amount::from_btc(self.untrusted_pending)?;
82-
let immature = Amount::from_btc(self.immature)?;
83-
84-
Ok(model::GetBalancesWatchOnly { trusted, untrusted_pending, immature })
85-
}
86-
}
87-
8853
/// Result of the JSON-RPC method `gettransaction`.
8954
///
9055
/// > gettransaction "txid" ( include_watchonly )

0 commit comments

Comments
 (0)