2020-01-22 10:25:07 +00:00
|
|
|
package changeset
|
2019-10-31 10:59:00 +00:00
|
|
|
|
|
|
|
import (
|
2020-01-16 21:21:40 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
2019-10-31 10:59:00 +00:00
|
|
|
)
|
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
/* Hashed changesets (key is a hash of common.Address) */
|
|
|
|
|
2020-01-22 10:25:07 +00:00
|
|
|
func NewAccountChangeSet() *ChangeSet {
|
2019-12-20 12:25:40 +00:00
|
|
|
return &ChangeSet{
|
|
|
|
Changes: make([]Change, 0),
|
2020-01-22 10:25:07 +00:00
|
|
|
keyLen: common.HashLength,
|
2019-12-20 12:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 10:25:07 +00:00
|
|
|
func EncodeAccounts(s *ChangeSet) ([]byte, error) {
|
2020-05-15 07:52:45 +00:00
|
|
|
return encodeAccounts(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeAccounts(b []byte) (*ChangeSet, error) {
|
|
|
|
h := NewAccountChangeSet()
|
|
|
|
err := decodeAccountsWithKeyLen(b, common.HashLength, h)
|
2019-12-03 11:13:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-15 07:52:45 +00:00
|
|
|
return h, nil
|
2019-10-31 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
type AccountChangeSetBytes []byte
|
2020-01-15 20:51:10 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func (b AccountChangeSetBytes) Walk(f func(k, v []byte) error) error {
|
|
|
|
return walkAccountChangeSet(b, common.HashLength, f)
|
2019-10-31 10:59:00 +00:00
|
|
|
}
|
2019-12-20 12:25:40 +00:00
|
|
|
|
2020-06-16 14:03:35 +00:00
|
|
|
func (b AccountChangeSetBytes) Find(k []byte) ([]byte, error) {
|
|
|
|
return findInAccountChangeSetBytes(b, k, common.HashLength)
|
2019-12-20 12:25:40 +00:00
|
|
|
}
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
/* Plain changesets (key is a common.Address) */
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func NewAccountChangeSetPlain() *ChangeSet {
|
|
|
|
return &ChangeSet{
|
|
|
|
Changes: make([]Change, 0),
|
|
|
|
keyLen: common.AddressLength,
|
2020-01-16 21:21:40 +00:00
|
|
|
}
|
2020-05-15 07:52:45 +00:00
|
|
|
}
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func EncodeAccountsPlain(s *ChangeSet) ([]byte, error) {
|
|
|
|
return encodeAccounts(s)
|
|
|
|
}
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func DecodeAccountsPlain(b []byte) (*ChangeSet, error) {
|
|
|
|
h := NewAccountChangeSetPlain()
|
|
|
|
err := decodeAccountsWithKeyLen(b, common.AddressLength, h)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-01-16 21:21:40 +00:00
|
|
|
}
|
2020-05-15 07:52:45 +00:00
|
|
|
return h, nil
|
|
|
|
}
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
type AccountChangeSetPlainBytes []byte
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func (b AccountChangeSetPlainBytes) Walk(f func(k, v []byte) error) error {
|
|
|
|
return walkAccountChangeSet(b, common.AddressLength, f)
|
|
|
|
}
|
2020-01-16 21:21:40 +00:00
|
|
|
|
2020-06-16 14:03:35 +00:00
|
|
|
func (b AccountChangeSetPlainBytes) Find(k []byte) ([]byte, error) {
|
|
|
|
return findInAccountChangeSetBytes(b, k, common.AddressLength)
|
2020-01-16 21:21:40 +00:00
|
|
|
}
|