erigon-pulse/core/rawdb/accessors_account.go
Alex Sharov 068463dff4
Store transactions individually (#1358)
* Store transactions individually

* Store transactions individually

* save progress

* checkIndex

* merge
2020-11-22 21:25:26 +00:00

71 lines
2.5 KiB
Go

// Copyright 2018 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package rawdb
import (
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/core/types/accounts"
)
// ReadAccount reading account object from multiple buckets of db
func ReadAccount(db databaseReader, addrHash common.Hash, acc *accounts.Account) (bool, error) {
addrHashBytes := addrHash[:]
enc, err := db.Get(dbutils.CurrentStateBucket, addrHashBytes)
if err != nil {
return false, err
}
if err = acc.DecodeForStorage(enc); err != nil {
return false, err
}
return true, nil
}
func WriteAccount(db DatabaseWriter, addrHash common.Hash, acc accounts.Account) error {
//fmt.Printf("WriteAccount: %x %x\n", addrHash, acc.Root)
addrHashBytes := addrHash[:]
value := make([]byte, acc.EncodingLengthForStorage())
acc.EncodeForStorage(value)
return db.Put(dbutils.CurrentStateBucket, addrHashBytes, value)
}
func DeleteAccount(db DatabaseDeleter, addrHash common.Hash) error {
return db.Delete(dbutils.CurrentStateBucket, addrHash[:], nil)
}
func PlainReadAccount(db databaseReader, address common.Address, acc *accounts.Account) (bool, error) {
enc, err := db.Get(dbutils.PlainStateBucket, address[:])
if err != nil {
return false, err
}
if err = acc.DecodeForStorage(enc); err != nil {
return false, err
}
return true, nil
}
func PlainWriteAccount(db DatabaseWriter, address common.Address, acc accounts.Account) error {
//fmt.Printf("PlainWriteAccount: %x %x\n", addrHash, acc.Root)
value := make([]byte, acc.EncodingLengthForStorage())
acc.EncodeForStorage(value)
return db.Put(dbutils.PlainStateBucket, address[:], value)
}
func PlainDeleteAccount(db DatabaseDeleter, address common.Address) error {
return db.Delete(dbutils.PlainStateBucket, address[:], nil)
}