github.com/palisadeinc/bor@v0.0.0-20230615125219-ab7196213d15/internal/ethapi/bor_api.go (about)

     1  package ethapi
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ethereum/go-ethereum/common"
     7  	"github.com/ethereum/go-ethereum/core/types"
     8  )
     9  
    10  // GetRootHash returns root hash for given start and end block
    11  func (s *PublicBlockChainAPI) GetRootHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64) (string, error) {
    12  	root, err := s.b.GetRootHash(ctx, starBlockNr, endBlockNr)
    13  	if err != nil {
    14  		return "", err
    15  	}
    16  	return root, nil
    17  }
    18  
    19  func (s *PublicBlockChainAPI) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) {
    20  	return s.b.GetBorBlockReceipt(ctx, hash)
    21  }
    22  
    23  //
    24  // Bor transaction utils
    25  //
    26  
    27  func (s *PublicBlockChainAPI) appendRPCMarshalBorTransaction(ctx context.Context, block *types.Block, fields map[string]interface{}, fullTx bool) map[string]interface{} {
    28  	if block != nil {
    29  		txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash()))
    30  		borTx, blockHash, blockNumber, txIndex, _ := s.b.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash())
    31  		if borTx != nil {
    32  			formattedTxs := fields["transactions"].([]interface{})
    33  			if fullTx {
    34  				marshalledTx := newRPCTransaction(borTx, blockHash, blockNumber, txIndex, block.BaseFee(), s.b.ChainConfig())
    35  				// newRPCTransaction calculates hash based on RLP of the transaction data.
    36  				// In case of bor block tx, we need simple derived tx hash (same as function argument) instead of RLP hash
    37  				marshalledTx.Hash = txHash
    38  				fields["transactions"] = append(formattedTxs, marshalledTx)
    39  			} else {
    40  				fields["transactions"] = append(formattedTxs, txHash)
    41  			}
    42  		}
    43  	}
    44  	return fields
    45  }