@@ -179,47 +179,35 @@ func (b *BaseRPC) GetTransactionsByAddress(address string, fromTxId string) ([]m
179
179
from := strings .ToLower (event .From .Hex ())
180
180
to := strings .ToLower (event .To .Hex ())
181
181
182
- // Skip if neither from nor to address is the target address, only interested in transactions related to the contract 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
- })
190
- continue
182
+ transaction := model.OnchainIcyTransaction {
183
+ TransactionHash : event .Raw .TxHash .Hex (),
184
+ Amount : event .Value .String (),
185
+ BlockNumber : event .Raw .BlockNumber ,
191
186
}
192
-
193
187
// Determine transaction type
194
- var txType model.TransactionType
195
- var otherAddress common.Address
196
188
if from == address {
197
- txType = model .Out
198
- otherAddress = event .To
189
+ transaction . Type = model .Out
190
+ transaction . ToAddress = event .To . Hex ()
199
191
} else if to == address {
200
- txType = model .In
201
- otherAddress = event .From
192
+ transaction .Type = model .In
193
+ transaction .FromAddress = event .From .Hex ()
194
+ } else {
195
+ transaction .Type = model .Transfer
196
+ transaction .FromAddress = event .From .Hex ()
197
+ transaction .ToAddress = event .To .Hex ()
202
198
}
203
199
204
200
// Get block time if possible
205
201
block , err := b .erc20Service .client .BlockByNumber (context .Background (), big .NewInt (int64 (event .Raw .BlockNumber )))
206
- var blockTime int64
207
202
if err == nil {
208
- blockTime = int64 (block .Time ())
203
+ transaction . BlockTime = int64 (block .Time ())
209
204
} else {
210
205
b .logger .Error ("[GetTransactionsByAddress][BlockByNumber] cannot get block data" , map [string ]string {
211
206
"error" : err .Error (),
212
207
})
213
208
}
214
209
215
- transactions = append (transactions , model.OnchainIcyTransaction {
216
- TransactionHash : event .Raw .TxHash .Hex (),
217
- Amount : event .Value .String (),
218
- Type : txType ,
219
- OtherAddress : otherAddress .Hex (),
220
- BlockTime : blockTime ,
221
- BlockNumber : event .Raw .BlockNumber ,
222
- })
210
+ transactions = append (transactions , transaction )
223
211
}
224
212
225
213
b .logger .Info ("[GetTransactionsByAddress] found transactions" , map [string ]string {
0 commit comments