-
Notifications
You must be signed in to change notification settings - Fork 46
/
key.go
70 lines (55 loc) · 1.73 KB
/
key.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package types
import (
"crypto/md5"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
)
const (
// ModuleName is the name of the module
ModuleName = "microtx"
// StoreKey to be used when creating the KVStore
StoreKey = ModuleName
// RouterKey is the module name router key
RouterKey = ModuleName
// QuerierRoute to be used for querierer msgs
QuerierRoute = ModuleName
)
var (
// The Microtx Module's bech32 address
ModuleAddress = authtypes.NewModuleAddress(ModuleName)
// The Microtx Module's EVM address
ModuleEVMAddress = common.BytesToAddress(ModuleAddress.Bytes())
// LiquidAccountKey is the index for all Liquid Infrastructure Accounts, whose keys contain
// a bech32 x/auth account address and values are EVM LiquidInfrastructureNFT contract addresses
LiquidAccountKey = HashString("LiquidAccount")
)
// GetLiquidAccountKey returns the LiquidAccount key for the given bech32 address,
// the key's format is [ LiquidAccountKey | bech32 address ]
func GetLiquidAccountKey(address sdk.AccAddress) []byte {
return AppendBytes(LiquidAccountKey, []byte(address.String()))
}
func GetAccountFromLiquidAccountKey(key []byte) sdk.AccAddress {
accountBz := key[len(LiquidAccountKey):]
return sdk.AccAddress(accountBz)
}
// Hashing string using cryptographic MD5 function
// returns 128bit(16byte) value
func HashString(input string) []byte {
md5 := md5.New()
md5.Write([]byte(input))
return md5.Sum(nil)
}
func AppendBytes(args ...[]byte) []byte {
length := 0
for _, v := range args {
length += len(v)
}
res := make([]byte, length)
length = 0
for _, v := range args {
copy(res[length:length+len(v)], v)
length += len(v)
}
return res
}