@@ -1888,25 +1888,45 @@ func NewDebugAPI(b Backend) *DebugAPI {
18881888 return & DebugAPI {b : b }
18891889}
18901890
1891- // GetHeaderRlp retrieves the RLP encoded for of a single header.
1892- func (api * DebugAPI ) GetHeaderRlp (ctx context.Context , number uint64 ) (hexutil.Bytes , error ) {
1893- header , _ := api .b .HeaderByNumber (ctx , rpc .BlockNumber (number ))
1891+ // GetRawHeader retrieves the RLP encoding for a single header.
1892+ func (api * DebugAPI ) GetRawHeader (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) (hexutil.Bytes , error ) {
1893+ var hash common.Hash
1894+ if h , ok := blockNrOrHash .Hash (); ok {
1895+ hash = h
1896+ } else {
1897+ block , err := api .b .BlockByNumberOrHash (ctx , blockNrOrHash )
1898+ if err != nil {
1899+ return nil , err
1900+ }
1901+ hash = block .Hash ()
1902+ }
1903+ header , _ := api .b .HeaderByHash (ctx , hash )
18941904 if header == nil {
1895- return nil , fmt .Errorf ("header #%d not found" , number )
1905+ return nil , fmt .Errorf ("header #%d not found" , hash )
18961906 }
18971907 return rlp .EncodeToBytes (header )
18981908}
18991909
1900- // GetBlockRlp retrieves the RLP encoded for of a single block.
1901- func (api * DebugAPI ) GetBlockRlp (ctx context.Context , number uint64 ) (hexutil.Bytes , error ) {
1902- block , _ := api .b .BlockByNumber (ctx , rpc .BlockNumber (number ))
1910+ // GetRawBlock retrieves the RLP encoded for a single block.
1911+ func (api * DebugAPI ) GetRawBlock (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) (hexutil.Bytes , error ) {
1912+ var hash common.Hash
1913+ if h , ok := blockNrOrHash .Hash (); ok {
1914+ hash = h
1915+ } else {
1916+ block , err := api .b .BlockByNumberOrHash (ctx , blockNrOrHash )
1917+ if err != nil {
1918+ return nil , err
1919+ }
1920+ hash = block .Hash ()
1921+ }
1922+ block , _ := api .b .BlockByHash (ctx , hash )
19031923 if block == nil {
1904- return nil , fmt .Errorf ("block #%d not found" , number )
1924+ return nil , fmt .Errorf ("block #%d not found" , hash )
19051925 }
19061926 return rlp .EncodeToBytes (block )
19071927}
19081928
1909- // GetRawReceipts retrieves the binary-encoded raw receipts of a single block.
1929+ // GetRawReceipts retrieves the binary-encoded receipts of a single block.
19101930func (api * DebugAPI ) GetRawReceipts (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) ([]hexutil.Bytes , error ) {
19111931 var hash common.Hash
19121932 if h , ok := blockNrOrHash .Hash (); ok {
@@ -1933,6 +1953,22 @@ func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.Block
19331953 return result , nil
19341954}
19351955
1956+ // GetRawTransaction returns the bytes of the transaction for the given hash.
1957+ func (s * DebugAPI ) GetRawTransaction (ctx context.Context , hash common.Hash ) (hexutil.Bytes , error ) {
1958+ // Retrieve a finalized transaction, or a pooled otherwise
1959+ tx , _ , _ , _ , err := s .b .GetTransaction (ctx , hash )
1960+ if err != nil {
1961+ return nil , err
1962+ }
1963+ if tx == nil {
1964+ if tx = s .b .GetPoolTransaction (hash ); tx == nil {
1965+ // Transaction not found anywhere, abort
1966+ return nil , nil
1967+ }
1968+ }
1969+ return tx .MarshalBinary ()
1970+ }
1971+
19361972// PrintBlock retrieves a block and returns its pretty printed form.
19371973func (api * DebugAPI ) PrintBlock (ctx context.Context , number uint64 ) (string , error ) {
19381974 block , _ := api .b .BlockByNumber (ctx , rpc .BlockNumber (number ))
0 commit comments