Browse Source

Always display amounts with full precision

xno
codesoap 8 months ago
parent
commit
1952971614
  1. 2
      README.md
  2. 2
      cmd/atto-safesign/README.md
  3. 17
      cmd/atto-safesign/util.go
  4. 17
      cmd/atto/util.go

2
README.md

@ -45,7 +45,7 @@ nano_1o3igdpf8c4msdgwcop71x4o16zzkhe4kyku4axdi8iwh8wh13e4fwgherik @@ -45,7 +45,7 @@ nano_1o3igdpf8c4msdgwcop71x4o16zzkhe4kyku4axdi8iwh8wh13e4fwgherik
$ # The balance command will receive pending funds automatically.
$ pass nano | atto balance
Creating receive block for 1.025 from nano_34ymtnmhwseiex4eqf7nnf5wcyg44kknuuen5wwurm18ma91msf6e1pqo8hx... done
Creating receive block for 0.100 from nano_39nd8eksw1ia6aokn96z4uthocke47hfsx9gr31othm1nrfwnzmmaeehiccq... done
Creating receive block for 0.1 from nano_39nd8eksw1ia6aokn96z4uthocke47hfsx9gr31othm1nrfwnzmmaeehiccq... done
1.337 NANO
$ # Choosing a representative is important for keeping the network

2
cmd/atto-safesign/README.md

@ -35,7 +35,7 @@ online$ echo $MY_ADDRESS | atto-safesign test.atto representative nano_3up3y8cd3 @@ -35,7 +35,7 @@ online$ echo $MY_ADDRESS | atto-safesign test.atto representative nano_3up3y8cd3
offline$ # The sign subcommand can then be used on an offline computer:
offline$ pass nano | atto-safesign test.atto sign
Sign block that sets balance to 0.100 NANO and representative to nano_18shbirtzhmkf7166h39nowj9c9zrpufeg75bkbyoobqwf1iu3srfm9eo3pz? [y/N]: y
Sign block that sets balance to 0.1 NANO and representative to nano_18shbirtzhmkf7166h39nowj9c9zrpufeg75bkbyoobqwf1iu3srfm9eo3pz? [y/N]: y
Sign block that sets balance to 0.232 NANO and representative to nano_18shbirtzhmkf7166h39nowj9c9zrpufeg75bkbyoobqwf1iu3srfm9eo3pz? [y/N]: y
Sign block that sets balance to 0.232 NANO and representative to nano_3up3y8cd3hhs7zdpmkpssgb1iyjpke3xwmgqy8rg58z1hwryqpjqnkuqayps? [y/N]: y

17
cmd/atto-safesign/util.go

@ -89,13 +89,18 @@ func appendLineToFile(in []byte) error { @@ -89,13 +89,18 @@ func appendLineToFile(in []byte) error {
}
func rawToNanoString(raw *big.Int) string {
rawPerKnano, _ := big.NewInt(0).SetString("1000000000000000000000000000", 10)
balance := big.NewInt(0).Div(raw, rawPerKnano).Int64()
if balance < 0 {
balance = -balance
return fmt.Sprintf("-%d.%03d NANO", balance/1000, balance%1000)
rawPerNano, _ := big.NewInt(0).SetString("1000000000000000000000000000000", 10)
absRaw := big.NewInt(0).Abs(raw)
integerDigits, fractionalDigits := big.NewInt(0).QuoRem(absRaw, rawPerNano, big.NewInt(0))
res := integerDigits.String()
if fractionalDigits.Sign() != 0 {
fractionalDigitsString := fmt.Sprintf("%030s", fractionalDigits.String())
res += "." + strings.TrimRight(fractionalDigitsString, "0")
}
return fmt.Sprintf("%d.%03d NANO", balance/1000, balance%1000)
if raw.Sign() < 0 {
return "-" + res + " NANO"
}
return res + " NANO"
}
func letUserVerifyBlock(block atto.Block) (err error) {

17
cmd/atto/util.go

@ -20,13 +20,18 @@ func getSeed() (string, error) { @@ -20,13 +20,18 @@ func getSeed() (string, error) {
}
func rawToNanoString(raw *big.Int) string {
rawPerKnano, _ := big.NewInt(0).SetString("1000000000000000000000000000", 10)
balance := big.NewInt(0).Div(raw, rawPerKnano).Int64()
if balance < 0 {
balance = -balance
return fmt.Sprintf("-%d.%03d NANO", balance/1000, balance%1000)
rawPerNano, _ := big.NewInt(0).SetString("1000000000000000000000000000000", 10)
absRaw := big.NewInt(0).Abs(raw)
integerDigits, fractionalDigits := big.NewInt(0).QuoRem(absRaw, rawPerNano, big.NewInt(0))
res := integerDigits.String()
if fractionalDigits.Sign() != 0 {
fractionalDigitsString := fmt.Sprintf("%030s", fractionalDigits.String())
res += "." + strings.TrimRight(fractionalDigitsString, "0")
}
return fmt.Sprintf("%d.%03d NANO", balance/1000, balance%1000)
if raw.Sign() < 0 {
return "-" + res + " NANO"
}
return res + " NANO"
}
func letUserVerifySend(amount, recipient string) (err error) {

Loading…
Cancel
Save