simplify ethclient

This commit is contained in:
aodhgan 2025-10-13 12:50:24 -07:00
parent 455f09d00a
commit 1d662b50a6

View file

@ -18,7 +18,6 @@
package ethclient
import (
"bytes"
"context"
"encoding/json"
"errors"
@ -698,40 +697,36 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
}
// SendRawTransactionSync submits a signed tx and waits for a receipt (or until
// SendTransactionSync submits a signed tx and waits for a receipt (or until
// the optional timeout elapses on the server side). If timeout == 0, the server
// uses its default.
func (ec *Client) SendRawTransactionSync(
func (ec *Client) SendTransactionSync(
ctx context.Context,
tx *types.Transaction,
timeout time.Duration,
timeout ...time.Duration,
) (*types.Receipt, error) {
var buf bytes.Buffer
if err := tx.EncodeRLP(&buf); err != nil {
raw, err := tx.MarshalBinary()
if err != nil {
return nil, err
}
return ec.SendRawTransactionSyncRaw(ctx, buf.Bytes(), timeout)
return ec.SendRawTransactionSync(ctx, raw, timeout...)
}
// SendRawTransactionSyncRaw is the low-level variant that takes the raw RLP.
func (ec *Client) SendRawTransactionSyncRaw(
func (ec *Client) SendRawTransactionSync(
ctx context.Context,
rawTx []byte,
timeout time.Duration,
timeout ...time.Duration,
) (*types.Receipt, error) {
var out *types.Receipt
// Build params: raw bytes as hex, plus optional timeout as hexutil.Uint64
params := []any{hexutil.Bytes(rawTx)}
if timeout > 0 {
t := hexutil.Uint64(timeout.Milliseconds())
params = append(params, t)
var ms *hexutil.Uint64
if len(timeout) > 0 && timeout[0] > 0 {
v := hexutil.Uint64(timeout[0] / time.Millisecond)
ms = &v
}
if err := ec.c.CallContext(ctx, &out, "eth_sendRawTransactionSync", params...); err != nil {
var receipt types.Receipt
if err := ec.c.CallContext(ctx, &receipt, "eth_sendRawTransactionSync", hexutil.Bytes(rawTx), ms); err != nil {
return nil, err
}
return out, nil
return &receipt, nil
}
// RevertErrorData returns the 'revert reason' data of a contract call.