Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Jan 5, 2021
1 parent 9703cec commit 1e2cc1c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ type backend struct {
abiMap map[string]*abi.ABI
nonceManager *NonceManager
signer types.Signer

maxGasPrice *big.Int
}

func NewBackend(client *ethclient.Client, signer types.Signer) (Backend, error) {
func NewBackend(client *ethclient.Client, signer types.Signer, maxGasPrice *big.Int) (Backend, error) {
abiMap, err := makeABIMap()
if err != nil {
return nil, err
Expand All @@ -60,6 +62,7 @@ func NewBackend(client *ethclient.Client, signer types.Signer) (Backend, error)
abiMap,
NewNonceManager(client),
signer,
maxGasPrice,
}, nil
}

Expand Down Expand Up @@ -99,6 +102,19 @@ func (b *backend) SendTransaction(ctx context.Context, tx *types.Transaction) er
return nil
}

func (b *backend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
gp, err := b.Client.SuggestGasPrice(ctx)
if err != nil {
return nil, err
}

if b.maxGasPrice != nil && gp.Cmp(b.maxGasPrice) >= 0 {
return nil, fmt.Errorf("current gas price exceeds maximum gas price")
}

return gp, nil
}

type txLog struct {
method string
inputs string
Expand Down
2 changes: 1 addition & 1 deletion eth/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestSendTransaction_SendErr_DontUpdateNonce(t *testing.T) {
signedTx, err := types.SignTx(tx, signer, privateKey)
require.Nil(t, err)

bi, err := NewBackend(client, signer)
bi, err := NewBackend(client, signer, nil)
require.Nil(t, err)

nonceLockBefore := bi.(*backend).nonceManager.getNonceLock(fromAddress)
Expand Down
2 changes: 1 addition & 1 deletion eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func NewClient(accountAddr ethcommon.Address, keystoreDir string, eth *ethclient

signer := types.NewEIP155Signer(chainID)

backend, err := NewBackend(eth, signer)
backend, err := NewBackend(eth, signer, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1e2cc1c

Please sign in to comment.