-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
363 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"network": { | ||
"blockchain": "Optimism", | ||
"network": "Goerli", | ||
"sub_network_identifier": null | ||
}, | ||
"online_url": "http://localhost:8080", | ||
"data_directory": "", | ||
"http_timeout": 300, | ||
"max_retries": 100, | ||
"max_online_connections": 500, | ||
"force_retry": true, | ||
"max_sync_concurrency": 64, | ||
"tip_delay": 120, | ||
"max_reorg_depth": 64, | ||
"log_configuration": false, | ||
"compression_disabled": true, | ||
"l0_in_memory_enabled": true, | ||
"all_in_memory_enabled": true, | ||
"table_size": 1, | ||
"value_log_file_size": 1024, | ||
"construction": null, | ||
"data": { | ||
"start_index": 4307133, | ||
"reconciliation_disabled": true, | ||
"inactive_discrepancy_search_disabled": true, | ||
"balance_tracking_disabled": true, | ||
"initial_balance_fetch_disabled":true, | ||
"active_reconciliation_concurrency": 32, | ||
"bootstrap_balances": "", | ||
"log_balance_changes": true, | ||
"log_transactions": true, | ||
"log_blocks": true, | ||
"end_conditions": { | ||
"tip": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
|
||
evmClient "github.com/coinbase/rosetta-geth-sdk/client" | ||
sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" | ||
EthTypes "github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
func (c *OpClient) GetBlockReceipts( | ||
ctx context.Context, | ||
blockHash common.Hash, | ||
txs []evmClient.RPCTransaction, | ||
baseFee *big.Int, | ||
) ([]*evmClient.RosettaTxReceipt, error) { | ||
receipts := make([]*evmClient.RosettaTxReceipt, len(txs)) | ||
if len(txs) == 0 { | ||
return receipts, 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: ðReceipts[i], | ||
} | ||
} | ||
|
||
maxBatchSize := 25 | ||
for i := 0; i < len(txs); i += maxBatchSize { | ||
if i+maxBatchSize < len(txs) { | ||
if err := c.BatchCallContext(ctx, reqs[i:i+maxBatchSize]); err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
if err := c.BatchCallContext(ctx, reqs[i:]); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
|
||
for i := range reqs { | ||
if reqs[i].Error != nil { | ||
return nil, reqs[i].Error | ||
} | ||
|
||
gasPrice, err := evmClient.EffectiveGasPrice(txs[i].Tx, baseFee) | ||
if err != nil { | ||
return nil, err | ||
} | ||
gasUsed := new(big.Int).SetUint64(ethReceipts[i].GasUsed) | ||
feeAmount := new(big.Int).Mul(gasUsed, gasPrice) | ||
if ethReceipts[i].L1Fee != nil { | ||
feeAmount.Add(feeAmount, ethReceipts[i].L1Fee) | ||
} | ||
|
||
receiptJSON, err := ethReceipts[i].MarshalJSON() | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to marshal receipt for %x: %v", txs[i].Tx.Hash().Hex(), err) | ||
} | ||
receipt := &evmClient.RosettaTxReceipt{ | ||
Type: ethReceipts[i].Type, | ||
GasPrice: gasPrice, | ||
GasUsed: gasUsed, | ||
Logs: ethReceipts[i].Logs, | ||
// This is a hack to get around the fact that the RosettaTxReceipt doesn't contain L1 fees. We add the raw receipt here so we can access other rollup fields later | ||
RawMessage: receiptJSON, | ||
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 { | ||
return nil, fmt.Errorf( | ||
"%w: expected block hash %s for Transaction but got %s", | ||
sdkTypes.ErrClientBlockOrphaned, | ||
blockHash.Hex(), | ||
ethReceipts[i].BlockHash.Hex(), | ||
) | ||
} | ||
} | ||
|
||
return receipts, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// GetNativeTransferGasLimit is Ethereum's custom implementation of estimating gas. | ||
func (c *OpClient) GetNativeTransferGasLimit(ctx context.Context, toAddress string, | ||
fromAddress string, value *big.Int) (uint64, error) { | ||
if len(toAddress) == 0 || value == nil { | ||
// We guard against malformed inputs that may have been generated using | ||
// a previous version of asset's rosetta | ||
return 21000, nil | ||
} | ||
to := common.HexToAddress(toAddress) | ||
return c.EstimateGas(ctx, ethereum.CallMsg{ | ||
From: common.HexToAddress(fromAddress), | ||
To: &to, | ||
Value: value, | ||
}) | ||
} |
Oops, something went wrong.