-
Notifications
You must be signed in to change notification settings - Fork 801
/
utils.go
27 lines (21 loc) · 902 Bytes
/
utils.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
package state
import (
"encoding/binary"
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// UseiToSweiMultiplier Fields that were denominated in usei will be converted to swei (1usei = 10^12swei)
// for existing Ethereum application (which assumes 18 decimal points) to display properly.
var UseiToSweiMultiplier = big.NewInt(1_000_000_000_000)
var SdkUseiToSweiMultiplier = sdk.NewIntFromBigInt(UseiToSweiMultiplier)
var CoinbaseAddressPrefix = []byte("evm_coinbase")
func GetCoinbaseAddress(txIdx int) sdk.AccAddress {
txIndexBz := make([]byte, 8)
binary.BigEndian.PutUint64(txIndexBz, uint64(txIdx))
return append(CoinbaseAddressPrefix, txIndexBz...)
}
func SplitUseiWeiAmount(amt *big.Int) (sdk.Int, sdk.Int) {
wei := new(big.Int).Mod(amt, UseiToSweiMultiplier)
usei := new(big.Int).Quo(amt, UseiToSweiMultiplier)
return sdk.NewIntFromBigInt(usei), sdk.NewIntFromBigInt(wei)
}