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

Migration to geth:1.13.13 #37

Merged
merged 4 commits into from
Feb 23, 2024
Merged
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 accounts/eth_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/miguelmota/go-ethereum-hdwallet"
"github.com/pkg/errors"
"github.com/stephenlacy/go-ethereum-hdwallet"
"github.com/zksync-sdk/zksync2-go/eip712"
)

Expand Down
2 changes: 1 addition & 1 deletion accounts/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/miguelmota/go-ethereum-hdwallet"
"github.com/pkg/errors"
"github.com/stephenlacy/go-ethereum-hdwallet"
"github.com/zksync-sdk/zksync2-go/eip712"
)

Expand Down
78 changes: 56 additions & 22 deletions clients/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ func (c *BaseClient) PendingTransactionCount(ctx context.Context) (uint, error)
}

func (c *BaseClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
return c.ethClient.CallContract(ctx, msg, blockNumber)
var hex hexutil.Bytes
err := c.rpcClient.CallContext(ctx, &hex, "eth_call", toCallArg(msg), toBlockNumArg(blockNumber))
if err != nil {
return nil, err
}
return hex, nil
}

func (c *BaseClient) CallContractL2(ctx context.Context, msg zkTypes.CallMsg, blockNumber *big.Int) ([]byte, error) {
Expand All @@ -237,7 +242,12 @@ func (c *BaseClient) CallContractL2(ctx context.Context, msg zkTypes.CallMsg, bl
}

func (c *BaseClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
return c.ethClient.CallContractAtHash(ctx, msg, blockHash)
var hex hexutil.Bytes
err := c.rpcClient.CallContext(ctx, &hex, "eth_call", toCallArg(msg), rpc.BlockNumberOrHashWithHash(blockHash, false))
if err != nil {
return nil, err
}
return hex, nil
}

func (c *BaseClient) CallContractAtHashL2(ctx context.Context, msg zkTypes.CallMsg, blockHash common.Hash) ([]byte, error) {
Expand All @@ -250,7 +260,12 @@ func (c *BaseClient) CallContractAtHashL2(ctx context.Context, msg zkTypes.CallM
}

func (c *BaseClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
return c.ethClient.PendingCallContract(ctx, msg)
var hex hexutil.Bytes
err := c.rpcClient.CallContext(ctx, &hex, "eth_call", toCallArg(msg), "pending")
if err != nil {
return nil, err
}
return hex, nil
}

func (c *BaseClient) PendingCallContractL2(ctx context.Context, msg zkTypes.CallMsg) ([]byte, error) {
Expand All @@ -271,7 +286,12 @@ func (c *BaseClient) SuggestGasTipCap(_ context.Context) (*big.Int, error) {
}

func (c *BaseClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) {
return c.ethClient.EstimateGas(ctx, call)
var hex hexutil.Uint64
err := c.rpcClient.CallContext(ctx, &hex, "eth_estimateGas", toCallArg(call))
if err != nil {
return 0, err
}
return uint64(hex), nil
}

func (c *BaseClient) EstimateGasL2(ctx context.Context, msg zkTypes.CallMsg) (uint64, error) {
Expand Down Expand Up @@ -725,24 +745,26 @@ func (c *BaseClient) getBlock(ctx context.Context, method string, args ...interf

return &zkTypes.Block{
Header: &types.Header{
ParentHash: block.ParentHash,
UncleHash: block.UncleHash,
Coinbase: block.Coinbase,
Root: block.Root,
TxHash: block.TxHash,
ReceiptHash: block.ReceiptHash,
Bloom: block.Bloom,
Difficulty: block.Difficulty.ToInt(),
Number: block.Number.ToInt(),
GasLimit: uint64(block.GasLimit),
GasUsed: uint64(block.GasUsed),
Time: uint64(block.Time),
Extra: block.Extra,
MixDigest: block.MixDigest,
Nonce: block.Nonce,
BaseFee: block.BaseFee.ToInt(),
WithdrawalsHash: nil,
ExcessDataGas: block.ExcessDataGas.ToInt(),
ParentHash: block.ParentHash,
UncleHash: block.UncleHash,
Coinbase: block.Coinbase,
Root: block.Root,
TxHash: block.TxHash,
ReceiptHash: block.ReceiptHash,
Bloom: block.Bloom,
Difficulty: block.Difficulty.ToInt(),
Number: block.Number.ToInt(),
GasLimit: uint64(block.GasLimit),
GasUsed: uint64(block.GasUsed),
Time: uint64(block.Time),
Extra: block.Extra,
MixDigest: block.MixDigest,
Nonce: block.Nonce,
BaseFee: block.BaseFee.ToInt(),
WithdrawalsHash: nil,
BlobGasUsed: nil,
ExcessBlobGas: nil,
ParentBeaconRoot: nil,
},
Uncles: uncles,
Transactions: block.Transactions,
Expand All @@ -764,3 +786,15 @@ func (c *BaseClient) Proof(ctx context.Context, address common.Address, keys []c
}
return &res, nil
}

func generateRandomAddress() (common.Address, error) {
privateKey, err := crypto.GenerateKey()
if err != nil {
return common.Address{}, fmt.Errorf("failed to generate radnom private key: %w", err)
}
publicKey, ok := privateKey.Public().(*ecdsa.PublicKey)
if !ok {
return common.Address{}, fmt.Errorf("failed to convert public key to ECDSA")
}
return crypto.PubkeyToAddress(*publicKey), nil
}
35 changes: 35 additions & 0 deletions clients/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ func toFilterArg(q ethereum.FilterQuery) (interface{}, error) {
return arg, nil
}

func toCallArg(msg ethereum.CallMsg) interface{} {
arg := map[string]interface{}{
"from": msg.From,
"to": msg.To,
}
if len(msg.Data) > 0 {
arg["data"] = hexutil.Bytes(msg.Data)
}
if msg.Value != nil {
arg["value"] = (*hexutil.Big)(msg.Value)
}
if msg.Gas != 0 {
arg["gas"] = hexutil.Uint64(msg.Gas)
}
if msg.GasPrice != nil {
arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice)
}
if msg.GasFeeCap != nil {
arg["maxFeePerGas"] = (*hexutil.Big)(msg.GasFeeCap)
}
if msg.GasTipCap != nil {
arg["maxPriorityFeePerGas"] = (*hexutil.Big)(msg.GasTipCap)
}
if msg.AccessList != nil {
arg["accessList"] = msg.AccessList
}
if msg.BlobGasFeeCap != nil {
arg["maxFeePerBlobGas"] = (*hexutil.Big)(msg.BlobGasFeeCap)
}
if msg.BlobHashes != nil {
arg["blobVersionedHashes"] = msg.BlobHashes
}
return arg
}

func toBlockNumArg(number *big.Int) string {
if number == nil {
return "latest"
Expand Down
47 changes: 29 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,45 @@ module github.com/zksync-sdk/zksync2-go
go 1.21

require (
github.com/ethereum/go-ethereum v1.12.0
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/ethereum/go-ethereum v1.13.13
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.1
github.com/stephenlacy/go-ethereum-hdwallet v0.0.0-20230913225845-a4fa94429863
github.com/stretchr/testify v1.8.4
)

require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/btcsuite/btcd v0.22.3 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd v0.24.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/tools v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading
Loading