-
Notifications
You must be signed in to change notification settings - Fork 0
/
Erc20TransferDetailExtractor.cs
48 lines (43 loc) · 1.58 KB
/
Erc20TransferDetailExtractor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using CirclesLand.BlockchainIndexer.TransactionDetailModels;
using Nethereum.RPC.Eth.DTOs;
namespace CirclesLand.BlockchainIndexer.DetailExtractors
{
public static class Erc20TransferDetailExtractor
{
public static IEnumerable<IDetail> Extract(Transaction transactionData, TransactionReceipt receipt)
{
var erc20Logs = receipt.Logs
.Where(o => TransactionClassifier.GetTopics(o).Contains(Settings.TransferEventTopic))
.ToArray();
if (!erc20Logs.Any())
{
throw new Exception("The supplied transaction is not a valid CRC 'transfer' " +
"transaction because it misses a log entry with " +
$"topic {Settings.TransferEventTopic}.");
}
foreach (var erc20Log in erc20Logs)
{
var isErc20Transfer = TransactionClassifier.IsErc20Transfer(
erc20Log,
out var tokenAddress,
out var from,
out var to,
out var value);
if (!isErc20Transfer || value == null)
{
continue;
}
yield return new Erc20Transfer
{
From = from,
To = to,
Token = tokenAddress,
Value = value.ToString()
};
};
}
}
}