-
Notifications
You must be signed in to change notification settings - Fork 10
/
account.go
63 lines (48 loc) · 1.32 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
package types
import (
"encoding/binary"
"github.com/holiman/uint256"
"github.com/smartbch/moeingevm/utils"
)
type AccountInfo struct {
data []byte
}
func NewAccountInfo(data []byte) *AccountInfo {
if len(data) != 49 {
panic("Invalid length for AccountInfo")
}
return &AccountInfo{data: data}
}
func ZeroAccountInfo() *AccountInfo {
return &AccountInfo{data: make([]byte, 49)}
}
func (info *AccountInfo) BalanceSlice() []byte {
return info.data[1:33]
}
func (info *AccountInfo) NonceSlice() []byte {
return info.data[33:41]
}
func (info *AccountInfo) SequenceSlice() []byte {
return info.data[41:49]
}
func (info *AccountInfo) Bytes() []byte {
return info.data
}
func (info *AccountInfo) Balance() *uint256.Int {
return utils.U256FromSlice32(info.BalanceSlice())
}
func (info *AccountInfo) UpdateBalance(newBalance *uint256.Int) {
copy(info.BalanceSlice(), utils.U256ToSlice32(newBalance))
}
func (info *AccountInfo) Nonce() uint64 {
return binary.BigEndian.Uint64(info.NonceSlice())
}
func (info *AccountInfo) UpdateNonce(newNonce uint64) {
binary.BigEndian.PutUint64(info.NonceSlice(), newNonce)
}
func (info *AccountInfo) Sequence() uint64 {
return binary.BigEndian.Uint64(info.SequenceSlice())
}
func (info *AccountInfo) UpdateSequence(newSeq uint64) {
binary.BigEndian.PutUint64(info.SequenceSlice(), newSeq)
}