getBNBTransactions method
Implementation
@override
Future<List<Map<String, dynamic>>> getBNBTransactions(String address) async {
try {
final currentBlock = await _client.getBlockNumber();
final fromBlock = currentBlock - 1000; // 1000개 블록으로 줄임
List<Map<String, dynamic>> transactions = [];
// 작은 범위로 나누어 조회
for (int i = fromBlock; i < currentBlock; i += 10) {
final toBlock = (i + 10 > currentBlock) ? currentBlock : i + 10;
final logs = await _client.getLogs(
FilterOptions(
fromBlock: BlockNum.exact(i),
toBlock: BlockNum.exact(toBlock),
address: EthereumAddress.fromHex(address),
topics: null,
),
);
for (var log in logs) {
if (log.address!.hex.toLowerCase() == address.toLowerCase() ||
log.topics!.any((topic) => topic!.contains(address.toLowerCase()))) {
transactions.add({
'hash': log.transactionHash,
'from': log.address!.hex,
'blockNumber': log.blockNum.toString(),
'timestamp': await getBlockTimestamp(log.blockNum.toString()),
'value': log.data,
});
}
}
// API 호출 제한을 피하기 위한 지연
await Future.delayed(Duration(milliseconds: 1000));
}
return transactions;
} catch (e) {
throw Exception('Failed to get BNB transactions: ${e.toString()}');
}
}