/
Program.cs
60 lines (50 loc) · 1.93 KB
/
Program.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
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Linq;
using System.Threading.Tasks;
using Casper.Network.SDK;
using Casper.Network.SDK.JsonRpc;
namespace ListRewards
{
public static class ListRewards
{
static string nodeAddress = "http://52.35.59.254:7777/rpc";
static NetCasperClient casperSdk;
public async static Task GetEraSummary()
{
var rpcResponse = await casperSdk.GetEraInfoBySwitchBlock(435_733);
var eraSummary = rpcResponse.Parse().EraSummary;
Console.WriteLine("Block Hash: " + eraSummary.BlockHash);
Console.WriteLine("Era Id : " + eraSummary.EraId);
var eraInfo = eraSummary.StoredValue.EraInfo;
// print the era rewards per validator
//
Console.WriteLine("Validator Deleg. Rewards");
Console.WriteLine("--------------------------------------------------------------------------------------------------------");
var groupedByValidator = eraInfo.SeigniorageAllocations
.GroupBy(allocation => allocation.ValidatorPublicKey);
foreach (var group in groupedByValidator)
{
var eraRewards = group.Sum(a => (double)a.Amount);
eraRewards /= 1_000_000_000;
Console.WriteLine($"{group.Key} - {group.Count(),5} - " +
$"{eraRewards.ToString("N9"),20} $CSPR");
}
}
public async static Task Main(string[] args)
{
casperSdk = new NetCasperClient(nodeAddress);
try
{
await GetEraSummary();
}
catch (RpcClientException e)
{
Console.WriteLine(e.RpcError.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}