Skip to content

Commit 79f363e

Browse files
Standardize decimals (#1620)
1 parent e191c88 commit 79f363e

File tree

18 files changed

+57
-41
lines changed

18 files changed

+57
-41
lines changed

cli/cli.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
type Controller interface {
1515
DatabasePath() string
1616
Symbol() string
17-
Decimals() uint8
1817
GetParser(string) (chain.Parser, error)
1918
HandleTx(*chain.Transaction, *chain.Result)
2019
LookupBalance(address codec.Address, uri string) (uint64, error)

cli/key.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (h *Handler) SetKey() error {
3636
"%d) {{cyan}}address:{{/}} %s {{cyan}}balance:{{/}} %s %s\n",
3737
i,
3838
addrStr,
39-
utils.FormatBalance(balance, h.c.Decimals()),
39+
utils.FormatBalance(balance),
4040
h.c.Symbol(),
4141
)
4242
}
@@ -73,7 +73,7 @@ func (h *Handler) Balance(checkAllChains bool) error {
7373
utils.Outf(
7474
"{{cyan}}address:{{/}} %s {{cyan}}balance:{{/}} %s %s\n",
7575
addr,
76-
utils.FormatBalance(balance, h.c.Decimals()),
76+
utils.FormatBalance(balance),
7777
h.c.Symbol(),
7878
)
7979
}

cli/prompt/prompt.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func Asset(label string, symbol string, allowNative bool) (ids.ID, error) {
124124

125125
func Amount(
126126
label string,
127-
decimals uint8,
128127
balance uint64,
129128
f func(input uint64) error,
130129
) (uint64, error) {
@@ -134,7 +133,7 @@ func Amount(
134133
if len(input) == 0 {
135134
return ErrInputEmpty
136135
}
137-
amount, err := utils.ParseBalance(input, decimals)
136+
amount, err := utils.ParseBalance(input)
138137
if err != nil {
139138
return err
140139
}
@@ -152,7 +151,7 @@ func Amount(
152151
return 0, err
153152
}
154153
rawAmount = strings.TrimSpace(rawAmount)
155-
return utils.ParseBalance(rawAmount, decimals)
154+
return utils.ParseBalance(rawAmount)
156155
}
157156

158157
func Int(

cli/spam.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (h *Handler) Spam(sh SpamHelper) error {
204204
distAmount := (balance - withholding) / uint64(numAccounts)
205205
utils.Outf(
206206
"{{yellow}}distributing funds to each account:{{/}} %s %s\n",
207-
utils.FormatBalance(distAmount, h.c.Decimals()),
207+
utils.FormatBalance(distAmount),
208208
h.c.Symbol(),
209209
)
210210
accounts := make([]*PrivateKey, numAccounts)
@@ -455,7 +455,7 @@ func (h *Handler) Spam(sh SpamHelper) error {
455455
}
456456
utils.Outf(
457457
"{{yellow}}returned funds:{{/}} %s %s\n",
458-
utils.FormatBalance(returnedBalance, h.c.Decimals()),
458+
utils.FormatBalance(returnedBalance),
459459
h.c.Symbol(),
460460
)
461461
return nil

consts/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ const (
3030
MaxUint64 = ^uint64(0)
3131
MaxFloat64 = math.MaxFloat64
3232
MillisecondsPerSecond = 1000
33+
Decimals = 9
3334
)

docs/tutorials/morpheusvm/options.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ func GetBalanceFromState(
2929
This function is almost identical to `getBalance()` except that we are passing
3030
along `f` of type `ReadState` instead of `im` of type `state.Immutable`.
3131

32-
We also need to specify the precision of our VM token. To do this, go to
33-
`consts/consts.go` and add the following constant:
34-
35-
```golang
36-
const Decimals = 9
37-
```
3832

3933
## Getting Started
4034

@@ -233,7 +227,7 @@ func (cli *JSONRPCClient) WaitForBalance(
233227
if !shouldExit {
234228
utils.Outf(
235229
"{{yellow}}waiting for %s balance: %s{{/}}\n",
236-
utils.FormatBalance(min, consts.Decimals),
230+
utils.FormatBalance(min),
237231
addr,
238232
)
239233
}

examples/morpheusvm/cmd/morpheus-cli/cmd/action.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/ava-labs/hypersdk/chain"
1212
"github.com/ava-labs/hypersdk/cli/prompt"
1313
"github.com/ava-labs/hypersdk/examples/morpheusvm/actions"
14-
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
1514
)
1615

1716
var actionCmd = &cobra.Command{
@@ -43,7 +42,7 @@ var transferCmd = &cobra.Command{
4342
}
4443

4544
// Select amount
46-
amount, err := prompt.Amount("amount", consts.Decimals, balance, nil)
45+
amount, err := prompt.Amount("amount", balance, nil)
4746
if err != nil {
4847
return err
4948
}

examples/morpheusvm/cmd/morpheus-cli/cmd/handler.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (*Handler) GetBalance(
9999
}
100100
utils.Outf(
101101
"{{yellow}}balance:{{/}} %s %s\n",
102-
utils.FormatBalance(balance, consts.Decimals),
102+
utils.FormatBalance(balance),
103103
consts.Symbol,
104104
)
105105
return balance, nil
@@ -121,10 +121,6 @@ func (*Controller) Symbol() string {
121121
return consts.Symbol
122122
}
123123

124-
func (*Controller) Decimals() uint8 {
125-
return consts.Decimals
126-
}
127-
128124
func (*Controller) GetParser(uri string) (chain.Parser, error) {
129125
cli := vm.NewJSONRPCClient(uri)
130126
return cli.Parser(context.TODO())

examples/morpheusvm/cmd/morpheus-cli/cmd/resolutions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
7070
actor,
7171
result.Error,
7272
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
73-
utils.FormatBalance(result.Fee, consts.Decimals),
73+
utils.FormatBalance(result.Fee),
7474
consts.Symbol,
7575
result.Units,
7676
)
@@ -81,7 +81,7 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
8181
var summaryStr string
8282
switch act := action.(type) { //nolint:gocritic
8383
case *actions.Transfer:
84-
summaryStr = fmt.Sprintf("%s %s -> %s\n", utils.FormatBalance(act.Value, consts.Decimals), consts.Symbol, actor)
84+
summaryStr = fmt.Sprintf("%s %s -> %s\n", utils.FormatBalance(act.Value), consts.Symbol, actor)
8585
}
8686
utils.Outf(
8787
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}summary (%s):{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
@@ -91,7 +91,7 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
9191
reflect.TypeOf(action),
9292
summaryStr,
9393
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
94-
utils.FormatBalance(result.Fee, consts.Decimals),
94+
utils.FormatBalance(result.Fee),
9595
consts.Symbol,
9696
result.Units,
9797
)

examples/morpheusvm/cmd/morpheus-cli/cmd/spam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (sh *SpamHelper) LookupBalance(choice int, address codec.Address) (uint64,
7373
"%d) {{cyan}}address:{{/}} %s {{cyan}}balance:{{/}} %s %s\n",
7474
choice,
7575
address,
76-
utils.FormatBalance(balance, consts.Decimals),
76+
utils.FormatBalance(balance),
7777
consts.Symbol,
7878
)
7979
return balance, err

0 commit comments

Comments
 (0)