Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable plugin modules #3588

Merged
merged 13 commits into from
Jul 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
{
var contractCodes = GetContractCodes();
var deploymentList = ContractDeploymentListProvider.GetDeployContractNameList();
return ContractInitializationProviders
.Where(p => deploymentList.Contains(p.SystemSmartContractName))
.OrderBy(p => deploymentList.IndexOf(p.SystemSmartContractName))
.Select(p =>
return ContractInitializationProviders
.GroupBy(p => p.SystemSmartContractName)
.Where(g => deploymentList.Contains(g.Key))
.OrderBy(g => deploymentList.IndexOf(g.Key))
.Select(g =>

Check warning on line 32 in src/AElf.Blockchains.BasicBaseChain/GenesisSmartContractDtoProviderBase.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.Blockchains.BasicBaseChain/GenesisSmartContractDtoProviderBase.cs#L28-L32

Added lines #L28 - L32 were not covered by tests
{
var p = g.Last();

Check warning on line 34 in src/AElf.Blockchains.BasicBaseChain/GenesisSmartContractDtoProviderBase.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.Blockchains.BasicBaseChain/GenesisSmartContractDtoProviderBase.cs#L34

Added line #L34 was not covered by tests
var code = contractCodes[p.ContractCodeName];
var methodList = p.GetInitializeMethodList(code);
var genesisSmartContractDto = new GenesisSmartContractDto
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using AElf.Blockchains.BasicBaseChain;
using AElf.ContractDeployer;
using AElf.Kernel.Plugin.Application;
using AElf.Kernel.SmartContract;
using AElf.Kernel.SmartContract.Application;
using Microsoft.Extensions.Options;
Expand All @@ -12,19 +14,23 @@
/// </summary>
public class MainChainGenesisSmartContractDtoProvider : GenesisSmartContractDtoProviderBase
{
private readonly IEnumerable<IPluginContractProvider> _pluginContractProviders;
private readonly ContractOptions _contractOptions;

public MainChainGenesisSmartContractDtoProvider(IContractDeploymentListProvider contractDeploymentListProvider,
IEnumerable<IContractInitializationProvider> contractInitializationProviders,
IEnumerable<IPluginContractProvider> pluginContractProviders,
IOptionsSnapshot<ContractOptions> contractOptions)
: base(contractDeploymentListProvider, contractInitializationProviders)
{
_pluginContractProviders = pluginContractProviders;

Check warning on line 26 in src/AElf.Blockchains.MainChain/MainChainGenesisSmartContractDtoProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.Blockchains.MainChain/MainChainGenesisSmartContractDtoProvider.cs#L26

Added line #L26 was not covered by tests
_contractOptions = contractOptions.Value;
}

protected override IReadOnlyDictionary<string, byte[]> GetContractCodes()
{
return ContractsDeployer.GetContractCodes<MainChainGenesisSmartContractDtoProvider>(_contractOptions
.GenesisContractDir);
return ContractsDeployer.GetContractCodes<MainChainGenesisSmartContractDtoProvider>(
_contractOptions.GenesisContractDir,
pluginContractNames: _pluginContractProviders.Select(p => p.GetContractName()).ToList());

Check warning on line 34 in src/AElf.Blockchains.MainChain/MainChainGenesisSmartContractDtoProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.Blockchains.MainChain/MainChainGenesisSmartContractDtoProvider.cs#L32-L34

Added lines #L32 - L34 were not covered by tests
}
}
7 changes: 6 additions & 1 deletion src/AElf.ContractDeployer/ContractsDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
public static class ContractsDeployer
{
public static IReadOnlyDictionary<string, byte[]> GetContractCodes<T>(string contractDir = null,
bool isPatched = false)
bool isPatched = false, List<string> pluginContractNames = null)
{
var contractNames = GetContractNames(typeof(T).Assembly).ToList();
if (pluginContractNames is { Count: > 0 })
{
contractNames.AddRange(pluginContractNames);
}

Check warning on line 17 in src/AElf.ContractDeployer/ContractsDeployer.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.ContractDeployer/ContractsDeployer.cs#L15-L17

Added lines #L15 - L17 were not covered by tests

if (contractNames.Count == 0) throw new NoContractDllFoundInManifestException();

return contractNames.Select(n => (n, GetCode(n, contractDir, isPatched)))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AElf.Kernel.Plugin.Application;

public interface IPluginContractProvider
{
string GetContractName();
}
25 changes: 16 additions & 9 deletions src/AElf.Launcher/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using AElf.Blockchains.MainChain;
using AElf.Blockchains.SideChain;
Expand All @@ -9,7 +10,8 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
using Volo.Abp;
using Volo.Abp.Modularity.PlugIns;

namespace AElf.Launcher;

Expand All @@ -28,13 +30,23 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
var chainType = _configuration.GetValue("ChainType", ChainType.MainChain);
var pluginSourcesFolder = _configuration.GetValue("PluginSourcesFolder", Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"aelf", "plugins"));
Action<AbpApplicationCreationOptions> optionsAction = options =>
{
if (Directory.Exists(pluginSourcesFolder))
{
options.PlugInSources.AddFolder(pluginSourcesFolder);
}
};
switch (chainType)
{
case ChainType.SideChain:
AddApplication<SideChainAElfModule>(services);
services.AddApplication<SideChainAElfModule>(optionsAction);
break;
default:
AddApplication<MainChainAElfModule>(services);
case ChainType.MainChain:
services.AddApplication<MainChainAElfModule>(optionsAction);
break;
}

Expand All @@ -56,11 +68,6 @@ public void ConfigureServices(IServiceCollection services)
});
}

private static void AddApplication<T>(IServiceCollection services) where T : IAbpModule
{
services.AddApplication<T>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
// ReSharper disable once UnusedMember.Global
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
Loading