Skip to content

Commit

Permalink
refactor(core): tari newtype wraps MicroTari (#3960)
Browse files Browse the repository at this point in the history
Description
---
- uses MicroTari to back Tari newtype

Motivation and Context
---
This avoids a fair amount of complexity and footguns. I wanted to remove the decimal dependency but it come in handy for the parsing of decimal strings. The only API breaking change is that negatives are not supported (not currently used) but this would be fairly straight forward to add.

How Has This Been Tested?
---
New and updated unit tests, Manually checked the wallet
  • Loading branch information
sdbondi committed Apr 4, 2022
1 parent 96d24c6 commit e590547
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 113 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{
convert::TryFrom,
fs::File,
io::{LineWriter, Write},
str::FromStr,
Expand Down Expand Up @@ -735,7 +734,7 @@ pub async fn command_runner(
}
if count > 0 {
let average = f64::from(sum) / count as f64;
let average = Tari::try_from(average / 1_000_000f64)?;
let average = Tari::from(MicroTari(average.round() as u64));
println!("Average value UTXO : {}", average);
}
if let Some(max) = values.iter().max() {
Expand Down
9 changes: 3 additions & 6 deletions applications/tari_console_wallet/src/automation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ use std::num::{ParseFloatError, ParseIntError};

use log::*;
use tari_common::exit_codes::{ExitCode, ExitError};
use tari_core::transactions::{
tari_amount::{MicroTariError, TariConversionError},
transaction_components::TransactionError,
};
use tari_core::transactions::{tari_amount::MicroTariError, transaction_components::TransactionError};
use tari_utilities::hex::HexError;
use tari_wallet::{
error::{WalletError, WalletStorageError},
Expand All @@ -45,8 +42,8 @@ pub const LOG_TARGET: &str = "wallet::automation::error";
pub enum CommandError {
#[error("Argument error - were they in the right order?")]
Argument,
#[error("Tari value conversion error `{0}`")]
TariConversionError(#[from] TariConversionError),
#[error("Tari value error `{0}`")]
MicroTariError(#[from] MicroTariError),
#[error("Transaction service error `{0}`")]
TransactionError(#[from] TransactionError),
#[error("Transaction service error `{0}`")]
Expand Down
1 change: 0 additions & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ criterion = { version = "0.3.5", optional = true }
croaring = { version = "=0.4.5", optional = true }
decimal-rs = "0.1.20"
derivative = "2.2.0"
derive_more = "0.99.16"
digest = "0.9.0"
fs2 = "0.3.0"
futures = { version = "^0.3.16", features = ["async-await"] }
Expand Down

0 comments on commit e590547

Please sign in to comment.