Skip to content

Commit 31fc4d5

Browse files
committed
set address in From optionally for CallOpts
1 parent 17ca79b commit 31fc4d5

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

seth/client.go

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,11 @@ func WithBlockNumber(bn uint64) CallOpt {
582582

583583
// NewCallOpts returns a new sequential call options wrapper
584584
func (m *Client) NewCallOpts(o ...CallOpt) *bind.CallOpts {
585-
if errCallOpts := m.errCallOptsIfAddressCountTooLow(0); errCallOpts != nil {
586-
return errCallOpts
587-
}
588585
co := &bind.CallOpts{
589586
Pending: false,
590-
From: m.Addresses[0],
587+
}
588+
if len(m.Addresses) > 0 {
589+
co.From = m.Addresses[0]
591590
}
592591
for _, f := range o {
593592
f(co)
@@ -597,43 +596,19 @@ func (m *Client) NewCallOpts(o ...CallOpt) *bind.CallOpts {
597596

598597
// NewCallKeyOpts returns a new sequential call options wrapper from the key N
599598
func (m *Client) NewCallKeyOpts(keyNum int, o ...CallOpt) *bind.CallOpts {
600-
if errCallOpts := m.errCallOptsIfAddressCountTooLow(keyNum); errCallOpts != nil {
601-
return errCallOpts
602-
}
603-
604599
co := &bind.CallOpts{
605600
Pending: false,
606601
From: m.Addresses[keyNum],
607602
}
603+
if len(m.Addresses) > 0 {
604+
co.From = m.Addresses[keyNum]
605+
}
608606
for _, f := range o {
609607
f(co)
610608
}
611609
return co
612610
}
613611

614-
// errCallOptsIfAddressCountTooLow returns non-nil CallOpts with error in Context if keyNum is out of range
615-
func (m *Client) errCallOptsIfAddressCountTooLow(keyNum int) *bind.CallOpts {
616-
if err := m.validateAddressesKeyNum(keyNum); err != nil {
617-
errText := err.Error()
618-
if keyNum == TimeoutKeyNum {
619-
errText += " (this is a probably because we didn't manage to find any synced key before timeout)"
620-
}
621-
622-
err := errors.New(errText)
623-
m.Errors = append(m.Errors, err)
624-
opts := &bind.CallOpts{}
625-
626-
// can't return nil, otherwise RPC wrapper will panic and we might lose funds on testnets/mainnets, that's why
627-
// error is passed in Context here to avoid panic, whoever is using Seth should make sure that there is no error
628-
// present in Context before using *bind.TransactOpts
629-
opts.Context = context.WithValue(context.Background(), ContextErrorKey{}, err)
630-
631-
return opts
632-
}
633-
634-
return nil
635-
}
636-
637612
// errTxOptsIfPrivateKeysCountTooLow returns non-nil TransactOpts with error in Context if keyNum is out of range
638613
func (m *Client) errTxOptsIfPrivateKeysCountTooLow(keyNum int) *bind.TransactOpts {
639614
if err := m.validatePrivateKeysKeyNum(keyNum); err != nil {
@@ -913,14 +888,14 @@ func (m *Client) CalculateGasEstimations(request GasEstimationRequest) GasEstima
913888
ctx, cancel := context.WithTimeout(context.Background(), m.Cfg.Network.TxnTimeout.Duration())
914889
defer cancel()
915890

916-
var disableEstimationsIfNeeded = func(err error) {
891+
disableEstimationsIfNeeded := func(err error) {
917892
if strings.Contains(err.Error(), ZeroGasSuggestedErr) {
918893
L.Warn().Msg("Received incorrect gas estimations. Disabling them and reverting to hardcoded values. Remember to update your config!")
919894
m.Cfg.Network.GasPriceEstimationEnabled = false
920895
}
921896
}
922897

923-
var calculateLegacyFees = func() {
898+
calculateLegacyFees := func() {
924899
gasPrice, err := m.GetSuggestedLegacyFees(ctx, request.Priority)
925900
if err != nil {
926901
disableEstimationsIfNeeded(err)

0 commit comments

Comments
 (0)