Skip to content

Commit

Permalink
patch v5 coin amount decimal scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Bea LeLeveret committed Jan 28, 2025
1 parent f59dde2 commit 02a6563
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/json_rescue_v5_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
scan::FrameworkVersion,
schema_transaction::{
EntryFunctionArgs, RelationLabel, WarehouseEvent, WarehouseTxMaster,
LEGACY_REBASE_MULTIPLIER,
COIN_DECIMAL_PRECISION, LEGACY_REBASE_MULTIPLIER,
},
unzip_temp::decompress_tar_archive,
};
Expand Down Expand Up @@ -126,7 +126,7 @@ fn maybe_decode_v5_genesis_function(
} => {
wtx.relation_label = RelationLabel::Transfer(
cast_legacy_account(destination)?,
*unscaled_value * LEGACY_REBASE_MULTIPLIER,
*unscaled_value * COIN_DECIMAL_PRECISION * LEGACY_REBASE_MULTIPLIER,
);

wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned()));
Expand All @@ -151,7 +151,7 @@ fn maybe_decode_v5_genesis_function(
} => {
wtx.relation_label = RelationLabel::Onboarding(
cast_legacy_account(account)?,
*unscaled_value * LEGACY_REBASE_MULTIPLIER,
*unscaled_value * COIN_DECIMAL_PRECISION * LEGACY_REBASE_MULTIPLIER,
);
}
ScriptFunctionCallGenesis::CreateValidatorAccount {
Expand Down Expand Up @@ -202,7 +202,7 @@ fn maybe_decode_v520_function(
} => {
wtx.relation_label = RelationLabel::Transfer(
cast_legacy_account(destination)?,
*unscaled_value * LEGACY_REBASE_MULTIPLIER,
*unscaled_value * COIN_DECIMAL_PRECISION * LEGACY_REBASE_MULTIPLIER,
);

wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned()));
Expand Down
6 changes: 3 additions & 3 deletions src/schema_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
pub const LEGACY_REBASE_MULTIPLIER: u64 = 35;
/// Decimal precision
// TODO: duplication, this is probably defined in libra-framework somewhere
pub const COIN_DECIMAL_PRECISION: f64 = 1000000.0;
pub const COIN_DECIMAL_PRECISION: u64 = 1000000;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum RelationLabel {
Expand Down Expand Up @@ -59,13 +59,13 @@ impl RelationLabel {
match &self {
RelationLabel::Transfer(_, amount) => {
if *amount > 0 {
let human = (*amount as f64) / COIN_DECIMAL_PRECISION;
let human = (*amount as f64) / COIN_DECIMAL_PRECISION as f64;
return Some(human);
}
}
RelationLabel::Onboarding(_, amount) => {
if *amount > 0 {
let human = (*amount as f64) / COIN_DECIMAL_PRECISION;
let human = (*amount as f64) / COIN_DECIMAL_PRECISION as f64;
return Some(human);
}
}
Expand Down

0 comments on commit 02a6563

Please sign in to comment.