Skip to content

Commit b34ba1a

Browse files
authored
fix: Lovelace rounding and docs catalyst toolbox | NPG-000 (#535)
# Description Fix conversion lovelace to ADA for catalyst-toolbox sve-snapshot. Now the conversion to ada is done on the total voting power. Also fixed the docs has they were unclear on what the --lovelace option does ## Checklist - [ ] My code follows the style guidelines of this project - [ x] I have performed a self-review of my code - [ x] I have commented my code, particularly in hard-to-understand areas - [ x] I have made corresponding changes to the documentation - [ x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
1 parent e7acdc2 commit b34ba1a

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/catalyst-toolbox/catalyst-toolbox/src/bin/cli/sve_snapshot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ pub struct SveSnapshotCmd {
2424
#[clap(short, long)]
2525
file: PathBuf,
2626

27-
/// Registrations voting power threshold for eligibility
27+
/// Registrations voting power threshold for eligibility expressed in lovelace
2828
#[clap(short, long)]
2929
min_stake_threshold: Value,
3030

3131
/// Discrimination to use for initial addresses
3232
#[clap(short, long)]
3333
discrimination: Discrimination,
3434

35-
/// Whether voting power is expressed in lovelace or ada
35+
/// Whether voting power in the outputfile is expressed in lovelace or ada
3636
#[clap(short, long)]
3737
lovelace: bool,
3838

src/catalyst-toolbox/snapshot-lib/src/sve.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ impl Snapshot {
5959
self.inner
6060
.iter()
6161
.map(|(vk, regs)| {
62-
let value: Value = regs
62+
let mut value: Value = regs
6363
.iter()
64-
.map(|reg| {
65-
let value = u64::from(reg.voting_power);
66-
if lovelace {
67-
value / 1_000_000
68-
} else {
69-
value
70-
}
71-
})
64+
.map(|reg| u64::from(reg.voting_power))
7265
.sum::<u64>()
7366
.into();
7467

68+
//convert to ADA
69+
if !lovelace {
70+
value = (u64::from(value) / 1_000_000).into();
71+
}
72+
7573
let address = chain_addr::Address(
7674
discrimination,
7775
chain_addr::Kind::Account(vk.to_inner().into()),

0 commit comments

Comments
 (0)