-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrcTrustDetailExtractor.cs
43 lines (38 loc) · 1.45 KB
/
CrcTrustDetailExtractor.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
using System;
using System.Collections.Generic;
using System.Linq;
using CirclesLand.BlockchainIndexer.TransactionDetailModels;
using Nethereum.BlockchainProcessing.BlockStorage.Entities.Mapping;
using Nethereum.RPC.Eth.DTOs;
namespace CirclesLand.BlockchainIndexer.DetailExtractors
{
public static class CrcTrustDetailExtractor
{
public static IEnumerable<IDetail> Extract(Transaction transactionData, TransactionReceipt receipt)
{
var log = receipt.Logs
.FirstOrDefault(o =>
TransactionClassifier.GetTopics(o).Contains(Settings.CrcTrustEventTopic));
if (log == null)
{
throw new Exception("The supplied transaction is not a valid CRC 'trust' transaction because " +
$"it misses a log entry with topic {Settings.CrcTrustEventTopic}.");
}
var isCrcTrust = TransactionClassifier.IsCrcTrust(
log,
out var canSendTo,
out var user,
out var limit);
if (!isCrcTrust || canSendTo == null || user == null || limit == null)
{
throw new Exception("The supplied transaction and receipt is not a CrcTrust.");
}
yield return new CrcTrust
{
Address = user,
CanSendTo = canSendTo,
Limit = limit.ToLong()
};
}
}
}