forked from evmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
54 lines (43 loc) · 1.31 KB
/
account.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
package types
import (
"encoding/hex"
"errors"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
)
// Address in go-crypto style
type Address = cmn.HexBytes
// create an Address from a string
func GetAddress(address string) (addr Address, err error) {
if len(address) == 0 {
return addr, errors.New("must use provide address")
}
bz, err := hex.DecodeString(address)
if err != nil {
return nil, err
}
return Address(bz), nil
}
// Account is a standard account using a sequence number for replay protection
// and a pubkey for authentication.
type Account interface {
GetAddress() Address
SetAddress(Address) error // errors if already set.
GetPubKey() crypto.PubKey // can return nil.
SetPubKey(crypto.PubKey) error
GetSequence() int64
SetSequence(int64) error
GetCoins() Coins
SetCoins(Coins) error
Get(key interface{}) (value interface{}, err error)
Set(key interface{}, value interface{}) error
}
// AccountMapper stores and retrieves accounts from stores
// retrieved from the context.
type AccountMapper interface {
NewAccountWithAddress(ctx Context, addr Address) Account
GetAccount(ctx Context, addr Address) Account
SetAccount(ctx Context, acc Account)
}
// AccountDecoder unmarshals account bytes
type AccountDecoder func(accountBytes []byte) (Account, error)