This repository was archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathaccount.go
83 lines (64 loc) · 1.87 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
ethcmn "github.com/ethereum/go-ethereum/common"
)
var _ auth.Account = (*Account)(nil)
const (
// DenomDefault defines the single coin type/denomination supported in
// Ethermint.
DenomDefault = "Photon"
)
// ----------------------------------------------------------------------------
// Main Ethermint account
// ----------------------------------------------------------------------------
// BaseAccount implements the auth.Account interface and embeds an
// auth.BaseAccount type. It is compatible with the auth.AccountMapper.
type Account struct {
*auth.BaseAccount
// merkle root of the storage trie
//
// TODO: good chance we may not need this
Root ethcmn.Hash
CodeHash []byte
}
// ProtoBaseAccount defines the prototype function for BaseAccount used for an
// account mapper.
func ProtoBaseAccount() auth.Account {
return &Account{BaseAccount: &auth.BaseAccount{}}
}
// Balance returns the balance of an account.
func (acc Account) Balance() sdk.Int {
return acc.GetCoins().AmountOf(DenomDefault)
}
// SetBalance sets an account's balance.
func (acc Account) SetBalance(amt sdk.Int) {
acc.SetCoins(sdk.Coins{sdk.NewCoin(DenomDefault, amt)})
}
// ----------------------------------------------------------------------------
// Code & Storage
// ----------------------------------------------------------------------------
// Account code and storage type aliases.
type (
Code []byte
Storage map[ethcmn.Hash]ethcmn.Hash
)
func (c Code) String() string {
return string(c)
}
func (c Storage) String() (str string) {
for key, value := range c {
str += fmt.Sprintf("%X : %X\n", key, value)
}
return
}
// Copy returns a copy of storage.
func (c Storage) Copy() Storage {
cpy := make(Storage)
for key, value := range c {
cpy[key] = value
}
return cpy
}