Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client.go #132

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/geth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version: '3'

services:
geth:
image: ethereum/client-go:v1.10.23
image: ethereum/client-go:v1.14.6
environment:
- DEVMODE=true
volumes:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
uses: ./.github/actions/geth
id: geth

- name: Sleep for 20 seconds
run: sleep 20s
- name: Sleep for 60 seconds
run: sleep 60s
shell: bash

- name: Get latest block from geth node
Expand Down
45 changes: 16 additions & 29 deletions examples/ethereum/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"

"log"
"math/big"
Expand Down Expand Up @@ -61,55 +60,43 @@ func (c *EthereumClient) GetBlockReceipts(
txs []evmClient.RPCTransaction,
baseFee *big.Int,
) ([]*evmClient.RosettaTxReceipt, error) {
receipts := make([]*evmClient.RosettaTxReceipt, len(txs))
if len(txs) == 0 {
return receipts, nil
return []*evmClient.RosettaTxReceipt{}, nil
}

ethReceipts := make([]*EthTypes.Receipt, len(txs))
reqs := make([]rpc.BatchElem, len(txs))
for i := range reqs {
reqs[i] = rpc.BatchElem{
Method: "eth_getTransactionReceipt",
Args: []interface{}{txs[i].TxExtraInfo.TxHash.String()},
Result: &ethReceipts[i],
}
}
if err := c.BatchCallContext(ctx, reqs); err != nil {
var ethReceipts []*EthTypes.Receipt
err := c.CallContext(ctx, &ethReceipts, "eth_getBlockReceipts", blockHash.Hex())
if err != nil {
return nil, err
}
for i := range reqs {
if reqs[i].Error != nil {
return nil, reqs[i].Error
}

if len(ethReceipts) != len(txs) {
return nil, fmt.Errorf("mismatch in number of transactions and receipts")
}

receipts := make([]*evmClient.RosettaTxReceipt, len(txs))
for i, ethReceipt := range ethReceipts {
gasPrice, err := evmClient.EffectiveGasPrice(txs[i].Tx, baseFee)
if err != nil {
return nil, err
}
gasUsed := new(big.Int).SetUint64(ethReceipts[i].GasUsed)
gasUsed := new(big.Int).SetUint64(ethReceipt.GasUsed)
feeAmount := new(big.Int).Mul(gasUsed, gasPrice)

receipt := &evmClient.RosettaTxReceipt{
Type: ethReceipts[i].Type,
receipts[i] = &evmClient.RosettaTxReceipt{
Type: ethReceipt.Type,
GasPrice: gasPrice,
GasUsed: gasUsed,
Logs: ethReceipts[i].Logs,
Logs: ethReceipt.Logs,
RawMessage: nil,
TransactionFee: feeAmount,
}

receipts[i] = receipt

if ethReceipts[i] == nil {
return nil, fmt.Errorf("got empty receipt for %x", txs[i].Tx.Hash().Hex())
}

if ethReceipts[i].BlockHash != blockHash {
if ethReceipt.BlockHash != blockHash {
return nil, fmt.Errorf(
"expected block hash %s for Transaction but got %s: %w",
blockHash.Hex(),
ethReceipts[i].BlockHash.Hex(),
ethReceipt.BlockHash.Hex(),
sdkTypes.ErrClientBlockOrphaned,
)
}
Expand Down
Loading