mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
triedb/pathdb: change stateset encode/decode
This commit is contained in:
parent
0104c64075
commit
88800178a4
1 changed files with 12 additions and 11 deletions
|
|
@ -92,13 +92,14 @@ func NewStateSetWithOrigin(accountOrigin map[common.Address][]byte, storageOrigi
|
||||||
// encode serializes the content of state set into the provided writer.
|
// encode serializes the content of state set into the provided writer.
|
||||||
func (s *StateSetWithOrigin) encode(w io.Writer) error {
|
func (s *StateSetWithOrigin) encode(w io.Writer) error {
|
||||||
// Encode accounts
|
// Encode accounts
|
||||||
type Account struct {
|
type Accounts struct {
|
||||||
Address common.Address
|
Addresses []common.Address
|
||||||
Blob []byte
|
Accounts [][]byte
|
||||||
}
|
}
|
||||||
accounts := make([]Account, 0, len(s.accountOrigin))
|
var accounts Accounts
|
||||||
for address, blob := range s.accountOrigin {
|
for address, blob := range s.accountOrigin {
|
||||||
accounts = append(accounts, Account{Address: address, Blob: blob})
|
accounts.Addresses = append(accounts.Addresses, address)
|
||||||
|
accounts.Accounts = append(accounts.Accounts, blob)
|
||||||
}
|
}
|
||||||
if err := rlp.Encode(w, accounts); err != nil {
|
if err := rlp.Encode(w, accounts); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -125,19 +126,19 @@ func (s *StateSetWithOrigin) encode(w io.Writer) error {
|
||||||
// decode deserializes the content from the rlp stream into the state set.
|
// decode deserializes the content from the rlp stream into the state set.
|
||||||
func (s *StateSetWithOrigin) decode(r *rlp.Stream) error {
|
func (s *StateSetWithOrigin) decode(r *rlp.Stream) error {
|
||||||
// Decode account origin
|
// Decode account origin
|
||||||
type Account struct {
|
type Accounts struct {
|
||||||
Address common.Address
|
Addresses []common.Address
|
||||||
Blob []byte
|
Accounts [][]byte
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
accounts []Account
|
accounts Accounts
|
||||||
accountSet = make(map[common.Address][]byte)
|
accountSet = make(map[common.Address][]byte)
|
||||||
)
|
)
|
||||||
if err := r.Decode(&accounts); err != nil {
|
if err := r.Decode(&accounts); err != nil {
|
||||||
return fmt.Errorf("load diff account origin set: %v", err)
|
return fmt.Errorf("load diff account origin set: %v", err)
|
||||||
}
|
}
|
||||||
for _, account := range accounts {
|
for i := 0; i < len(accounts.Accounts); i++ {
|
||||||
accountSet[account.Address] = account.Blob
|
accountSet[accounts.Addresses[i]] = accounts.Accounts[i]
|
||||||
}
|
}
|
||||||
s.accountOrigin = accountSet
|
s.accountOrigin = accountSet
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue