Skip to content

Commit

Permalink
don't use rpc call if network is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrl-alt-lulz committed Jul 21, 2023
1 parent c5f738e commit c412000
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
17 changes: 13 additions & 4 deletions client/deploy_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"os"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -126,10 +127,18 @@ func (w *Web3Actions) GetSignedTxToDeploySmartContract(ctx context.Context, payl
log.Ctx(ctx).Err(err).Msg("Web3Actions: Transfer: SetGasPriceAndLimit")
return nil, err
}
chainID, err := w.C.ChainID(ctx)
if err != nil {
log.Ctx(ctx).Err(err).Msg("CallFunctionWithData: GetChainID")
return nil, fmt.Errorf("couldn't get chain ID: %v", err)
var chainID *big.Int
switch strings.ToLower(w.Network) {
case "mainnet":
chainID = new(big.Int).SetInt64(1)
case "goerli":
chainID = new(big.Int).SetInt64(5)
default:
chainID, err = w.C.ChainID(ctx)
if err != nil {
log.Ctx(ctx).Err(err).Msg("CallFunctionWithData: GetChainID")
return nil, fmt.Errorf("couldn't get chain ID: %v", err)
}
}
publicKeyECDSA := w.EcdsaPublicKey()
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
Expand Down
18 changes: 14 additions & 4 deletions client/prep_signed_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package web3_actions
import (
"context"
"fmt"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -17,10 +19,18 @@ func (w *Web3Actions) GetSignedSendTx(ctx context.Context, params SendEtherPaylo
log.Ctx(ctx).Err(err).Msg("Send: GetNonce")
return nil, err
}
chainID, err := w.C.ChainID(ctx)
if err != nil {
log.Ctx(ctx).Err(err).Msg("Send: GetChainID")
return nil, fmt.Errorf("couldn't get chain ID: %v", err)
var chainID *big.Int
switch strings.ToLower(w.Network) {
case "mainnet":
chainID = new(big.Int).SetInt64(1)
case "goerli":
chainID = new(big.Int).SetInt64(5)
default:
chainID, err = w.C.ChainID(ctx)
if err != nil {
log.Ctx(ctx).Err(err).Msg("CallFunctionWithData: GetChainID")
return nil, fmt.Errorf("couldn't get chain ID: %v", err)
}
}
scAddr := common.HexToAddress(params.ToAddress.Hex())
payload := &SendContractTxPayload{
Expand Down
18 changes: 14 additions & 4 deletions client/prep_smart_contract_signed_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package web3_actions
import (
"context"
"fmt"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -28,10 +30,18 @@ func (w *Web3Actions) GetSignedTxToCallFunctionWithData(ctx context.Context, pay
log.Ctx(ctx).Err(err).Msg("Send: SuggestAndSetGasPriceAndLimitForTx")
return nil, err
}
chainID, err := w.C.ChainID(ctx)
if err != nil {
log.Ctx(ctx).Err(err).Msg("CallFunctionWithData: GetChainID")
return nil, fmt.Errorf("couldn't get chain ID: %v", err)
var chainID *big.Int
switch strings.ToLower(w.Network) {
case "mainnet":
chainID = new(big.Int).SetInt64(1)
case "goerli":
chainID = new(big.Int).SetInt64(5)
default:
chainID, err = w.C.ChainID(ctx)
if err != nil {
log.Ctx(ctx).Err(err).Msg("CallFunctionWithData: GetChainID")
return nil, fmt.Errorf("couldn't get chain ID: %v", err)
}
}
publicKeyECDSA := w.EcdsaPublicKey()
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
Expand Down

0 comments on commit c412000

Please sign in to comment.