Skip to content

Commit

Permalink
The following methods were created: eth_createAccessList, eth_coinbas…
Browse files Browse the repository at this point in the history
…e, eth_getBlockReceipts, txpool_ContentFrom
  • Loading branch information
novosandara committed Mar 10, 2024
1 parent 07ada94 commit 22a5ece
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
90 changes: 90 additions & 0 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,37 @@ func (e *Eth) filterExtra(block *types.Block) error {
return nil
}

// CreateAccessList creates a EIP-2930 type AccessList for the given transaction.
// Reexec and BlockNrOrHash can be specified to create the accessList on top of a certain state.
func (e *Eth) CreateAccessList(arg *txnArgs, filter BlockNumberOrHash) (interface{}, error) {
header, err := GetHeaderFromBlockNumberOrHash(filter, e.store)
if err != nil {
return nil, err
}

transaction, err := DecodeTxn(arg, header.Number, e.store, true)
if err != nil {
return nil, err
}

res := &accessListResult{
Accesslist: transaction.AccessList(),
GasUsed: argUint64(header.GasUsed),
}

return res, nil
}

// Returns the client coinbase address.
func (e *Eth) Coinbase() (interface{}, error) {
h := e.store.Header()
if h == nil {
return nil, fmt.Errorf("header has a nil value")
}

return types.BytesToAddress(h.Miner), nil
}

// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.
func (e *Eth) GetBlockTransactionCountByHash(blockHash types.Hash) (interface{}, error) {
block, ok := e.store.GetBlockByHash(blockHash, true)
Expand Down Expand Up @@ -410,6 +441,65 @@ func (e *Eth) GetTransactionReceipt(hash types.Hash) (interface{}, error) {
return toReceipt(raw, txn, uint64(txIndex), block.Header, logs), nil
}

// GetBlockReceipts returns all transaction receipts for a given block.
func (e *Eth) GetBlockReceipts(number BlockNumber) (interface{}, error) {
num, err := GetNumericBlockNumber(number, e.store)
if err != nil {
return nil, err
}

block, ok := e.store.GetBlockByNumber(num, true)
if !ok {
return nil, nil
}

blockHash := block.Hash()
receipts, err := e.store.GetReceiptsByHash(blockHash)
if err != nil {

Check failure on line 458 in jsonrpc/eth_endpoint.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

only one cuddle assignment allowed before if statement (wsl)
// block receipts not found
e.logger.Warn(
fmt.Sprintf("Receipts for block with hash [%s] not found", blockHash.String()),
)

return nil, nil
}

numberOfReceipts := len(receipts)
if numberOfReceipts == 0 {
// Receipts not written yet on the db
e.logger.Warn(
fmt.Sprintf("No receipts found for block with hash [%s]", blockHash.String()),
)

return nil, nil
}

if len(block.Transactions) == 0 {
e.logger.Warn(
fmt.Sprintf("No transations found for block with hash [%s]", blockHash.String()),

Check failure on line 479 in jsonrpc/eth_endpoint.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

`transations` is a misspelling of `transitions` (misspell)
)

return nil, nil
}

if numberOfReceipts > len(block.Transactions) {
numberOfReceipts = len(block.Transactions)
}

var resReceipts []*receipt = make([]*receipt, numberOfReceipts)

Check failure on line 489 in jsonrpc/eth_endpoint.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

ST1023: should omit type []*receipt from declaration; it will be inferred from the right-hand side (stylecheck)
logIndex := 0

Check failure on line 490 in jsonrpc/eth_endpoint.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

assignments should only be cuddled with other assignments (wsl)
for txIndex, txn := range block.Transactions {

Check failure on line 491 in jsonrpc/eth_endpoint.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

only one cuddle assignment allowed before range statement (wsl)
raw := receipts[txIndex]
// accumulate receipt logs indexes from block transactions
// that are before the desired transaction
logIndex += len(receipts[txIndex].Logs)
logs := toLogs(raw.Logs, uint64(logIndex), uint64(txIndex), block.Header, raw.TxHash)
resReceipts[txIndex] = toReceipt(raw, txn, uint64(txIndex), block.Header, logs)
}

return resReceipts, nil
}

// GetStorageAt returns the contract storage at the index position
func (e *Eth) GetStorageAt(
address types.Address,
Expand Down
36 changes: 36 additions & 0 deletions jsonrpc/txpool_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type ContentResponse struct {
Queued map[types.Address]map[uint64]*transaction `json:"queued"`
}

type ContentAddressResponse struct {
Pending map[uint64]*transaction `json:"pending"`
Queued map[uint64]*transaction `json:"queued"`
}

type InspectResponse struct {
Pending map[string]map[string]string `json:"pending"`
Queued map[string]map[string]string `json:"queued"`
Expand All @@ -41,6 +46,37 @@ type StatusResponse struct {
Queued uint64 `json:"queued"`
}

// ContentFrom returns the transactions contained within the transaction pool.
func (t *TxPool) ContentFrom(addr types.Address) (interface{}, error) {
convertTxMap := func(txMap []*types.Transaction) map[uint64]*transaction {
result := make(map[uint64]*transaction, len(txMap))
for key, tx := range txMap {
result[uint64(key)] = toTransaction(tx, nil, &types.ZeroHash, nil)
}

return result
}

pendingTxs, queuedTxs := t.store.GetTxs(true)

pTxs, ok := pendingTxs[addr]
if !ok {
return nil, nil
}

qTxs, ok := queuedTxs[addr]
if !ok {
return nil, nil
}

resp := ContentAddressResponse{
Pending: convertTxMap(pTxs),
Queued: convertTxMap(qTxs),
}

return resp, nil
}

// Create response for txpool_content request.
// See https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content.
func (t *TxPool) Content() (interface{}, error) {
Expand Down
5 changes: 5 additions & 0 deletions jsonrpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ type header struct {
BaseFee argUint64 `json:"baseFeePerGas,omitempty"`
}

type accessListResult struct {
Accesslist types.TxAccessList `json:"accessList"`
GasUsed argUint64 `json:"gasUsed"`
}

type block struct {
ParentHash types.Hash `json:"parentHash"`
Sha3Uncles types.Hash `json:"sha3Uncles"`
Expand Down

0 comments on commit 22a5ece

Please sign in to comment.