|
1 | 1 | // SPDX-License-Identifier: CC0-1.0
|
2 | 2 |
|
| 3 | +use bitcoin::amount::ParseAmountError; |
3 | 4 | use bitcoin::consensus::encode;
|
4 |
| -use bitcoin::{BlockHash, SignedAmount, Transaction, Txid}; |
| 5 | +use bitcoin::{Amount, BlockHash, SignedAmount, Transaction, Txid}; |
5 | 6 |
|
6 |
| -use super::{GetTransaction, GetTransactionError}; |
| 7 | +use super::{GetBalances, GetBalancesMine, GetBalancesWatchOnly, GetTransaction, GetTransactionError}; |
7 | 8 | use crate::model;
|
8 | 9 |
|
| 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 | + |
9 | 43 | impl GetTransaction {
|
10 | 44 | /// Converts version specific type to a version nonspecific, more strongly typed type.
|
11 | 45 | pub fn into_model(self) -> Result<model::GetTransaction, GetTransactionError> {
|
|
0 commit comments