7
7
"encoding/hex"
8
8
"fmt"
9
9
"math/big"
10
+ "strings"
10
11
"time"
11
12
12
13
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -139,12 +140,17 @@ func (b *BaseRPC) GetTransactionsByAddress(address string, fromTxId string) ([]m
139
140
// Process transactions in batches to avoid block range limitation
140
141
const maxBlockRange = 10000
141
142
var allTransactions []model.OnchainIcyTransaction
143
+ address = strings .ToLower (address )
142
144
143
145
for currentStart := startBlock ; currentStart <= latestBlock ; currentStart += maxBlockRange {
144
146
currentEnd := currentStart + maxBlockRange
145
147
if currentEnd > latestBlock {
146
148
currentEnd = latestBlock
147
149
}
150
+ b .logger .Info ("[GetTransactionsByAddress]" , map [string ]string {
151
+ "startBlock" : fmt .Sprintf ("%d" , currentStart ),
152
+ "endBlock" : fmt .Sprintf ("%d" , currentEnd ),
153
+ })
148
154
149
155
// Prepare filter options for current block range
150
156
opts := & bind.FilterOpts {
@@ -170,19 +176,27 @@ func (b *BaseRPC) GetTransactionsByAddress(address string, fromTxId string) ([]m
170
176
var transactions []model.OnchainIcyTransaction
171
177
for iterator .Next () {
172
178
event := iterator .Event
179
+ from := strings .ToLower (event .From .Hex ())
180
+ to := strings .ToLower (event .To .Hex ())
173
181
174
182
// Skip if neither from nor to address is the target address, only interested in transactions related to the contract address
175
- if event .From .Hex () != address && event .To .Hex () != address {
183
+ if from != address && to != address {
184
+ b .logger .Info ("[GetTransactionsByAddress] skipping event" , map [string ]string {
185
+ "from" : event .From .Hex (),
186
+ "to" : event .To .Hex (),
187
+ "address" : address ,
188
+ "value" : event .Value .String (),
189
+ })
176
190
continue
177
191
}
178
192
179
193
// Determine transaction type
180
194
var txType model.TransactionType
181
195
var otherAddress common.Address
182
- if event . From . Hex () == address {
196
+ if from == address {
183
197
txType = model .Out
184
198
otherAddress = event .To
185
- } else if event . To . Hex () == address {
199
+ } else if to == address {
186
200
txType = model .In
187
201
otherAddress = event .From
188
202
}
@@ -208,8 +222,17 @@ func (b *BaseRPC) GetTransactionsByAddress(address string, fromTxId string) ([]m
208
222
})
209
223
}
210
224
225
+ b .logger .Info ("[GetTransactionsByAddress] found transactions" , map [string ]string {
226
+ "len" : fmt .Sprintf ("%d" , len (transactions )),
227
+ })
228
+
211
229
// Append batch transactions to all transactions
212
230
allTransactions = append (allTransactions , transactions ... )
231
+
232
+ // limit the number of transactions to fetch
233
+ if len (allTransactions ) >= 100 {
234
+ break
235
+ }
213
236
}
214
237
215
238
return allTransactions , nil
0 commit comments