Patch for concurrent iterator & others (onto v1.11.6) #386
@ -1888,25 +1888,45 @@ func NewDebugAPI(b Backend) *DebugAPI {
|
|||||||
return &DebugAPI{b: b}
|
return &DebugAPI{b: b}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHeaderRlp retrieves the RLP encoded for of a single header.
|
// GetRawHeader retrieves the RLP encoding for a single header.
|
||||||
func (api *DebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) {
|
func (api *DebugAPI) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
|
||||||
header, _ := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number))
|
var hash common.Hash
|
||||||
|
if h, ok := blockNrOrHash.Hash(); ok {
|
||||||
|
hash = h
|
||||||
|
} else {
|
||||||
|
block, err := api.b.BlockByNumberOrHash(ctx, blockNrOrHash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
hash = block.Hash()
|
||||||
|
}
|
||||||
|
header, _ := api.b.HeaderByHash(ctx, hash)
|
||||||
if header == nil {
|
if header == nil {
|
||||||
return nil, fmt.Errorf("header #%d not found", number)
|
return nil, fmt.Errorf("header #%d not found", hash)
|
||||||
}
|
}
|
||||||
return rlp.EncodeToBytes(header)
|
return rlp.EncodeToBytes(header)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockRlp retrieves the RLP encoded for of a single block.
|
// GetRawBlock retrieves the RLP encoded for a single block.
|
||||||
func (api *DebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) {
|
func (api *DebugAPI) GetRawBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
|
||||||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
var hash common.Hash
|
||||||
|
if h, ok := blockNrOrHash.Hash(); ok {
|
||||||
|
hash = h
|
||||||
|
} else {
|
||||||
|
block, err := api.b.BlockByNumberOrHash(ctx, blockNrOrHash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
hash = block.Hash()
|
||||||
|
}
|
||||||
|
block, _ := api.b.BlockByHash(ctx, hash)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, fmt.Errorf("block #%d not found", number)
|
return nil, fmt.Errorf("block #%d not found", hash)
|
||||||
}
|
}
|
||||||
return rlp.EncodeToBytes(block)
|
return rlp.EncodeToBytes(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRawReceipts retrieves the binary-encoded raw receipts of a single block.
|
// GetRawReceipts retrieves the binary-encoded receipts of a single block.
|
||||||
func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) {
|
func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) {
|
||||||
var hash common.Hash
|
var hash common.Hash
|
||||||
if h, ok := blockNrOrHash.Hash(); ok {
|
if h, ok := blockNrOrHash.Hash(); ok {
|
||||||
@ -1933,6 +1953,22 @@ func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.Block
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRawTransaction returns the bytes of the transaction for the given hash.
|
||||||
|
func (s *DebugAPI) GetRawTransaction(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) {
|
||||||
|
// Retrieve a finalized transaction, or a pooled otherwise
|
||||||
|
tx, _, _, _, err := s.b.GetTransaction(ctx, hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if tx == nil {
|
||||||
|
if tx = s.b.GetPoolTransaction(hash); tx == nil {
|
||||||
|
// Transaction not found anywhere, abort
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tx.MarshalBinary()
|
||||||
|
}
|
||||||
|
|
||||||
// PrintBlock retrieves a block and returns its pretty printed form.
|
// PrintBlock retrieves a block and returns its pretty printed form.
|
||||||
func (api *DebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) {
|
func (api *DebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) {
|
||||||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
||||||
|
@ -224,13 +224,13 @@ web3._extend({
|
|||||||
outputFormatter: console.log
|
outputFormatter: console.log
|
||||||
}),
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'getHeaderRlp',
|
name: 'getRawHeader',
|
||||||
call: 'debug_getHeaderRlp',
|
call: 'debug_getRawHeader',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'getBlockRlp',
|
name: 'getRawBlock',
|
||||||
call: 'debug_getBlockRlp',
|
call: 'debug_getRawBlock',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
@ -238,6 +238,11 @@ web3._extend({
|
|||||||
call: 'debug_getRawReceipts',
|
call: 'debug_getRawReceipts',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'getRawTransaction',
|
||||||
|
call: 'debug_getRawTransaction',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'setHead',
|
name: 'setHead',
|
||||||
call: 'debug_setHead',
|
call: 'debug_setHead',
|
||||||
|
Loading…
Reference in New Issue
Block a user