github.com/amazechain/amc@v0.1.3/common/blockchain.go (about)

     1  // Copyright 2022 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package common
    18  
    19  import (
    20  	"github.com/amazechain/amc/common/block"
    21  	"github.com/amazechain/amc/common/types"
    22  	"github.com/amazechain/amc/internal/consensus"
    23  	"github.com/amazechain/amc/modules/state"
    24  	"github.com/amazechain/amc/params"
    25  	"github.com/holiman/uint256"
    26  	"github.com/ledgerwatch/erigon-lib/kv"
    27  	"github.com/libp2p/go-libp2p/core/peer"
    28  )
    29  
    30  type IHeaderChain interface {
    31  	GetHeaderByNumber(number *uint256.Int) block.IHeader
    32  	GetHeaderByHash(h types.Hash) (block.IHeader, error)
    33  	InsertHeader(headers []block.IHeader) (int, error)
    34  	GetBlockByHash(h types.Hash) (block.IBlock, error)
    35  	GetBlockByNumber(number *uint256.Int) (block.IBlock, error)
    36  }
    37  
    38  type IBlockChain interface {
    39  	IHeaderChain
    40  	Config() *params.ChainConfig
    41  	CurrentBlock() block.IBlock
    42  	Blocks() []block.IBlock
    43  	Start() error
    44  	GenesisBlock() block.IBlock
    45  	NewBlockHandler(payload []byte, peer peer.ID) error
    46  	InsertChain(blocks []block.IBlock) (int, error)
    47  	InsertBlock(blocks []block.IBlock, isSync bool) (int, error)
    48  	SetEngine(engine consensus.Engine)
    49  	GetBlocksFromHash(hash types.Hash, n int) (blocks []block.IBlock)
    50  	SealedBlock(b block.IBlock) error
    51  	Engine() consensus.Engine
    52  	GetReceipts(blockHash types.Hash) (block.Receipts, error)
    53  	GetLogs(blockHash types.Hash) ([][]*block.Log, error)
    54  	SetHead(head uint64) error
    55  	AddFutureBlock(block block.IBlock) error
    56  
    57  	GetHeader(types.Hash, *uint256.Int) block.IHeader
    58  	// alias for GetBlocksFromHash?
    59  	GetBlock(hash types.Hash, number uint64) block.IBlock
    60  	StateAt(tx kv.Tx, blockNr uint64) *state.IntraBlockState
    61  
    62  	GetTd(hash types.Hash, number *uint256.Int) *uint256.Int
    63  	HasBlock(hash types.Hash, number uint64) bool
    64  
    65  	DB() kv.RwDB
    66  	Quit() <-chan struct{}
    67  
    68  	Close() error
    69  
    70  	WriteBlockWithState(block block.IBlock, receipts []*block.Receipt, ibs *state.IntraBlockState, nopay map[types.Address]*uint256.Int) error
    71  
    72  	GetDepositInfo(address types.Address) (*uint256.Int, *uint256.Int)
    73  	GetAccountRewardUnpaid(account types.Address) (*uint256.Int, error)
    74  }
    75  
    76  type IMiner interface {
    77  	Start()
    78  	PendingBlockAndReceipts() (block.IBlock, block.Receipts)
    79  }