2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program 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 Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-05-02 16:17:02 +00:00
|
|
|
package level
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-11-23 18:12:24 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2018-05-02 16:17:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2019-04-03 05:14:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
2019-07-15 22:08:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2018-05-02 16:17:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Reader interface {
|
|
|
|
GetBlock(hash common.Hash, number uint64) *types.Block
|
2018-11-23 18:12:24 +00:00
|
|
|
GetBlockNumber(hash common.Hash) *uint64
|
2018-05-02 16:17:02 +00:00
|
|
|
GetBlockReceipts(hash common.Hash, number uint64) types.Receipts
|
|
|
|
GetCanonicalHash(number uint64) common.Hash
|
2018-05-03 21:58:45 +00:00
|
|
|
GetHeadBlockHash() common.Hash
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LevelDatabaseReader struct {
|
2019-04-03 05:14:02 +00:00
|
|
|
reader ethdb.Reader
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 05:14:02 +00:00
|
|
|
func NewLevelDatabaseReader(reader ethdb.Reader) *LevelDatabaseReader {
|
2018-05-03 21:58:45 +00:00
|
|
|
return &LevelDatabaseReader{reader: reader}
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ldbr *LevelDatabaseReader) GetBlock(hash common.Hash, number uint64) *types.Block {
|
2018-11-23 18:12:24 +00:00
|
|
|
return rawdb.ReadBlock(ldbr.reader, hash, number)
|
2018-05-03 21:58:45 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 18:12:24 +00:00
|
|
|
func (ldbr *LevelDatabaseReader) GetBlockNumber(hash common.Hash) *uint64 {
|
|
|
|
return rawdb.ReadHeaderNumber(ldbr.reader, hash)
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ldbr *LevelDatabaseReader) GetBlockReceipts(hash common.Hash, number uint64) types.Receipts {
|
2019-07-15 22:08:40 +00:00
|
|
|
return rawdb.ReadReceipts(ldbr.reader, hash, number, ¶ms.ChainConfig{})
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ldbr *LevelDatabaseReader) GetCanonicalHash(number uint64) common.Hash {
|
2018-11-23 18:12:24 +00:00
|
|
|
return rawdb.ReadCanonicalHash(ldbr.reader, number)
|
2018-05-03 21:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ldbr *LevelDatabaseReader) GetHeadBlockHash() common.Hash {
|
2018-11-23 18:12:24 +00:00
|
|
|
return rawdb.ReadHeadBlockHash(ldbr.reader)
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|