Skip to content

Commit

Permalink
quick convert to optionals (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera authored Jan 20, 2024
1 parent 1af7bba commit a1400ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/transactor/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func New(noncer Noncer, signer kmstypes.TxSigner, mc3Batcher *Multicall3Batcher)
// BuildTransactionFromRequests builds a transaction from a list of requests.
func (f *Factory) BuildTransactionFromRequests(
ctx context.Context,
txReqs []*types.TxRequest,
txReqs ...*types.TxRequest,
) (*coretypes.Transaction, error) {
switch len(txReqs) {
case 0:
Expand All @@ -53,7 +53,7 @@ func (f *Factory) BuildTransactionFromRequests(
return f.BuildTransaction(ctx, txReqs[0])
default:
// len(txReqs) > 1 then build a multicall transaction.
ar := f.mc3Batcher.BatchTxRequests(ctx, txReqs)
ar := f.mc3Batcher.BatchTxRequests(ctx, txReqs...)

// Build the transaction to include the calldata.
// ar.To should be the Multicall3 contract address
Expand Down
7 changes: 3 additions & 4 deletions core/transactor/factory/multicall.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func NewMulticall3Batcher(address common.Address) *Multicall3Batcher {

// BatchTxRequests creates a batched transaction request for the given transaction requests.
func (mc *Multicall3Batcher) BatchTxRequests(
_ context.Context,
txReqs []*types.TxRequest,
_ context.Context, txReqs ...*types.TxRequest,
) *types.TxRequest {
var (
calls = make([]bindings.Multicall3Call, len(txReqs))
Expand Down Expand Up @@ -82,12 +81,12 @@ func (mc *Multicall3Batcher) BatchTxRequests(
func (mc *Multicall3Batcher) BatchCallRequests(
ctx context.Context,
from common.Address,
txReqs []*types.TxRequest,
txReqs ...*types.TxRequest,
) ([]bindings.Multicall3Result, error) {
sCtx := sdk.UnwrapContext(ctx)

// get the batched tx (call) requests
batchedCall := mc.BatchTxRequests(ctx, txReqs)
batchedCall := mc.BatchTxRequests(ctx, txReqs...)
batchedCall.From = from

// call the multicall3 contract with the batched call request
Expand Down
6 changes: 3 additions & 3 deletions core/transactor/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (t *TxrV2) mainLoop(ctx context.Context) {
t.mu.Lock()
go func() {
defer t.mu.Unlock()
if err := t.sendAndTrack(ctx, msgIDs, batch); err != nil {
if err := t.sendAndTrack(ctx, msgIDs, batch...); err != nil {
t.logger.Error("failed to process batch", "err", err)
}
}()
Expand Down Expand Up @@ -189,9 +189,9 @@ func (t *TxrV2) retrieveBatch(_ context.Context) ([]string, []*types.TxRequest)
// It builds a transaction from the batch and sends it.
// It also tracks the transaction for future reference.
func (t *TxrV2) sendAndTrack(
ctx context.Context, msgIDs []string, batch []*types.TxRequest,
ctx context.Context, msgIDs []string, batch ...*types.TxRequest,
) error {
tx, err := t.factory.BuildTransactionFromRequests(ctx, batch)
tx, err := t.factory.BuildTransactionFromRequests(ctx, batch...)
if err != nil {
return err
}
Expand Down

0 comments on commit a1400ba

Please sign in to comment.