evm/transactionoptions.go

59 lines
1.2 KiB
Go

package evm
import (
"context"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/shopspring/decimal"
)
type TransactOpts struct {
*bind.TransactOpts
}
func NewTransactOpts(ctx context.Context, client Client) (*TransactOpts, error) {
auth, err := client.NewTransactor()
if err != nil {
return nil, err
}
auth.Context = ctx
return &TransactOpts{
auth,
}, nil
}
func (o *TransactOpts) SetValue(value decimal.Decimal) *TransactOpts {
o.Value = value.Shift(18).BigInt()
return o
}
func (o *TransactOpts) SetGasLimit(limit uint64) *TransactOpts {
o.GasLimit = limit
return o
}
func (o *TransactOpts) SetGasPrice(gasprice decimal.Decimal) *TransactOpts {
o.GasPrice = gasprice.Shift(9).BigInt()
return o
}
type ExecutionOption func(*TransactOpts) *TransactOpts
func WithGasPrice(gasprice decimal.Decimal) ExecutionOption {
return func(opts *TransactOpts) *TransactOpts {
return opts.SetGasPrice(gasprice)
}
}
func WithGasLimit(gaslimit uint64) ExecutionOption {
return func(opts *TransactOpts) *TransactOpts {
return opts.SetGasLimit(gaslimit)
}
}
func WithValue(value decimal.Decimal) ExecutionOption {
return func(opts *TransactOpts) *TransactOpts {
return opts.SetValue(value)
}
}