forked from jingkunlee/Tron.Wallet.Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TronServiceExtension.cs
31 lines (25 loc) · 1.12 KB
/
TronServiceExtension.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
using Microsoft.Extensions.Options;
namespace Tron.Wallet.Web;
using Microsoft.Extensions.DependencyInjection;
using TronNetSdk;
public record TronRecord(IServiceProvider ServiceProvider, ITronClient? TronClient, IOptions<TronNetOptions>? Options);
public static class TronServiceExtension {
private static IServiceProvider AddTron() {
IServiceCollection services = new ServiceCollection();
services.AddTronNet(x =>
{
x.Network = TronNetwork.MainNet;
x.Channel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50051 };
x.SolidityChannel = new GrpcChannelOption { Host = "grpc.trongrid.io", Port = 50052 };
x.ApiKey = "80a8b20f-a917-43a9-a2f1-809fe6eec0d6";
});
services.AddLogging();
return services.BuildServiceProvider();
}
public static TronRecord GetRecord() {
var provider = AddTron();
var client = provider.GetService<ITronClient>();
var options = provider.GetService<IOptions<TronNetOptions>>();
return new TronRecord(provider, client, options);
}
}