-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathBasicBaseChainAElfModule.cs
More file actions
137 lines (121 loc) · 5.26 KB
/
BasicBaseChainAElfModule.cs
File metadata and controls
137 lines (121 loc) · 5.26 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System.IO;
using System.Linq;
using AElf.Contracts.Genesis;
using AElf.CrossChain;
using AElf.CrossChain.Grpc;
using AElf.CSharp.CodeOps;
using AElf.EconomicSystem;
using AElf.GovernmentSystem;
using AElf.Kernel;
using AElf.Kernel.Consensus.AEDPoS;
using AElf.Kernel.SmartContract;
using AElf.Kernel.SmartContract.ExecutionPluginForCallThreshold;
using AElf.Kernel.SmartContract.ExecutionPluginForMethodFee;
using AElf.Kernel.SmartContract.ExecutionPluginForResourceFee;
using AElf.Kernel.SmartContract.Parallel;
using AElf.Kernel.Token;
using AElf.Modularity;
using AElf.OpenTelemetry;
using AElf.OS;
using AElf.OS.Network.Grpc;
using AElf.OS.Node.Application;
using AElf.OS.Node.Domain;
using AElf.Runtime.CSharp;
using AElf.RuntimeSetup;
using AElf.WebApp.Application.Chain;
using AElf.WebApp.Web;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.AspNetCore;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace AElf.Blockchains.BasicBaseChain;
[DependsOn(
typeof(CrossChainAElfModule),
typeof(KernelAElfModule),
typeof(AEDPoSAElfModule),
typeof(TokenKernelAElfModule),
typeof(OSAElfModule),
typeof(AbpAspNetCoreModule),
typeof(CSharpRuntimeAElfModule),
typeof(CSharpCodeOpsAElfModule),
typeof(GrpcNetworkModule),
typeof(RuntimeSetupAElfModule),
typeof(GrpcCrossChainAElfModule),
typeof(GovernmentSystemAElfModule),
typeof(EconomicSystemAElfModule),
//web api module
typeof(WebWebAppAElfModule),
typeof(ParallelExecutionModule),
typeof(OpenTelemetryModule),
//plugin
typeof(ExecutionPluginForMethodFeeModule),
typeof(ExecutionPluginForResourceFeeModule),
typeof(ExecutionPluginForCallThresholdModule)
)]
public class BasicBaseChainAElfModule : AElfModule
{
public OsBlockchainNodeContext OsBlockchainNodeContext { get; set; }
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
var contentRootPath = hostingEnvironment.ContentRootPath;
var hostBuilderContext = context.Services.GetSingletonInstanceOrNull<HostBuilderContext>();
var chainType = configuration.GetValue("ChainType", ChainType.MainChain);
var netType = configuration.GetValue("NetType", NetType.MainNet);
var newConfig = new ConfigurationBuilder().AddConfiguration(configuration)
.AddJsonFile($"appsettings.{chainType}.{netType}.json")
.AddJsonFile($"appsettings.{hostingEnvironment.EnvironmentName}.json", true)
.SetBasePath(contentRootPath)
.Build();
hostBuilderContext.Configuration = newConfig;
Configure<EconomicOptions>(newConfig.GetSection("Economic"));
Configure<ChainOptions>(option =>
{
option.ChainId = ChainHelper.ConvertBase58ToChainId(newConfig["ChainId"]);
option.ChainType = chainType;
option.NetType = netType;
});
Configure<HostSmartContractBridgeContextOptions>(options =>
{
options.ContextVariables[ContextVariableDictionary.NativeSymbolName] =
newConfig.GetValue("Economic:Symbol", "ELF");
options.ContextVariables["SymbolListToPayTxFee"] =
newConfig.GetValue("Economic:SymbolListToPayTxFee", "WRITE,READ,STORAGE,TRAFFIC");
options.ContextVariables["SymbolListToPayRental"] =
newConfig.GetValue("Economic:SymbolListToPayRental", "CPU,RAM,DISK,NET");
});
Configure<ContractOptions>(newConfig.GetSection("Contract"));
Configure<ContractOptions>(options =>
{
options.GenesisContractDir = Path.Combine(contentRootPath, "genesis");
});
Configure<WebAppOptions>(newConfig.GetSection("WebApp"));
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var chainOptions = context.ServiceProvider.GetService<IOptionsSnapshot<ChainOptions>>().Value;
var dto = new OsBlockchainNodeContextStartDto
{
ChainId = chainOptions.ChainId,
ZeroSmartContract = typeof(BasicContractZero)
};
var dtoProvider = context.ServiceProvider.GetRequiredService<IGenesisSmartContractDtoProvider>();
dto.InitializationSmartContracts = dtoProvider.GetGenesisSmartContractDtos().ToList();
var contractOptions = context.ServiceProvider.GetService<IOptionsSnapshot<ContractOptions>>().Value;
dto.ContractDeploymentAuthorityRequired = contractOptions.ContractDeploymentAuthorityRequired;
var osService = context.ServiceProvider.GetService<IOsBlockchainNodeContextService>();
var that = this;
AsyncHelper.RunSync(async () => { that.OsBlockchainNodeContext = await osService.StartAsync(dto); });
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
var osService = context.ServiceProvider.GetService<IOsBlockchainNodeContextService>();
var that = this;
AsyncHelper.RunSync(() => osService.StopAsync(that.OsBlockchainNodeContext));
}
}