Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug about precision loss in Tokens func #41

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,28 @@ func MustNewRegAddress(actor eos.AccountName, address Address, ownerPubKey strin

// BurnAddress will destroy an address owned by an account
type BurnAddress struct {
FioAddress Address `json:"fio_address"`
FioAddress string `json:"fio_address"`
Actor eos.AccountName `json:"actor"`
Tpid string `json:"tpid"`
MaxFee uint64 `json:"max_fee"`
}

func NewBurnAddress(actor eos.AccountName, address Address, tpid string) (action *Action, ok bool) {
func NewBurnAddress(actor eos.AccountName, address Address) (action *Action, ok bool) {
if ok := address.Valid(); !ok {
return nil, false
}
return NewAction("fio.address", "burnaddress", actor,
BurnAddress{
FioAddress: address,
FioAddress: string(address),
Actor: actor,
Tpid: tpid,
Tpid: CurrentTpid(),
MaxFee: Tokens(GetMaxFee(FeeBurnAddress)),
},
), true
}

func MustNewBurnAddress(actor eos.AccountName, address Address, tpid string) (action *Action) {
a, ok := NewBurnAddress(actor, address, tpid)
func MustNewBurnAddress(actor eos.AccountName, address Address) (action *Action) {
a, ok := NewBurnAddress(actor, address)
if !ok {
panic("invalid fio address in call to MustBurnNewAddress")
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/ethereum/go-ethereum v1.9.25
github.com/mr-tron/base58 v1.2.0
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.5
github.com/tidwall/sjson v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9Ac
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
Expand Down
3 changes: 2 additions & 1 deletion token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package fio

import (
"github.com/fioprotocol/fio-go/eos"
"github.com/shopspring/decimal"
)

const FioSymbol = "ᵮ"

// Tokens is a convenience function for converting from a float for human readability.
// Example 1 FIO Token: Tokens(1.0) == uint64(1000000000)
func Tokens(tokens float64) uint64 {
return uint64(tokens * 1000000000.0)
return uint64(decimal.NewFromFloat(tokens).Mul(decimal.NewFromInt(1000000000)).IntPart())
}

// TransferTokensPubKey is used to send FIO tokens to a public key
Expand Down