-
Notifications
You must be signed in to change notification settings - Fork 2
/
coin.go
55 lines (44 loc) · 899 Bytes
/
coin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package types
import (
"math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type (
Coins []Coin
Coin struct {
Denom string `json:"denom"`
Amount float64 `json:"amount"`
}
)
func NewCoin(denom string, amount float64) Coin {
return Coin{
Denom: denom,
Amount: amount,
}
}
func NewCoinFromSDK(coin sdk.Coin) Coin {
return Coin{
Denom: coin.Denom,
Amount: float64(coin.Amount.BigInt().Int64()),
}
}
func NewCoinsFromSDK(coins sdk.Coins) Coins {
res := make(Coins, len(coins))
for i, c := range coins {
res[i] = NewCoinFromSDK(c)
}
return res
}
func NewCoinsFromSDKDec(coins sdk.DecCoins) Coins {
res := make(Coins, len(coins))
for i, c := range coins {
res[i] = Coin{
Denom: c.Denom,
Amount: c.Amount.MustFloat64(),
}
}
return res
}
func (c Coin) IsEqual(o Coin) bool {
return c.Denom == o.Denom && math.Nextafter(c.Amount, o.Amount) == o.Amount
}