internal/ethapi: add GetReceipt to Backend
This commit is contained in:
parent
8f13fe41ec
commit
4eed38c39d
|
@ -209,6 +209,12 @@ func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*type
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetReceiptByHash retrieves the receipt by transaction hash
|
||||||
|
func (bc *BlockChain) GetReceiptByHash(txHash common.Hash) *types.Receipt {
|
||||||
|
receipt, _, _, _ := rawdb.ReadReceipt(bc.db, txHash, bc.chainConfig)
|
||||||
|
return receipt
|
||||||
|
}
|
||||||
|
|
||||||
// GetReceiptsByHash retrieves the receipts for all transactions in a given block.
|
// GetReceiptsByHash retrieves the receipts for all transactions in a given block.
|
||||||
func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
|
func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
|
||||||
if receipts, ok := bc.receiptsCache.Get(hash); ok {
|
if receipts, ok := bc.receiptsCache.Get(hash); ok {
|
||||||
|
|
|
@ -234,6 +234,10 @@ func (b *EthAPIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockN
|
||||||
return nil, nil, errors.New("invalid arguments; neither block nor hash specified")
|
return nil, nil, errors.New("invalid arguments; neither block nor hash specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *EthAPIBackend) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
||||||
|
return b.eth.blockchain.GetReceiptByHash(txHash), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
return b.eth.blockchain.GetReceiptsByHash(hash), nil
|
return b.eth.blockchain.GetReceiptsByHash(hash), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,11 @@ func (b *testBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.
|
||||||
return nil, errors.New("block body not found")
|
return nil, errors.New("block body not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *testBackend) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
||||||
|
receipt, _, _, _ := rawdb.ReadReceipt(b.db, txHash, params.TestChainConfig)
|
||||||
|
return receipt, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b *testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
if number := rawdb.ReadHeaderNumber(b.db, hash); number != nil {
|
if number := rawdb.ReadHeaderNumber(b.db, hash); number != nil {
|
||||||
if header := rawdb.ReadHeader(b.db, hash, *number); header != nil {
|
if header := rawdb.ReadHeader(b.db, hash, *number); header != nil {
|
||||||
|
|
|
@ -99,6 +99,10 @@ func (b *testBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber)
|
||||||
return b.chain.GetBlockByNumber(uint64(number)), nil
|
return b.chain.GetBlockByNumber(uint64(number)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *testBackend) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
||||||
|
return b.chain.GetReceiptByHash(txHash), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b *testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
return b.chain.GetReceiptsByHash(hash), nil
|
return b.chain.GetReceiptsByHash(hash), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -550,6 +550,10 @@ func (b testBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOr
|
||||||
panic("only implemented for number")
|
panic("only implemented for number")
|
||||||
}
|
}
|
||||||
func (b testBackend) Pending() (*types.Block, types.Receipts, *state.StateDB) { panic("implement me") }
|
func (b testBackend) Pending() (*types.Block, types.Receipts, *state.StateDB) { panic("implement me") }
|
||||||
|
func (b testBackend) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
||||||
|
receipt, _, _, _ := rawdb.ReadReceipt(b.db, txHash, b.chain.Config())
|
||||||
|
return receipt, nil
|
||||||
|
}
|
||||||
func (b testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
header, err := b.HeaderByHash(ctx, hash)
|
header, err := b.HeaderByHash(ctx, hash)
|
||||||
if header == nil || err != nil {
|
if header == nil || err != nil {
|
||||||
|
|
|
@ -67,6 +67,7 @@ type Backend interface {
|
||||||
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
|
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
|
||||||
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
|
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
|
||||||
Pending() (*types.Block, types.Receipts, *state.StateDB)
|
Pending() (*types.Block, types.Receipts, *state.StateDB)
|
||||||
|
GetReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error)
|
||||||
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
|
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
|
||||||
GetTd(ctx context.Context, hash common.Hash) *big.Int
|
GetTd(ctx context.Context, hash common.Hash) *big.Int
|
||||||
GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
|
GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
|
||||||
|
|
|
@ -361,6 +361,9 @@ func (b *backendMock) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrO
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
func (b *backendMock) Pending() (*types.Block, types.Receipts, *state.StateDB) { return nil, nil, nil }
|
func (b *backendMock) Pending() (*types.Block, types.Receipts, *state.StateDB) { return nil, nil, nil }
|
||||||
|
func (b *backendMock) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
func (b *backendMock) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b *backendMock) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue