-
Notifications
You must be signed in to change notification settings - Fork 179
/
coin_adapter.go
35 lines (31 loc) · 929 Bytes
/
coin_adapter.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
package types
func CoinAdapterToCoin(adapter CoinAdapter) Coin {
return Coin{
Denom: adapter.Denom,
Amount: NewDecFromBigIntWithPrec(adapter.Amount.BigInt(), Precision),
}
}
func CoinToCoinAdapter(adapter Coin) CoinAdapter {
return CoinAdapter{
Denom: adapter.Denom,
Amount: NewIntFromBigInt(adapter.Amount.BigInt()),
}
}
func CoinAdaptersToCoins(adapters CoinAdapters) Coins {
var coins Coins = make([]Coin, 0, len(adapters))
for i, _ := range adapters {
coins = append(coins, CoinAdapterToCoin(adapters[i]))
}
return coins
}
func CoinsToCoinAdapters(coins Coins) CoinAdapters {
//Note:
// `var adapters CoinAdapters = make([]CoinAdapter, 0)`
// The code above if invalid.
// []CoinAdapter{} and nil are different in json format which can make different signBytes.
var adapters CoinAdapters
for i, _ := range coins {
adapters = append(adapters, CoinToCoinAdapter(coins[i]))
}
return adapters
}