Skip to content

Commit c48eec3

Browse files
author
=
committed
fix: decode txs concurrently
1 parent 2afbf4e commit c48eec3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

internal/common/transaction.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"math/big"
66
"strings"
7+
"sync"
78

89
"github.com/ethereum/go-ethereum/accounts/abi"
910
"github.com/rs/zerolog/log"
@@ -53,7 +54,7 @@ type DecodedTransaction struct {
5354
}
5455

5556
func DecodeTransactions(chainId string, txs []Transaction) []*DecodedTransaction {
56-
decodedTxs := []*DecodedTransaction{}
57+
decodedTxs := make([]*DecodedTransaction, len(txs))
5758
abis := make(map[string]*abi.ABI)
5859

5960
decodeTxFunc := func(transaction *Transaction) *DecodedTransaction {
@@ -68,6 +69,7 @@ func DecodeTransactions(chainId string, txs []Transaction) []*DecodedTransaction
6869
} else {
6970
abis[transaction.ToAddress] = abiResult
7071
}
72+
abi = abiResult
7173
}
7274

7375
if abi == nil {
@@ -94,10 +96,16 @@ func DecodeTransactions(chainId string, txs []Transaction) []*DecodedTransaction
9496
return transaction.Decode(method)
9597
}
9698

97-
for _, transaction := range txs {
98-
decodedTx := decodeTxFunc(&transaction)
99-
decodedTxs = append(decodedTxs, decodedTx)
99+
var wg sync.WaitGroup
100+
for idx, transaction := range txs {
101+
wg.Add(1)
102+
go func(idx int, transaction Transaction) {
103+
defer wg.Done()
104+
decodedTx := decodeTxFunc(&transaction)
105+
decodedTxs[idx] = decodedTx
106+
}(idx, transaction)
100107
}
108+
wg.Wait()
101109
return decodedTxs
102110
}
103111

0 commit comments

Comments
 (0)