github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/triedb/history.go (about) 1 // Copyright 2023 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package triedb 18 19 import ( 20 "errors" 21 22 "github.com/ethereum/go-ethereum/common" 23 "github.com/ethereum/go-ethereum/triedb/pathdb" 24 ) 25 26 // AccountHistory inspects the account history within the specified range. 27 // 28 // Start: State ID of the first history object for the query. 0 implies the first 29 // available object is selected as the starting point. 30 // 31 // End: State ID of the last history for the query. 0 implies the last available 32 // object is selected as the starting point. Note end is included for query. 33 // 34 // This function is only supported by path mode database. 35 func (db *Database) AccountHistory(address common.Address, start, end uint64) (*pathdb.HistoryStats, error) { 36 pdb, ok := db.backend.(*pathdb.Database) 37 if !ok { 38 return nil, errors.New("not supported") 39 } 40 return pdb.AccountHistory(address, start, end) 41 } 42 43 // StorageHistory inspects the storage history within the specified range. 44 // 45 // Start: State ID of the first history object for the query. 0 implies the first 46 // available object is selected as the starting point. 47 // 48 // End: State ID of the last history for the query. 0 implies the last available 49 // object is selected as the starting point. Note end is included for query. 50 // 51 // Note, slot refers to the hash of the raw slot key. 52 // 53 // This function is only supported by path mode database. 54 func (db *Database) StorageHistory(address common.Address, slot common.Hash, start uint64, end uint64) (*pathdb.HistoryStats, error) { 55 pdb, ok := db.backend.(*pathdb.Database) 56 if !ok { 57 return nil, errors.New("not supported") 58 } 59 return pdb.StorageHistory(address, slot, start, end) 60 } 61 62 // HistoryRange returns the block numbers associated with earliest and latest 63 // state history in the local store. 64 // 65 // This function is only supported by path mode database. 66 func (db *Database) HistoryRange() (uint64, uint64, error) { 67 pdb, ok := db.backend.(*pathdb.Database) 68 if !ok { 69 return 0, 0, errors.New("not supported") 70 } 71 return pdb.HistoryRange() 72 }