2021-11-08 18:20:31 +00:00
|
|
|
package evm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-11-09 04:11:05 +00:00
|
|
|
|
2021-11-08 18:20:31 +00:00
|
|
|
"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
|
|
|
|
}
|
2021-11-09 04:11:05 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|