From bf382bcba85cfe0e1d1ecd61b6e32c81bd791114 Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 8 Jun 2022 16:57:29 +0800 Subject: [PATCH 01/21] Initial commit of new structure. --- all.sln | 7 + .../AEDPoSViewer/AEDPoSViewerHostedService.cs | 6 +- examples/AEDPoSViewer/AEDPoSViewerModule.cs | 3 + examples/AEDPoSViewer/AEDPoSViewerService.cs | 3 +- examples/AEDPoSViewer/appsettings.json | 6 +- examples/TokenManager/Program.cs | 41 +- examples/TokenManager/SyncTokenInfoOptions.cs | 7 + examples/TokenManager/TokenManager.csproj | 21 + .../TokenManager/TokenManagerConstants.cs | 7 + .../TokenManager/TokenManagerHostedService.cs | 43 ++ examples/TokenManager/TokenManagerModule.cs | 22 + examples/TokenManager/TokenManagerService.cs | 121 +++++ examples/TokenManager/TokenMangerOptions.cs | 6 + examples/TokenManager/appsettings.json | 56 ++ .../AElf.Client.Abp.TokenManager.csproj | 13 + .../AElfClientTokenManagerModule.cs | 17 + .../ITokenService.cs | 20 + src/AElf.Client.Abp.TokenManager/README.md | 4 + .../TokenManagerConstants.cs | 6 + .../TokenManagerOptions.cs | 6 + .../TokenService.Send.cs | 56 ++ .../TokenService.View.cs | 50 ++ src/AElf.Client.Abp/AElf.Client.Abp.csproj | 1 + src/AElf.Client.Abp/AElfClientAbpConstants.cs | 6 + src/AElf.Client.Abp/AElfClientModule.cs | 12 +- .../AElfClientService.Blockchain.cs | 32 ++ src/AElf.Client.Abp/AElfClientService.Send.cs | 44 ++ ...ntService.cs => AElfClientService.View.cs} | 16 +- src/AElf.Client.Abp/IAElfClientService.cs | 10 +- .../Options/AElfClientConfigOptions.cs | 7 + src/AElf.Client.Abp/Profile/CommonProfile.cs | 27 + .../Profile/MerklePathProfile.cs | 14 + .../Profile/TransactionProfile.cs | 71 +++ .../AElf.Client.Protobuf.csproj | 6 + .../Protobuf/nft_contract.proto | 505 ++++++++++++++++++ .../Protobuf/token_contract_impl.proto | 240 +++++++++ src/AElf.Client/AElf.Client.csproj | 2 +- src/AElf.Client/AElfClient.Client.cs | 440 ++++++++------- src/AElf.Client/AElfClient.cs | 2 +- src/AElf.Client/AElfClientConstants.cs | 8 +- src/AElf.Client/Dto/BlockDto.cs | 2 + src/AElf.Client/Dto/ChainStatusDto.cs | 24 +- src/AElf.Client/Dto/MerklePathDto.cs | 2 +- src/AElf.Client/Dto/TransactionResultDto.cs | 16 +- src/AElf.Client/Services/HttpService.cs | 11 +- test/AElf.Client.Test/ClientTest.cs | 4 +- 46 files changed, 1773 insertions(+), 250 deletions(-) create mode 100644 examples/TokenManager/SyncTokenInfoOptions.cs create mode 100644 examples/TokenManager/TokenManagerConstants.cs create mode 100644 examples/TokenManager/TokenManagerHostedService.cs create mode 100644 examples/TokenManager/TokenManagerModule.cs create mode 100644 examples/TokenManager/TokenManagerService.cs create mode 100644 examples/TokenManager/TokenMangerOptions.cs create mode 100644 examples/TokenManager/appsettings.json create mode 100644 src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj create mode 100644 src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs create mode 100644 src/AElf.Client.Abp.TokenManager/ITokenService.cs create mode 100644 src/AElf.Client.Abp.TokenManager/README.md create mode 100644 src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs create mode 100644 src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs create mode 100644 src/AElf.Client.Abp.TokenManager/TokenService.Send.cs create mode 100644 src/AElf.Client.Abp.TokenManager/TokenService.View.cs create mode 100644 src/AElf.Client.Abp/AElfClientAbpConstants.cs create mode 100644 src/AElf.Client.Abp/AElfClientService.Blockchain.cs create mode 100644 src/AElf.Client.Abp/AElfClientService.Send.cs rename src/AElf.Client.Abp/{AElfClientService.cs => AElfClientService.View.cs} (77%) create mode 100644 src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs create mode 100644 src/AElf.Client.Abp/Profile/CommonProfile.cs create mode 100644 src/AElf.Client.Abp/Profile/MerklePathProfile.cs create mode 100644 src/AElf.Client.Abp/Profile/TransactionProfile.cs create mode 100644 src/AElf.Client.Protobuf/Protobuf/nft_contract.proto create mode 100644 src/AElf.Client.Protobuf/Protobuf/token_contract_impl.proto diff --git a/all.sln b/all.sln index 3e3a5d1..7e26974 100644 --- a/all.sln +++ b/all.sln @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Test", "test\AE EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp", "src\AElf.Client.Abp\AElf.Client.Abp.csproj", "{BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TokenManager", "src\AElf.Client.Abp.TokenManager\AElf.Client.Abp.TokenManager.csproj", "{4E127996-AE35-4DCC-B4C0-057CB5B22A0E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,7 @@ Global {BE0E29FA-A9C6-4E03-9E0C-297CCF7C5729} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} {4D019C99-8B1C-42B0-8630-F1E3661F414B} = {7CD2B508-C765-4720-B430-94E79135797A} {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F} = {940361AC-2167-4D30-A4F6-9A543C608196} + {4E127996-AE35-4DCC-B4C0-057CB5B22A0E} = {940361AC-2167-4D30-A4F6-9A543C608196} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -63,5 +66,9 @@ Global {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}.Debug|Any CPU.Build.0 = Debug|Any CPU {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}.Release|Any CPU.ActiveCfg = Release|Any CPU {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}.Release|Any CPU.Build.0 = Release|Any CPU + {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/examples/AEDPoSViewer/AEDPoSViewerHostedService.cs b/examples/AEDPoSViewer/AEDPoSViewerHostedService.cs index bdb0b9c..c1f2491 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerHostedService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerHostedService.cs @@ -1,5 +1,3 @@ -using System.Threading; -using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -34,8 +32,8 @@ public async Task StartAsync(CancellationToken cancellationToken) await _abpApplication.InitializeAsync(); - var helloWorldService = _abpApplication.ServiceProvider.GetRequiredService(); - await helloWorldService.RunAsync(); + var viewerService = _abpApplication.ServiceProvider.GetRequiredService(); + await viewerService.RunAsync(); } public async Task StopAsync(CancellationToken cancellationToken) diff --git a/examples/AEDPoSViewer/AEDPoSViewerModule.cs b/examples/AEDPoSViewer/AEDPoSViewerModule.cs index 1bd743a..eabd86d 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerModule.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerModule.cs @@ -8,5 +8,8 @@ namespace AEDPoSViewer; )] public class AEDPoSViewerModule : AbpModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + } } \ No newline at end of file diff --git a/examples/AEDPoSViewer/AEDPoSViewerService.cs b/examples/AEDPoSViewer/AEDPoSViewerService.cs index 6dafa91..b678195 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerService.cs @@ -1,4 +1,5 @@ using AElf.Client; +using AElf.Client.Abp; using AElf.Contracts.Consensus.AEDPoS; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -29,7 +30,7 @@ public async Task RunAsync() var clientService = scope.ServiceProvider.GetRequiredService(); var result = await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, - "GetCurrentRoundInformation", new Empty(), EndpointType.MainNetSidechain.ToString(), "Ean"); + "GetCurrentRoundInformation", new Empty(), EndpointType.TestNetMainChain.ToString()); var round = new Round(); round.MergeFrom(result); diff --git a/examples/AEDPoSViewer/appsettings.json b/examples/AEDPoSViewer/appsettings.json index ec1136b..4c78fdb 100644 --- a/examples/AEDPoSViewer/appsettings.json +++ b/examples/AEDPoSViewer/appsettings.json @@ -17,7 +17,7 @@ } ] }, - "AElfAccount":{ + "AElfAccount": { "KeyDirectory": "", "AccountConfigList": [ { @@ -36,5 +36,9 @@ "PrivateKey": "5e2f12d13e4527ad1128e07db00f1614ec6b8b51662e68d4fdb42125ab384195", } ] + }, + "AElfClientConfig": { + "UseClientAlias": "TestNetMainChain", + "UseAccountAlias": "Ean" } } \ No newline at end of file diff --git a/examples/TokenManager/Program.cs b/examples/TokenManager/Program.cs index e5dff12..4d45858 100644 --- a/examples/TokenManager/Program.cs +++ b/examples/TokenManager/Program.cs @@ -1,3 +1,40 @@ -// See https://aka.ms/new-console-template for more information +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using Serilog.Events; +using TokenManager; -Console.WriteLine("Hello, World!"); \ No newline at end of file +Log.Logger = new LoggerConfiguration() + .MinimumLevel.Information() + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning) +#if DEBUG + .MinimumLevel.Override("AEDPoSViewer", LogEventLevel.Debug) +#else + .MinimumLevel.Override("AEDPoSViewer", LogEventLevel.Information) +#endif + .Enrich.FromLogContext() + .WriteTo.Async(c => c.File($"Logs/aelf-consensus-viewer-{DateTime.UtcNow:yyyy-MM-dd}.logs")) + .WriteTo.Async(c => c.Console()) + .CreateLogger(); + +try +{ + await Host.CreateDefaultBuilder(args) + .ConfigureServices(services => + { + services.AddHostedService(); + }) + .UseSerilog() + .RunConsoleAsync(); + return 0; +} +catch (Exception ex) +{ + Log.Fatal(ex, "Host terminated unexpectedly!"); + return 1; +} +finally +{ + Log.CloseAndFlush(); +} \ No newline at end of file diff --git a/examples/TokenManager/SyncTokenInfoOptions.cs b/examples/TokenManager/SyncTokenInfoOptions.cs new file mode 100644 index 0000000..aa22f70 --- /dev/null +++ b/examples/TokenManager/SyncTokenInfoOptions.cs @@ -0,0 +1,7 @@ +namespace TokenManager; + +public class SyncTokenInfoOptions +{ + public string CreateTransactionId { get; set; } + public string ValidateTokenInfoExistsTransactionId { get; set; } +} \ No newline at end of file diff --git a/examples/TokenManager/TokenManager.csproj b/examples/TokenManager/TokenManager.csproj index b9de063..0409bd7 100644 --- a/examples/TokenManager/TokenManager.csproj +++ b/examples/TokenManager/TokenManager.csproj @@ -7,4 +7,25 @@ enable + + + + + + + + + + + + + + + + + PreserveNewest + Always + + + diff --git a/examples/TokenManager/TokenManagerConstants.cs b/examples/TokenManager/TokenManagerConstants.cs new file mode 100644 index 0000000..bf2ab06 --- /dev/null +++ b/examples/TokenManager/TokenManagerConstants.cs @@ -0,0 +1,7 @@ +namespace TokenManager; + +public class TokenManagerConstants +{ + public const string TokenSmartContractName = "AElf.ContractNames.Token"; + public const string NativeTokenSymbol = "ELF"; +} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs new file mode 100644 index 0000000..544bcfc --- /dev/null +++ b/examples/TokenManager/TokenManagerHostedService.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using Volo.Abp; + +namespace TokenManager; + +public class TokenManagerHostedService : IHostedService +{ + private IAbpApplicationWithInternalServiceProvider _abpApplication; + + private readonly IConfiguration _configuration; + private readonly IHostEnvironment _hostEnvironment; + + public TokenManagerHostedService(IConfiguration configuration, IHostEnvironment hostEnvironment) + { + _configuration = configuration; + _hostEnvironment = hostEnvironment; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + _abpApplication = await AbpApplicationFactory.CreateAsync(options => + { + options.Services.ReplaceConfiguration(_configuration); + options.Services.AddSingleton(_hostEnvironment); + + options.UseAutofac(); + options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog()); + }); + + await _abpApplication.InitializeAsync(); + + var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); + await tokenManagerService.GetTokenInfoAsync(); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + await _abpApplication.ShutdownAsync(); + } +} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerModule.cs b/examples/TokenManager/TokenManagerModule.cs new file mode 100644 index 0000000..00f69fe --- /dev/null +++ b/examples/TokenManager/TokenManagerModule.cs @@ -0,0 +1,22 @@ +using AElf.Client.Abp; +using AElf.Client.Abp.TokenManager; +using AElf.Client.Options; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace TokenManager; + +[DependsOn( + typeof(AElfClientModule), + typeof(AElfClientTokenManagerModule) +)] +public class AEDPoSViewerModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(options => { configuration.GetSection("TokenManager").Bind(options); }); + Configure(options => { configuration.GetSection("SyncTokenInfo").Bind(options); }); + } +} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs new file mode 100644 index 0000000..014243d --- /dev/null +++ b/examples/TokenManager/TokenManagerService.cs @@ -0,0 +1,121 @@ +using AElf.Client; +using AElf.Client.Abp; +using AElf.Client.Abp.TokenManager; +using AElf.Client.Dto; +using AElf.Contracts.MultiToken; +using AElf.Contracts.NFT; +using AElf.Types; +using Google.Protobuf; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Serilog; +using Volo.Abp.DependencyInjection; +using Volo.Abp.ObjectMapping; + +namespace TokenManager; + +public class TokenManagerService : ITransientDependency +{ + private readonly ITokenService _tokenService; + private readonly IObjectMapper _objectMapper; + private readonly SyncTokenInfoOptions _syncTokenInfoOptions; + private IServiceScopeFactory ServiceScopeFactory { get; } + + public ILogger Logger { get; set; } + + public TokenManagerService(IServiceScopeFactory serviceScopeFactory, + ITokenService tokenService, + IObjectMapper objectMapper, + IOptionsSnapshot syncTokenInfoOptions) + { + _tokenService = tokenService; + _objectMapper = objectMapper; + _syncTokenInfoOptions = syncTokenInfoOptions.Value; + ServiceScopeFactory = serviceScopeFactory; + + Logger = NullLogger.Instance; + } + + public async Task GetTokenInfoAsync() + { + var tokenInfo = await _tokenService.GetTokenInfoAsync("ELF"); + Logger.LogInformation("{TokenInfo}", tokenInfo.ToString()); + } + + private async Task ValidateTokenInfoExistsAsync() + { + var client = new AElfClientBuilder().UsePublicEndpoint(EndpointType.TestNetMainChain).Build(); + var protocolCreateEvent = await GetNFTProtocolCreatedEventAsync(client); + + var validateTokenInfoExistsInput = new ValidateTokenInfoExistsInput + { + Symbol = protocolCreateEvent.Symbol, + TokenName = protocolCreateEvent.ProtocolName, + Decimals = 0, + IsBurnable = protocolCreateEvent.IsBurnable, + Issuer = protocolCreateEvent.Creator, + IssueChainId = protocolCreateEvent.IssueChainId, + TotalSupply = protocolCreateEvent.TotalSupply, + ExternalInfo = {protocolCreateEvent.Metadata.Value} + }; + + using var scope = ServiceScopeFactory.CreateScope(); + var clientService = scope.ServiceProvider.GetRequiredService(); + var txId = await clientService.SendSystemAsync(TokenManagerConstants.TokenSmartContractName, + "ValidateTokenInfoExists", validateTokenInfoExistsInput, EndpointType.TestNetMainChain.ToString(), + "eanz"); + Logger.LogInformation(txId); + var result = await client.GetTransactionResultAsync(txId); + Logger.LogInformation(result.Status); + Logger.LogInformation(result.Error); + } + + public async Task SyncTokenInfoAsync() + { + var client = new AElfClientBuilder().UsePublicEndpoint(EndpointType.TestNetMainChain).Build(); + var txId = _syncTokenInfoOptions.ValidateTokenInfoExistsTransactionId; + var txResult = await client.GetTransactionResultAsync(txId); + var merklePath = await client.GetMerklePathByTransactionIdAsync(txId); + + using var scope = ServiceScopeFactory.CreateScope(); + var clientService = scope.ServiceProvider.GetRequiredService(); + var tx = _objectMapper.Map(txResult.Transaction); + var crossChainCreateTokenInput = new CrossChainCreateTokenInput + { + FromChainId = AElfClientConstants.MainChainId, + MerklePath = new MerklePath + { + MerklePathNodes = + { + merklePath?.MerklePathNodes.Select(n => new MerklePathNode + { + Hash = Hash.LoadFromHex(n.Hash), + IsLeftChildNode = n.IsLeftChildNode + }) + } + }, + ParentChainHeight = txResult.BlockNumber, + TransactionBytes = tx.ToByteString() + }; + var resultTxId = await clientService.SendAsync("7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX", "CrossChainCreateToken", + crossChainCreateTokenInput, EndpointType.TestNetSidechain.ToString(), "eanz"); + + Logger.LogInformation(resultTxId); + var result = await client.GetTransactionResultAsync(resultTxId); + Logger.LogInformation(result.Status); + Logger.LogInformation(result.Error); + } + + private async Task GetNFTProtocolCreatedEventAsync(AElfClient client) + { + var transactionResultDto = await client.GetTransactionResultAsync(_syncTokenInfoOptions.CreateTransactionId); + var protocolCreated = new NFTProtocolCreated(); + var logEvent = ByteString.FromBase64(transactionResultDto.Logs.Single(l => l.Name == nameof(NFTProtocolCreated)) + .NonIndexed); + protocolCreated.MergeFrom(logEvent); + Logger.LogInformation(protocolCreated.ToString()); + return protocolCreated; + } +} \ No newline at end of file diff --git a/examples/TokenManager/TokenMangerOptions.cs b/examples/TokenManager/TokenMangerOptions.cs new file mode 100644 index 0000000..67da3ec --- /dev/null +++ b/examples/TokenManager/TokenMangerOptions.cs @@ -0,0 +1,6 @@ +namespace TokenManager; + +public class TokenManagerOptions +{ + public string NFTContractAddress { get; set; } +} \ No newline at end of file diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json new file mode 100644 index 0000000..fd5a9ad --- /dev/null +++ b/examples/TokenManager/appsettings.json @@ -0,0 +1,56 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "AElfClient": { + "ClientConfigList": [ + { + "Alias": "Example", + "Endpoint": "http://192.168.0.31:6800", + "UserName": "", + "Password": "", + "Timeout": 100 + } + ] + }, + "AElfAccount": { + "KeyDirectory": "", + "AccountConfigList": [ + { + "Alias": "Ean", + "PrivateKey": "8cc296e44d9e8881942e75a21ebc116ed3f29e39e0eaace1c92dc21e86d215c3", + "Address": "2AiXjNszZwUMdonm2RYb3GsB3aLUU3hkD1fxoazMwqPAamerLQ", + "Password": "aelftest" + }, + { + "Alias": "Test1", + "Address": "215tht8WyakoxNK4SvsR132jChydxE27RtJN8HSk1UXxuDQnmM", + "Password": "aelftest" + }, + { + "Alias": "Test2", + "PrivateKey": "5e2f12d13e4527ad1128e07db00f1614ec6b8b51662e68d4fdb42125ab384195", + }, + { + "Alias": "eanz", + "Address": "2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT", + "Password": "zhaoyiqi" + } + ] + }, + "TokenManager": { + "NFTContractAddress": "" + }, + "SyncTokenInfo": { + "CreateTransactionId": "c50498fdfa9213b7ffe6b39909514b3b0dc8d863511607944c337c8df9d72e06", + "ValidateTokenInfoExistsTransactionId": "145243e8d95702d698198d2e1b65dc88ca741cef9e8a0d2436682fc366e0cf17" + }, + "AElfClientConfig": { + "UseClientAlias": "TestNetSidechain", + "UseAccountAlias": "Ean" + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj b/src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj new file mode 100644 index 0000000..a49c765 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs b/src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs new file mode 100644 index 0000000..fe33352 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace AElf.Client.Abp.TokenManager; + +[DependsOn( + typeof(AElfClientModule) +)] +public class AElfClientTokenManagerModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(options => { configuration.GetSection("TokenManager").Bind(options); }); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/ITokenService.cs b/src/AElf.Client.Abp.TokenManager/ITokenService.cs new file mode 100644 index 0000000..aacd2a5 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/ITokenService.cs @@ -0,0 +1,20 @@ +using AElf.Contracts.MultiToken; +using AElf.Contracts.NFT; +using AElf.Types; +using CreateInput = AElf.Contracts.MultiToken.CreateInput; +using GetAllowanceOutput = AElf.Contracts.MultiToken.GetAllowanceOutput; +using GetBalanceOutput = AElf.Contracts.MultiToken.GetBalanceOutput; + +namespace AElf.Client.Abp.TokenManager; + +public interface ITokenService +{ + Task CreateTokenAsync(CreateInput createInput); + Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput); + Task MintNFTAsync(MintInput mintInput); + Task SyncTokenInfoAsync(string symbol); + + Task GetTokenInfoAsync(string symbol); + Task GetTokenBalanceAsync(string symbol, Address owner); + Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/README.md b/src/AElf.Client.Abp.TokenManager/README.md new file mode 100644 index 0000000..a7c2a45 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/README.md @@ -0,0 +1,4 @@ +# AElf Client TokenManager +Some useful methods to interact with: +- [AElf MultiToken Contract](https://github.com/AElfProject/AElf/tree/dev/contract/AElf.Contracts.MultiToken) +- [AElf NFT Contract](https://github.com/AElfProject/AElf/tree/dev/contract/AElf.Contracts.NFT) diff --git a/src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs b/src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs new file mode 100644 index 0000000..c273150 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.TokenManager; + +public class TokenManagerConstants +{ + public const string TokenSmartContractName = "AElf.ContractNames.Token"; +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs b/src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs new file mode 100644 index 0000000..4be0371 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.TokenManager; + +public class TokenManagerOptions +{ + public string NFTContractAddress { get; set; } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/TokenService.Send.cs b/src/AElf.Client.Abp.TokenManager/TokenService.Send.cs new file mode 100644 index 0000000..e44a495 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/TokenService.Send.cs @@ -0,0 +1,56 @@ +using AElf.Client.Options; +using AElf.Contracts.NFT; +using AElf.Types; +using Google.Protobuf; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using CreateInput = AElf.Contracts.MultiToken.CreateInput; + +namespace AElf.Client.Abp.TokenManager; + +public partial class TokenService : ITokenService, ITransientDependency +{ + private readonly IAElfClientService _clientService; + private readonly TokenManagerOptions _tokenManagerOptions; + private readonly AElfClientConfigOptions _clientConfigOptions; + + public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions, + IOptionsSnapshot tokenManagerOptions) + { + _clientService = clientService; + _tokenManagerOptions = tokenManagerOptions.Value; + _clientConfigOptions = clientConfigOptions.Value; + } + + public async Task CreateTokenAsync(CreateInput createInput) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var txId = await _clientService.SendSystemAsync(TokenManagerConstants.TokenSmartContractName, "Create", createInput, + useClientAlias); + var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); + return txResult; + } + + public async Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var txId = await _clientService.SendAsync(_tokenManagerOptions.NFTContractAddress, "Create", createInput, + useClientAlias); + var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); + return txResult; + } + + public async Task MintNFTAsync(MintInput mintInput) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var txId = await _clientService.SendAsync(_tokenManagerOptions.NFTContractAddress, "Mint", mintInput, + useClientAlias); + var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); + return txResult; + } + + public async Task SyncTokenInfoAsync(string symbol) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/TokenService.View.cs b/src/AElf.Client.Abp.TokenManager/TokenService.View.cs new file mode 100644 index 0000000..09dc600 --- /dev/null +++ b/src/AElf.Client.Abp.TokenManager/TokenService.View.cs @@ -0,0 +1,50 @@ +using AElf.Contracts.MultiToken; +using AElf.Types; +using Google.Protobuf; + +namespace AElf.Client.Abp.TokenManager; + +public partial class TokenService +{ + public async Task GetTokenInfoAsync(string symbol) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var result = await _clientService.ViewSystemAsync(TokenManagerConstants.TokenSmartContractName, "GetTokenInfo", + new GetTokenInfoInput + { + Symbol = symbol + }, useClientAlias); + var tokenInfo = new TokenInfo(); + tokenInfo.MergeFrom(result); + return tokenInfo; + } + + public async Task GetTokenBalanceAsync(string symbol, Address owner) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var result = await _clientService.ViewSystemAsync(TokenManagerConstants.TokenSmartContractName, "GetBalance", + new GetBalanceInput + { + Owner = owner, + Symbol = symbol + }, useClientAlias); + var balance = new GetBalanceOutput(); + balance.MergeFrom(result); + return balance; + } + + public async Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var result = await _clientService.ViewSystemAsync(TokenManagerConstants.TokenSmartContractName, "GetAllowance", + new GetAllowanceInput + { + Owner = owner, + Spender = spender, + Symbol = symbol + }, useClientAlias); + var allowance = new GetAllowanceOutput(); + allowance.MergeFrom(result); + return allowance; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElf.Client.Abp.csproj b/src/AElf.Client.Abp/AElf.Client.Abp.csproj index 2f6815f..7f59710 100644 --- a/src/AElf.Client.Abp/AElf.Client.Abp.csproj +++ b/src/AElf.Client.Abp/AElf.Client.Abp.csproj @@ -12,6 +12,7 @@ + diff --git a/src/AElf.Client.Abp/AElfClientAbpConstants.cs b/src/AElf.Client.Abp/AElfClientAbpConstants.cs new file mode 100644 index 0000000..b8ba12d --- /dev/null +++ b/src/AElf.Client.Abp/AElfClientAbpConstants.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp; + +public class AElfClientAbpConstants +{ + public const int DefaultWaitMilliseconds = 100; +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientModule.cs b/src/AElf.Client.Abp/AElfClientModule.cs index 95cfe53..6b83d19 100644 --- a/src/AElf.Client.Abp/AElfClientModule.cs +++ b/src/AElf.Client.Abp/AElfClientModule.cs @@ -2,12 +2,14 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Autofac; +using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; namespace AElf.Client.Abp; [DependsOn( - typeof(AbpAutofacModule) + typeof(AbpAutofacModule), + typeof(AbpAutoMapperModule) )] public class AElfClientModule : AbpModule { @@ -16,5 +18,13 @@ public override void ConfigureServices(ServiceConfigurationContext context) var configuration = context.Services.GetConfiguration(); Configure(options => { configuration.GetSection("AElfClient").Bind(options); }); Configure(options => { configuration.GetSection("AElfAccount").Bind(options); }); + Configure(options => { configuration.GetSection("AElfClientConfig").Bind(options); }); + + context.Services.AddAutoMapperObjectMapper(); + + Configure(options => + { + options.AddMaps(); + }); } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientService.Blockchain.cs b/src/AElf.Client.Abp/AElfClientService.Blockchain.cs new file mode 100644 index 0000000..7042a90 --- /dev/null +++ b/src/AElf.Client.Abp/AElfClientService.Blockchain.cs @@ -0,0 +1,32 @@ +using AElf.Client.Dto; + +namespace AElf.Client.Abp; + +public partial class AElfClientService +{ + public async Task GetTransactionResultAsync(string transactionId, string clientAlias) + { + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); + var result = await aelfClient.GetTransactionResultAsync(transactionId); + var i = 0; + while (i < 10) + { + if (result!.Status == TransactionResultStatus.Mined.ToString().ToUpper()) + { + break; + } + + if (result.Status == TransactionResultStatus.Failed.ToString().ToUpper() || + result.Status == TransactionResultStatus.NodeValidationFailed.ToString().ToUpper()) + { + break; + } + + await Task.Delay(AElfClientAbpConstants.DefaultWaitMilliseconds); + result = await aelfClient.GetTransactionResultAsync(transactionId); + i++; + } + + return _objectMapper.Map(result!); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientService.Send.cs b/src/AElf.Client.Abp/AElfClientService.Send.cs new file mode 100644 index 0000000..b06001e --- /dev/null +++ b/src/AElf.Client.Abp/AElfClientService.Send.cs @@ -0,0 +1,44 @@ +using AElf.Client.Dto; +using Google.Protobuf; + +namespace AElf.Client.Abp; + +public partial class AElfClientService +{ + public async Task SendAsync(string contractAddress, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default") + { + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); + var tx = new TransactionBuilder(aelfClient) + .UsePrivateKey(aelfAccount) + .UseContract(contractAddress) + .UseMethod(methodName) + .UseParameter(parameter) + .Build(); + return await PerformSendAsync(aelfClient, tx); + } + + public async Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default") + { + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); + var tx = new TransactionBuilder(aelfClient) + .UsePrivateKey(aelfAccount) + .UseSystemContract(systemContractName) + .UseMethod(methodName) + .UseParameter(parameter) + .Build(); + return await PerformSendAsync(aelfClient, tx); + } + + private static async Task PerformSendAsync(AElfClient aelfClient, Transaction tx) + { + var result = await aelfClient.SendTransactionAsync(new SendTransactionInput + { + RawTransaction = tx.ToByteArray().ToHex() + }); + return result.TransactionId; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientService.cs b/src/AElf.Client.Abp/AElfClientService.View.cs similarity index 77% rename from src/AElf.Client.Abp/AElfClientService.cs rename to src/AElf.Client.Abp/AElfClientService.View.cs index 734cbb7..185f9ce 100644 --- a/src/AElf.Client.Abp/AElfClientService.cs +++ b/src/AElf.Client.Abp/AElfClientService.View.cs @@ -1,22 +1,26 @@ using AElf.Client.Dto; using Google.Protobuf; using Volo.Abp.DependencyInjection; +using Volo.Abp.ObjectMapping; namespace AElf.Client.Abp; -public class AElfClientService : IAElfClientService, ITransientDependency +public partial class AElfClientService : IAElfClientService, ITransientDependency { private readonly IAElfClientProvider _aelfClientProvider; private readonly IAElfAccountProvider _aelfAccountProvider; + private readonly IObjectMapper _objectMapper; - public AElfClientService(IAElfClientProvider aelfClientProvider, IAElfAccountProvider aelfAccountProvider) + public AElfClientService(IAElfClientProvider aelfClientProvider, IAElfAccountProvider aelfAccountProvider, + IObjectMapper objectMapper) { _aelfClientProvider = aelfClientProvider; _aelfAccountProvider = aelfAccountProvider; + _objectMapper = objectMapper; } - public async Task ViewAsync(string contractAddress, string methodName, IMessage parameter, string clientAlias, - string accountAlias = "Default") + public async Task ViewAsync(string contractAddress, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default") { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); @@ -29,8 +33,8 @@ public async Task ViewAsync(string contractAddress, string methodName, I return await PerformViewAsync(aelfClient, tx); } - public async Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, string clientAlias, - string accountAlias = "Default") + public async Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default") { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); var privateKey = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); diff --git a/src/AElf.Client.Abp/IAElfClientService.cs b/src/AElf.Client.Abp/IAElfClientService.cs index 3d126f5..04400f5 100644 --- a/src/AElf.Client.Abp/IAElfClientService.cs +++ b/src/AElf.Client.Abp/IAElfClientService.cs @@ -1,6 +1,6 @@ using Google.Protobuf; -namespace AElf.Client; +namespace AElf.Client.Abp; public interface IAElfClientService { @@ -9,4 +9,12 @@ Task ViewAsync(string contractAddress, string methodName, IMessage param Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, string clientAlias, string accountAlias = "Default"); + + Task SendAsync(string contractAddress, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default"); + + Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default"); + + Task GetTransactionResultAsync(string transactionId, string clientAlias); } \ No newline at end of file diff --git a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs b/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs new file mode 100644 index 0000000..9c00c0e --- /dev/null +++ b/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs @@ -0,0 +1,7 @@ +namespace AElf.Client.Options; + +public class AElfClientConfigOptions +{ + public string UseClientAlias { get; set; } + public string UseAccountAlias { get; set; } = "Default"; +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/Profile/CommonProfile.cs b/src/AElf.Client.Abp/Profile/CommonProfile.cs new file mode 100644 index 0000000..e025ada --- /dev/null +++ b/src/AElf.Client.Abp/Profile/CommonProfile.cs @@ -0,0 +1,27 @@ +using Google.Protobuf; + +namespace AElf.Client.Abp; + +public class CommonProfile : AutoMapper.Profile +{ + public CommonProfile() + { + CreateMap() + .ConvertUsing(s => s == null ? null : s.ToHex()); + + CreateMap() + .ConvertUsing(s => Hash.LoadFromHex(s)); + + CreateMap() + .ConvertUsing(s => s.ToBase58()); + + CreateMap() + .ConvertUsing(s => Address.FromBase58(s)); + + CreateMap() + .ConvertUsing(s => s.ToBase64()); + + CreateMap() + .ConvertUsing(s => ByteString.CopyFromUtf8(s)); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/Profile/MerklePathProfile.cs b/src/AElf.Client.Abp/Profile/MerklePathProfile.cs new file mode 100644 index 0000000..d8b2a75 --- /dev/null +++ b/src/AElf.Client.Abp/Profile/MerklePathProfile.cs @@ -0,0 +1,14 @@ +using AElf.Client.Dto; +using AutoMapper; + +namespace AElf.Client.Abp; + +public class MerklePathProfile : Profile +{ + public MerklePathProfile() + { + CreateMap(); + + CreateMap(); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/Profile/TransactionProfile.cs b/src/AElf.Client.Abp/Profile/TransactionProfile.cs new file mode 100644 index 0000000..fce5de8 --- /dev/null +++ b/src/AElf.Client.Abp/Profile/TransactionProfile.cs @@ -0,0 +1,71 @@ +using AElf.Client.Dto; +using AutoMapper; +using Google.Protobuf; +using Volo.Abp.AutoMapper; + +namespace AElf.Client.Abp; + +public class TransactionProfile : Profile +{ + public const string ErrorTrace = "WithMetrics"; + + public TransactionProfile() + { + CreateMap(); + CreateMap(); + + CreateMap() + .ForMember(d => d.ReturnValue, opt => opt.MapFrom(s => s.ReturnValue.ToHex(false))) + .ForMember(d => d.Bloom, + opt => opt.MapFrom(s => + s.Status == TransactionResultStatus.NotExisted + ? null + : s.Bloom.Length == 0 + ? ByteString.CopyFrom(new byte[256]).ToBase64() + : s.Bloom.ToBase64())) + .ForMember(d => d.Status, opt => opt.MapFrom(s => s.Status.ToString().ToUpper())) + .ForMember(d => d.Error, opt => opt.MapFrom()) + .Ignore(d => d.Transaction) + .Ignore(d => d.TransactionSize); + + TransactionResultStatus status; + CreateMap() + .ForMember(d => d.ReturnValue, + opt => opt.MapFrom(s => ByteString.CopyFrom(ByteArrayHelper.HexStringToByteArray(s.ReturnValue)))) + .ForMember(d => d.Bloom, opt => opt.MapFrom(s => + s.Status.ToUpper() == TransactionResultStatus.NotExisted.ToString().ToUpper() + ? null + : string.IsNullOrEmpty(s.Bloom) + ? ByteString.Empty + : ByteString.FromBase64(s.Bloom))) + .ForMember(d => d.Status, + opt => opt.MapFrom(s => + Enum.TryParse(s.Status, out status) + ? status + : TransactionResultStatus.NotExisted)); + + CreateMap(); + } +} + +public class TransactionErrorResolver : IValueResolver +{ + public string Resolve(TransactionResult source, TransactionResultDto destination, string destMember, + ResolutionContext context) + { + var errorTraceNeeded = (bool)context.Items[TransactionProfile.ErrorTrace]; + return TakeErrorMessage(source.Error, errorTraceNeeded); + } + + public static string TakeErrorMessage(string transactionResultError, bool errorTraceNeeded) + { + if (string.IsNullOrWhiteSpace(transactionResultError)) + return null; + + if (errorTraceNeeded) + return transactionResultError; + + using var stringReader = new StringReader(transactionResultError); + return stringReader.ReadLine(); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj index a582f80..977fcda 100644 --- a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj +++ b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj @@ -35,12 +35,18 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile MSBuild:Compile + + MSBuild:Compile + diff --git a/src/AElf.Client.Protobuf/Protobuf/nft_contract.proto b/src/AElf.Client.Protobuf/Protobuf/nft_contract.proto new file mode 100644 index 0000000..b3521f6 --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/nft_contract.proto @@ -0,0 +1,505 @@ +/** + * NFT contract. + */ +syntax = "proto3"; + +package nft; + +import "aelf/core.proto"; +import "aelf/options.proto"; +import "acs1.proto"; +import "transaction_fee.proto"; +import "authority_info.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; + +option csharp_namespace = "AElf.Contracts.NFT"; + +service NFTContract { + option (aelf.csharp_state) = "AElf.Contracts.NFT.NFTContractState"; + option (aelf.base) = "acs1.proto"; + + // Create a new nft protocol. + rpc Create (CreateInput) returns (google.protobuf.StringValue) { + } + rpc CrossChainCreate (CrossChainCreateInput) returns (google.protobuf.Empty) { + } + // Mint (Issue) an amount of nft. + rpc Mint (MintInput) returns (aelf.Hash) { + } + // Transfer nft to another address. + rpc Transfer (TransferInput) returns (google.protobuf.Empty) { + } + // Transfer nft from one address to another. + rpc TransferFrom (TransferFromInput) returns (google.protobuf.Empty) { + } + // Approve another address to transfer nft from own account. + rpc Approve (ApproveInput) returns (google.protobuf.Empty) { + } + // De-approve. + rpc UnApprove (UnApproveInput) returns (google.protobuf.Empty) { + } + // Approve or de-approve another address as the operator of all NFTs of a certain protocol. + rpc ApproveProtocol (ApproveProtocolInput) returns (google.protobuf.Empty) { + } + // Destroy nfts. + rpc Burn (BurnInput) returns (google.protobuf.Empty) { + } + // Lock several nfts and fts to mint one nft. + rpc Assemble (AssembleInput) returns (aelf.Hash) { + } + // Disassemble one assembled nft to get locked nfts and fts back. + rpc Disassemble (DisassembleInput) returns (google.protobuf.Empty) { + } + // Modify metadata of one nft. + rpc Recast (RecastInput) returns (google.protobuf.Empty) { + } + + rpc AddMinters (AddMintersInput) returns (google.protobuf.Empty) { + } + rpc RemoveMinters (RemoveMintersInput) returns (google.protobuf.Empty) { + } + + rpc AddNFTType (AddNFTTypeInput) returns (google.protobuf.Empty) { + } + rpc RemoveNFTType (google.protobuf.StringValue) returns (google.protobuf.Empty) { + } + + rpc GetNFTProtocolInfo (google.protobuf.StringValue) returns (NFTProtocolInfo) { + option (aelf.is_view) = true; + } + rpc GetNFTInfo (GetNFTInfoInput) returns (NFTInfo) { + option (aelf.is_view) = true; + } + rpc GetNFTInfoByTokenHash (aelf.Hash) returns (NFTInfo) { + option (aelf.is_view) = true; + } + rpc GetBalance (GetBalanceInput) returns (GetBalanceOutput) { + option (aelf.is_view) = true; + } + rpc GetBalanceByTokenHash (GetBalanceByTokenHashInput) returns (GetBalanceOutput) { + option (aelf.is_view) = true; + } + rpc GetAllowance (GetAllowanceInput) returns (GetAllowanceOutput) { + option (aelf.is_view) = true; + } + rpc GetAllowanceByTokenHash (GetAllowanceByTokenHashInput) returns (GetAllowanceOutput) { + option (aelf.is_view) = true; + } + rpc GetMinterList (google.protobuf.StringValue) returns (MinterList) { + option (aelf.is_view) = true; + } + rpc CalculateTokenHash (CalculateTokenHashInput) returns (aelf.Hash) { + option (aelf.is_view) = true; + } + rpc GetNFTTypes (google.protobuf.Empty) returns (NFTTypes) { + option (aelf.is_view) = true; + } + rpc GetOperatorList (GetOperatorListInput) returns (AddressList) { + option (aelf.is_view) = true; + } +} + +// Structs +message NFTTypes { + map value = 1; +} + +// Inputs +message CreateInput { + // The type of this nft protocol. + string nft_type = 1; + // The name of this nft protocol. + string protocol_name = 2; + // The total supply of the token. + int64 total_supply = 3; + // The address that created the token. + aelf.Address creator = 4; + // A flag indicating if this token is burnable. + bool is_burnable = 5; + // The chain id of the token. + int32 issue_chain_id = 6; + // The metadata of the token. + Metadata metadata = 7; + // Base Uri. + string base_uri = 8; + // Is token id can be reused. + bool is_token_id_reuse = 9; + // Initial minter list (creator will be added automatically) + MinterList minter_list = 10; +} + +message CrossChainCreateInput { + string symbol = 1; +} + +message TransferInput { + aelf.Address to = 1; + string symbol = 2; + int64 token_id = 3; + string memo = 4; + int64 amount = 5; +} + +message TransferFromInput { + aelf.Address from = 1; + aelf.Address to = 2; + string symbol = 3; + int64 token_id = 4; + string memo = 5; + int64 amount = 6; +} + +message ApproveInput { + aelf.Address spender = 1; + string symbol = 2; + int64 token_id = 3; + int64 amount = 4; +} + +message UnApproveInput { + aelf.Address spender = 1; + string symbol = 2; + int64 token_id = 3; + int64 amount = 4; +} + +message ApproveProtocolInput { + aelf.Address operator = 1; + string symbol = 2; + bool approved = 3; +} + +message AddressList { + repeated aelf.Address value = 1; +} + +message GetOperatorListInput { + string symbol = 1; + aelf.Address owner = 2; +} + +message BurnInput { + string symbol = 1; + int64 token_id = 2; + int64 amount = 3; +} + +message AssembleInput { + string symbol = 1; + aelf.Address owner = 2; + string uri = 3; + string alias = 4; + Metadata metadata = 5; + AssembledNfts assembled_nfts = 6; + AssembledFts assembled_fts = 7; + int64 token_id = 8; +} + +message DisassembleInput { + string symbol = 1; + int64 token_id = 2; + aelf.Address owner = 3; +} + +message MinterList { + repeated aelf.Address value = 1; +} + +message MintInput { + string symbol = 1; + aelf.Address owner = 2; + string uri = 3; + string alias = 4; + Metadata metadata = 5; + int64 quantity = 6; + int64 token_id = 7; +} + +message GetBalanceInput { + aelf.Address owner = 1; + string symbol = 2; + int64 token_id = 3; +} + +message GetBalanceByTokenHashInput { + aelf.Address owner = 1; + aelf.Hash token_hash = 2; +} + +message GetBalanceOutput { + aelf.Address owner = 1; + aelf.Hash token_hash = 2; + int64 balance = 3; +} + +message GetAllowanceInput { + string symbol = 1; + int64 token_id = 2; + aelf.Address owner = 3; + aelf.Address spender = 4; +} + +message GetAllowanceByTokenHashInput { + aelf.Hash token_hash = 1; + aelf.Address owner = 2; + aelf.Address spender = 3; +} + +message GetAllowanceOutput { + aelf.Hash token_hash = 1; + int64 allowance = 2; + aelf.Address owner = 3; + aelf.Address spender = 4; +} + +message CalculateTokenHashInput { + string symbol = 1; + int64 token_id = 2; +} + +message NFTProtocolInfo { + // The symbol of the token. + string symbol = 1; + // The minted number of the token. + int64 supply = 2; + // The total number of the token. + int64 total_supply = 3; + // The address that creat the token. + aelf.Address creator = 4; + // Base Uri. + string base_uri = 5; + // A flag indicating if this token is burnable. + bool is_burnable = 6; + // The chain to mint this token. + int32 issue_chain_id = 7; + // The metadata of the token. + Metadata metadata = 8; + // NFT Type. + string nft_type = 9; + // Protocol name, aka token name in MultiToken Contract. + string protocol_name = 10; + // Is token id can be reused. + bool is_token_id_reuse = 11; + int64 issued = 12; +} + +message NFTInfo { + // The symbol of the protocol this nft belongs to. + string symbol = 1; + // The name of the protocol this nft belongs to. + string protocol_name = 2; + // Actually is the order of this token. + int64 token_id = 3; + // The address that creat the base token. + aelf.Address creator = 4; + // The addresses that mint this token. + repeated aelf.Address minters = 5; + // The metadata of the token. + Metadata metadata = 6; + // Minted amount. + int64 quantity = 7; + // Token Uri. + string uri = 8; + // Base Uri. + string base_uri = 9; + // Alias + string alias = 10; + // Is burned. + bool is_burned = 11; + // NFT Type + string nft_type = 12; +} + +enum NFTType { + ANY = 0; + ART = 1; + MUSIC = 2; + DOMAIN_NAMES = 3; + VIRTUAL_WORLDS = 4; + TRADING_CARDS = 5; + COLLECTABLES = 6; + SPORTS = 7; + UTILITY = 8; + BADGES = 9; +} + +message Metadata { + map value = 1; +} + +message AddMintersInput { + MinterList minter_list = 1; + string symbol = 2; +} + +message RemoveMintersInput { + MinterList minter_list = 1; + string symbol = 2; +} + +message GetNFTInfoInput { + string symbol = 1; + int64 token_id = 2; +} + +message RecastInput { + string symbol = 1; + int64 token_id = 2; + string uri = 3; + string alias = 4; + Metadata metadata = 5; +} + +message AssembledNfts { + map value = 1; +} + +message AssembledFts { + map value = 1; +} + +message AddNFTTypeInput { + string full_name = 1; + string short_name = 2; +} + +// Events + +message NFTProtocolCreated { + option (aelf.is_event) = true; + // The symbol of this protocol. + string symbol = 1; + // The name of this protocol. + string protocol_name = 2; + // The total supply of the token. + int64 total_supply = 3; + // The address that created the token. + aelf.Address creator = 4; + // A flag indicating if this token is burnable. + bool is_burnable = 5; + // The chain id of the token. + int32 issue_chain_id = 6; + // The metadata of the token. + Metadata metadata = 7; + // Base Uri. + string base_uri = 8; + // Is token id can be reused. + bool is_token_id_reuse = 9; + string nft_type = 10; +} + +message NFTMinted { + option (aelf.is_event) = true; + // The symbol of this protocol. + string symbol = 1; + // The name of this protocol. + string protocol_name = 2; + // Actually is the order of this token. + int64 token_id = 3; + // The address that creat the base token. + aelf.Address creator = 4; + // The address that mint this token. + aelf.Address minter = 5; + // The metadata of the token. + Metadata metadata = 6; + // The current owner of this nft. + aelf.Address owner = 7; + // Token Uri. + string uri = 8; + // Base Uri. + string base_uri = 9; + // Alias + string alias = 10; + // NFT Type + string nft_type = 11; + // Quantity + int64 quantity = 12; + int64 total_quantity = 13; + aelf.Hash token_hash = 14; +} + +message Transferred { + option (aelf.is_event) = true; + aelf.Address from = 1 [(aelf.is_indexed) = true]; + aelf.Address to = 2 [(aelf.is_indexed) = true]; + string symbol = 3 [(aelf.is_indexed) = true]; + int64 token_id = 4 [(aelf.is_indexed) = true]; + int64 amount = 5; + string memo = 6; +} + +message Approved { + option (aelf.is_event) = true; + aelf.Address owner = 1 [(aelf.is_indexed) = true]; + aelf.Address spender = 2 [(aelf.is_indexed) = true]; + string symbol = 3 [(aelf.is_indexed) = true]; + int64 token_id = 4 [(aelf.is_indexed) = true]; + int64 amount = 5; +} + +message UnApproved { + option (aelf.is_event) = true; + aelf.Address owner = 1 [(aelf.is_indexed) = true]; + aelf.Address spender = 2 [(aelf.is_indexed) = true]; + string symbol = 3 [(aelf.is_indexed) = true]; + int64 token_id = 4 [(aelf.is_indexed) = true]; + int64 current_allowance = 5; +} + +message Burned { + option (aelf.is_event) = true; + aelf.Address burner = 1 [(aelf.is_indexed) = true]; + string symbol = 2 [(aelf.is_indexed) = true]; + int64 token_id = 3 [(aelf.is_indexed) = true]; + int64 amount = 4; +} + +message Recasted { + option (aelf.is_event) = true; + string symbol = 1 [(aelf.is_indexed) = true]; + int64 token_id = 2 [(aelf.is_indexed) = true]; + Metadata old_metadata = 3 [(aelf.is_indexed) = true]; + Metadata new_metadata = 4 [(aelf.is_indexed) = true]; + string alias = 5 [(aelf.is_indexed) = true]; + string uri = 6 [(aelf.is_indexed) = true]; +} + +message Assembled { + option (aelf.is_event) = true; + string symbol = 1 [(aelf.is_indexed) = true]; + int64 token_id = 2 [(aelf.is_indexed) = true]; + AssembledNfts assembled_nfts = 3 [(aelf.is_indexed) = true]; + AssembledFts assembled_fts = 4 [(aelf.is_indexed) = true]; +} + +message Disassembled { + option (aelf.is_event) = true; + string symbol = 1 [(aelf.is_indexed) = true]; + int64 token_id = 2 [(aelf.is_indexed) = true]; + AssembledNfts disassembled_nfts = 3 [(aelf.is_indexed) = true]; + AssembledFts disassembled_fts = 4 [(aelf.is_indexed) = true]; +} + +message NFTTypeAdded { + option (aelf.is_event) = true; + string full_name = 1; + string short_name = 2; +} + +message NFTTypeRemoved { + option (aelf.is_event) = true; + string short_name = 1; +} + +message MinterListAdded { + option (aelf.is_event) = true; + MinterList minter_list = 1; + string symbol = 2; +} + +message MinterListRemoved { + option (aelf.is_event) = true; + MinterList minter_list = 1; + string symbol = 2; +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/Protobuf/token_contract_impl.proto b/src/AElf.Client.Protobuf/Protobuf/token_contract_impl.proto new file mode 100644 index 0000000..cfc91fc --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/token_contract_impl.proto @@ -0,0 +1,240 @@ +/** + * MultiToken contract. + * + * The MultiToken contract is mainly used to manage the user's account and transaction fees related Settings. + * + * Implement AElf Standards ACS1 and ACS2. + */ +syntax = "proto3"; + +package tokenimpl; + +import "aelf/core.proto"; +import "acs1.proto"; +import "acs2.proto"; +import "token_contract.proto"; +// Because implementation uses this proto file. +import "transaction_fee.proto"; +import "authority_info.proto"; + +option csharp_namespace = "AElf.Contracts.MultiToken"; + +service TokenContractImpl { + option (aelf.csharp_state) = "AElf.Contracts.MultiToken.TokenContractState"; + option (aelf.base) = "acs1.proto"; + option (aelf.base) = "acs2.proto"; + option (aelf.base) = "token_contract.proto"; + + // Transfer resource tokens to designated contract address. + rpc AdvanceResourceToken (AdvanceResourceTokenInput) returns (google.protobuf.Empty) { + } + + // Take token from contract address. + rpc TakeResourceTokenBack (TakeResourceTokenBackInput) returns (google.protobuf.Empty) { + } + + // Register the token contract address for cross chain. + rpc RegisterCrossChainTokenContractAddress (RegisterCrossChainTokenContractAddressInput) returns (google.protobuf.Empty) { + } + + // Set the receiver address of the side chain transaction fee. + rpc SetFeeReceiver (aelf.Address) returns (google.protobuf.Empty) { + } + + // Validates if the token exist. + rpc ValidateTokenInfoExists(ValidateTokenInfoExistsInput) returns (google.protobuf.Empty){ + } + + // Update the rental unit price of the side chain. + rpc UpdateRental (UpdateRentalInput) returns (google.protobuf.Empty) { + } + + // Set the amount of resources fee per minute for the side chain. + rpc UpdateRentedResources (UpdateRentedResourcesInput) returns (google.protobuf.Empty) { + } + + // Transfer Token to the specified contract. + rpc TransferToContract (TransferToContractInput) returns (google.protobuf.Empty) { + } + + // Change the governance organization of side chain rental. + rpc ChangeSideChainRentalController (AuthorityInfo) returns (google.protobuf.Empty) { + } + + // Change the governance organization for tokens to pay transaction fees. + rpc ChangeSymbolsToPayTXSizeFeeController(AuthorityInfo) returns (google.protobuf.Empty){ + } + + // Change the governance organization for cross-chain token contract address registration. + rpc ChangeCrossChainTokenContractRegistrationController (AuthorityInfo) returns (google.protobuf.Empty) { + } + + // Change the governance organization of the coefficient of the user transaction fee calculation formula. + rpc ChangeUserFeeController (AuthorityInfo) returns (google.protobuf.Empty) { + } + + // Change the governance organization of the coefficient of the developer's transaction resource fee calculation formula. + rpc ChangeDeveloperController (AuthorityInfo) returns (google.protobuf.Empty) { + } + + // Get the address of fee receiver. + rpc GetFeeReceiver (google.protobuf.Empty) returns (aelf.Address){ + option (aelf.is_view) = true; + } + + // Query the amount of resources usage currently. + rpc GetResourceUsage (google.protobuf.Empty) returns (ResourceUsage) { + option (aelf.is_view) = true; + } + + // Query the governance organization for tokens to pay transaction fees. + rpc GetSymbolsToPayTXSizeFeeController(google.protobuf.Empty) returns (AuthorityInfo){ + option (aelf.is_view) = true; + } + + // Query the governance organization of the + rpc GetCrossChainTokenContractRegistrationController (google.protobuf.Empty) returns (AuthorityInfo) { + option (aelf.is_view) = true; + } + + // Query the governance organization that calculates the formula coefficient + // for the transaction cost the user sends the contract. + rpc GetUserFeeController(google.protobuf.Empty) returns (UserFeeController){ + option (aelf.is_view) = true; + } + + // Query the governing organization of the formula coefficients for calculating developer contract transaction fee. + rpc GetDeveloperFeeController (google.protobuf.Empty) returns (DeveloperFeeController) { + option (aelf.is_view) = true; + } + + // Query the organization that governs the side chain rental fee. + rpc GetSideChainRentalControllerCreateInfo (google.protobuf.Empty) returns (AuthorityInfo) { + option (aelf.is_view) = true; + } + + // Compute the virtual address for locking. + rpc GetVirtualAddressForLocking (GetVirtualAddressForLockingInput) returns (aelf.Address) { + option (aelf.is_view) = true; + } + + // Query how much resource tokens should be paid currently. + rpc GetOwningRental (google.protobuf.Empty) returns (OwningRental) { + option (aelf.is_view) = true; + } + + // Query the unit price of the side chain resource cost, resource cost = unit price * quantity, + // the quantity can be queried through GetResourceUsage. + rpc GetOwningRentalUnitValue (google.protobuf.Empty) returns (OwningRentalUnitValue) { + option (aelf.is_view) = true; + } +} + +message AdvanceResourceTokenInput { + // The contract address to transfer. + aelf.Address contract_address = 1; + // The resource token symbol to transfer. + string resource_token_symbol = 2; + // The amount of resource token to transfer. + int64 amount = 3; +} + +message TakeResourceTokenBackInput { + // The contract address to take back. + aelf.Address contract_address = 1; + // The resource token symbol to take back. + string resource_token_symbol = 2; + // The amount of resource token to take back. + int64 amount = 3; +} + +message RegisterCrossChainTokenContractAddressInput{ + // The source chain id. + int32 from_chain_id = 1; + // The parent chain height of the transaction. + int64 parent_chain_height = 2; + // The raw bytes of the transfer transaction. + bytes transaction_bytes = 3; + // The merkle path created from the transaction. + aelf.MerklePath merkle_path = 4; + // The token contract address. + aelf.Address token_contract_address = 5; +} + +message ValidateTokenInfoExistsInput{ + // The symbol of the token. + string symbol = 1; + // The full name of the token. + string token_name = 2; + // The total supply of the token. + int64 total_supply = 3; + // The precision of the token. + int32 decimals = 4; + // The address that created the token. + aelf.Address issuer = 5; + // A flag indicating if this token is burnable. + bool is_burnable = 6; + // The chain id of the token. + int32 issue_chain_id = 7; + // The external information of the token. + map external_info = 8; +} + +message UpdateRentalInput { + // The unit price of resource tokens, symbol -> unit price. + map rental = 1; +} + +message UpdateRentedResourcesInput { + // Amount of resource tokens consumed per minute, symbol -> resource consumption. + map resource_amount = 1; +} + +message ResourceUsage { + // The amount of resource tokens usage, symbol -> amount. + map value = 1; +} + +message GetVirtualAddressForLockingInput { + // The address of the lock. + aelf.Address address = 1; + // The id of the lock. + aelf.Hash lock_id = 2; +} + +message OwningRental { + // The amount of resource tokens owed, symbol -> amount. + map resource_amount = 1; +} + +message OwningRentalUnitValue { + // Resource unit price, symbol -> unit price. + map resource_unit_value = 1; +} + +message TransferToContractInput { + // The symbol of token. + string symbol = 1; + // The amount of token. + int64 amount = 2; + // The memo. + string memo = 3; +} + +message UserFeeController{ + // The association that governs the organization. + AuthorityInfo root_controller = 1; + // The parliament organization of members. + AuthorityInfo parliament_controller = 2; + // The referendum organization of members. + AuthorityInfo referendum_controller = 3; +} + +message DeveloperFeeController { + // The association that governs the organization. + AuthorityInfo root_controller = 1; + // The parliament organization of members. + AuthorityInfo parliament_controller = 2; + // The developer organization of members. + AuthorityInfo developer_controller = 3; +} diff --git a/src/AElf.Client/AElf.Client.csproj b/src/AElf.Client/AElf.Client.csproj index ffb9f1b..063facb 100644 --- a/src/AElf.Client/AElf.Client.csproj +++ b/src/AElf.Client/AElf.Client.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/AElf.Client/AElfClient.Client.cs b/src/AElf.Client/AElfClient.Client.cs index c187395..f9039d8 100644 --- a/src/AElf.Client/AElfClient.Client.cs +++ b/src/AElf.Client/AElfClient.Client.cs @@ -2,8 +2,10 @@ using AElf.Client.Extensions; using AElf.Client.Model; using AElf.Client.Services; +using AElf.Contracts.MultiToken; using AElf.Cryptography; using AElf.Cryptography.ECDSA; +using AElf.Standards.ACS1; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -12,257 +14,293 @@ namespace AElf.Client; public partial class AElfClient : IClientService { /// - /// Verify whether this sdk successfully connects the chain. - /// - /// IsConnected or not - public async Task IsConnectedAsync() + /// Verify whether this sdk successfully connects the chain. + /// + /// IsConnected or not + public async Task IsConnectedAsync() + { + try { - try - { - var chainStatus = await GetChainStatusAsync(); - return chainStatus != null; - } - catch (Exception) - { - return false; - } + var chainStatus = await GetChainStatusAsync(); + return chainStatus != null; } - - /// - /// Get the address of genesis contract. - /// - /// Address - public async Task GetGenesisContractAddressAsync() + catch (Exception) { - var statusDto = await GetChainStatusAsync(); - var genesisAddress = statusDto?.GenesisContractAddress; - return genesisAddress; + return false; } + } + + /// + /// Get the address of genesis contract. + /// + /// Address + public async Task GetGenesisContractAddressAsync() + { + var statusDto = await GetChainStatusAsync(); + var genesisAddress = statusDto?.GenesisContractAddress; + return genesisAddress; + } - /// - /// Get address of a contract by given contractNameHash. - /// - /// - /// Address - public async Task
GetContractAddressByNameAsync(Hash contractNameHash) + /// + /// Get address of a contract by given contractNameHash. + /// + /// + /// Address + public async Task
GetContractAddressByNameAsync(Hash contractNameHash) + { + var from = GetAddressFromPrivateKey(AElfClientConstants.DefaultPrivateKey); + var to = await GetGenesisContractAddressAsync(); + var transaction = await GenerateTransactionAsync(from, to, "GetContractAddressByName", contractNameHash); + var txWithSig = SignTransaction(AElfClientConstants.DefaultPrivateKey, transaction); + + var response = await ExecuteTransactionAsync(new ExecuteTransactionDto { - var from = GetAddressFromPrivateKey(AElfClientConstants.DefaultPrivateKey); - var to = await GetGenesisContractAddressAsync(); - var transaction = await GenerateTransactionAsync(from, to, "GetContractAddressByName", contractNameHash); - var txWithSig = SignTransaction(AElfClientConstants.DefaultPrivateKey, transaction); + RawTransaction = txWithSig.ToByteArray().ToHex() + }); + var byteArray = ByteArrayHelper.HexStringToByteArray(response); + var address = Address.Parser.ParseFrom(byteArray); - var response = await ExecuteTransactionAsync(new ExecuteTransactionDto + return address; + } + + /// + /// Build a transaction from the input parameters. + /// + /// + /// + /// + /// + /// Transaction unsigned + public async Task GenerateTransactionAsync(string? from, string? to, + string methodName, IMessage input) + { + try + { + AssertValidAddress(to); + var chainStatus = await GetChainStatusAsync(); + var transaction = new Transaction { - RawTransaction = txWithSig.ToByteArray().ToHex() - }); - var byteArray = ByteArrayHelper.HexStringToByteArray(response); - var address = Address.Parser.ParseFrom(byteArray); + From = from.ToAddress(), + To = Address.FromBase58(to), + MethodName = methodName, + Params = input.ToByteString(), + RefBlockNumber = chainStatus.BestChainHeight, + RefBlockPrefix = ByteString.CopyFrom(Hash.LoadFromHex(chainStatus.BestChainHash).Value + .Take(4).ToArray()) + }; - return address; + return transaction; } - - /// - /// Build a transaction from the input parameters. - /// - /// - /// - /// - /// - /// Transaction unsigned - public async Task GenerateTransactionAsync(string? from, string? to, - string methodName, IMessage input) + catch (Exception ex) { - try - { - AssertValidAddress(to); - var chainStatus = await GetChainStatusAsync(); - var transaction = new Transaction - { - From = from.ToAddress(), - To = Address.FromBase58(to), - MethodName = methodName, - Params = input.ToByteString(), - RefBlockNumber = chainStatus.BestChainHeight, - RefBlockPrefix = ByteString.CopyFrom(Hash.LoadFromHex(chainStatus.BestChainHash).Value - .Take(4).ToArray()) - }; - - return transaction; - } - catch (Exception ex) - { - throw new AElfClientException($"Failed to generate transaction: {ex.Message}"); - } + throw new AElfClientException($"Failed to generate transaction: {ex.Message}"); } + } - /// - /// Convert the Address to the displayed string:symbol_base58-string_base58-string-chain-id - /// - /// - /// - public async Task GetFormattedAddressAsync(Address address) + /// + /// Convert the Address to the displayed string:symbol_base58-string_base58-string-chain-id + /// + /// + /// + public async Task GetFormattedAddressAsync(Address address) + { + var tokenContractAddress = + await GetContractAddressByNameAsync(HashHelper.ComputeFrom("AElf.ContractNames.Token")); + var fromAddress = GetAddressFromPrivateKey(AElfClientConstants.DefaultPrivateKey); + var toAddress = tokenContractAddress.ToBase58(); + var methodName = "GetPrimaryTokenSymbol"; + var param = new Empty(); + + var transaction = await GenerateTransactionAsync(fromAddress, toAddress, methodName, param); + var txWithSign = SignTransaction(AElfClientConstants.DefaultPrivateKey, transaction); + + var result = await ExecuteTransactionAsync(new ExecuteTransactionDto { - var tokenContractAddress = await GetContractAddressByNameAsync(HashHelper.ComputeFrom("AElf.ContractNames.Token")); - var fromAddress = GetAddressFromPrivateKey(AElfClientConstants.DefaultPrivateKey); - var toAddress = tokenContractAddress.ToBase58(); - var methodName = "GetPrimaryTokenSymbol"; - var param = new Empty(); + RawTransaction = txWithSign.ToByteArray().ToHex() + }); - var transaction = await GenerateTransactionAsync(fromAddress, toAddress, methodName, param); - var txWithSign = SignTransaction(AElfClientConstants.DefaultPrivateKey, transaction); + var symbol = StringValue.Parser.ParseFrom(ByteArrayHelper.HexStringToByteArray(result)); + var chainIdString = (await GetChainStatusAsync())?.ChainId; - var result = await ExecuteTransactionAsync(new ExecuteTransactionDto - { - RawTransaction = txWithSign.ToByteArray().ToHex() - }); + return $"{symbol.Value}_{address.ToBase58()}_{chainIdString}"; + } - var symbol = StringValue.Parser.ParseFrom(ByteArrayHelper.HexStringToByteArray(result)); - var chainIdString = (await GetChainStatusAsync())?.ChainId; + /// + /// Sign a transaction using private key. + /// + /// + /// + /// Transaction signed + public Transaction SignTransaction(string? privateKeyHex, Transaction transaction) + { + var transactionData = transaction.GetHash().ToByteArray(); - return $"{symbol.Value}_{address.ToBase58()}_{chainIdString}"; - } + privateKeyHex ??= AElfClientConstants.DefaultPrivateKey; - /// - /// Sign a transaction using private key. - /// - /// - /// - /// Transaction signed - public Transaction SignTransaction(string? privateKeyHex, Transaction transaction) - { - var transactionData = transaction.GetHash().ToByteArray(); + // Sign the hash + var privateKey = ByteArrayHelper.HexStringToByteArray(privateKeyHex); + var signature = CryptoHelper.SignWithPrivateKey(privateKey, transactionData); + transaction.Signature = ByteString.CopyFrom(signature); - privateKeyHex ??= AElfClientConstants.DefaultPrivateKey; + return transaction; + } - // Sign the hash - var privateKey = ByteArrayHelper.HexStringToByteArray(privateKeyHex); - var signature = CryptoHelper.SignWithPrivateKey(privateKey, transactionData); - transaction.Signature = ByteString.CopyFrom(signature); + /// + /// Sign a transaction using private key. + /// + /// + /// + /// Transaction signed + public Transaction SignTransaction(byte[]? privateKey, Transaction transaction) + { + var transactionData = transaction.GetHash().ToByteArray(); - return transaction; - } - - /// - /// Sign a transaction using private key. - /// - /// - /// - /// Transaction signed - public Transaction SignTransaction(byte[]? privateKey, Transaction transaction) - { - var transactionData = transaction.GetHash().ToByteArray(); + privateKey ??= ByteArrayHelper.HexStringToByteArray(AElfClientConstants.DefaultPrivateKey); - privateKey ??= ByteArrayHelper.HexStringToByteArray(AElfClientConstants.DefaultPrivateKey); + // Sign the hash + var signature = CryptoHelper.SignWithPrivateKey(privateKey, transactionData); + transaction.Signature = ByteString.CopyFrom(signature); - // Sign the hash - var signature = CryptoHelper.SignWithPrivateKey(privateKey, transactionData); - transaction.Signature = ByteString.CopyFrom(signature); + return transaction; + } - return transaction; - } + /// + /// Get the account address through the public key. + /// + /// + /// Account + public string GetAddressFromPubKey(string pubKey) + { + var publicKey = ByteArrayHelper.HexStringToByteArray(pubKey); + var address = Address.FromPublicKey(publicKey); + return address.ToBase58(); + } - /// - /// Get the account address through the public key. - /// - /// - /// Account - public string GetAddressFromPubKey(string pubKey) + /// + /// Get the account address through the private key. + /// + /// + /// + public string? GetAddressFromPrivateKey(string? privateKeyHex) + { + var address = Address.FromPublicKey(GetAElfKeyPair(privateKeyHex).PublicKey); + return address.ToBase58(); + } + + public KeyPairInfo GenerateKeyPairInfo() + { + var keyPair = CryptoHelper.GenerateKeyPair(); + var privateKey = keyPair.PrivateKey.ToHex(); + var publicKey = keyPair.PublicKey.ToHex(); + var address = GetAddressFromPrivateKey(privateKey); + + return new KeyPairInfo { - var publicKey = ByteArrayHelper.HexStringToByteArray(pubKey); - var address = Address.FromPublicKey(publicKey); - return address.ToBase58(); - } - - /// - /// Get the account address through the private key. - /// - /// - /// - public string? GetAddressFromPrivateKey(string? privateKeyHex) + PrivateKey = privateKey, + PublicKey = publicKey, + Address = address + }; + } + + public async Task CalculateTransactionFeeBill(Transaction transaction) + { + var tokenContractAddress = + await GetContractAddressByNameAsync(HashHelper.ComputeFrom("AElf.ContractNames.Token")); + var fromAddress = GetAddressFromPrivateKey(AElfClientConstants.DefaultPrivateKey); + var toAddress = tokenContractAddress.ToBase58(); + var methodName = "GetMethodFee"; + var param = new StringValue { Value = transaction.MethodName }; + + var getMethodFeeTx = await GenerateTransactionAsync(fromAddress, toAddress, methodName, param); + var executeResult = await ExecuteTransactionAsync(new ExecuteTransactionDto { - var address = Address.FromPublicKey(GetAElfKeyPair(privateKeyHex).PublicKey); - return address.ToBase58(); - } + RawTransaction = getMethodFeeTx.ToByteArray().ToHex() + }); - public Address GetBase58String(string base58String) - { - return Address.FromBase58(base58String); - } + var methodFees = new MethodFees(); + methodFees.MergeFrom(ByteArrayHelper.HexStringToByteArray(executeResult)); - public KeyPairInfo GenerateKeyPairInfo() - { - var keyPair = CryptoHelper.GenerateKeyPair(); - var privateKey = keyPair.PrivateKey.ToHex(); - var publicKey = keyPair.PublicKey.ToHex(); - var address = GetAddressFromPrivateKey(privateKey); + var bill = new TransactionFeeBill(); - return new KeyPairInfo - { - PrivateKey = privateKey, - PublicKey = publicKey, - Address = address - }; + if (methodFees.Fees.Any()) + { + var baseFees = GetBaseFeeDictionary(methodFees); } - #region private methods + return bill; + } - private ECKeyPair GetAElfKeyPair(string? privateKeyHex) - { - var privateKey = ByteArrayHelper.HexStringToByteArray(privateKeyHex); - var keyPair = CryptoHelper.FromPrivateKey(privateKey); + #region private methods - return keyPair; - } + private ECKeyPair GetAElfKeyPair(string? privateKeyHex) + { + var privateKey = ByteArrayHelper.HexStringToByteArray(privateKeyHex); + var keyPair = CryptoHelper.FromPrivateKey(privateKey); - private string GetRequestUrl(string baseUrl, string relativeUrl) - { - return new Uri(new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/")), relativeUrl).ToString(); - } + return keyPair; + } + + private string GetRequestUrl(string baseUrl, string relativeUrl) + { + return new Uri(new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/")), relativeUrl).ToString(); + } - private void AssertValidAddress(params string?[] addresses) + private void AssertValidAddress(params string?[] addresses) + { + try { - try + foreach (var address in addresses) { - foreach (var address in addresses) - { - Address.FromBase58(address); - } - } - catch (Exception) - { - throw new AElfClientException(Error.Message[Error.InvalidAddress]); + Address.FromBase58(address); } } + catch (Exception) + { + throw new AElfClientException(Error.Message[Error.InvalidAddress]); + } + } - private void AssertValidHash(params string[] hashes) + private void AssertValidHash(params string[] hashes) + { + try { - try + foreach (var hash in hashes) { - foreach (var hash in hashes) - { - Hash.LoadFromHex(hash); - } - } - catch (Exception) - { - throw new AElfClientException(Error.Message[Error.InvalidBlockHash]); + Hash.LoadFromHex(hash); } } + catch (Exception) + { + throw new AElfClientException(Error.Message[Error.InvalidBlockHash]); + } + } - private void AssertValidTransactionId(params string[] transactionIds) + private void AssertValidTransactionId(params string[] transactionIds) + { + try { - try - { - foreach (var transactionId in transactionIds) - { - Hash.LoadFromHex(transactionId); - } - } - catch (Exception) + foreach (var transactionId in transactionIds) { - throw new AElfClientException(Error.Message[Error.InvalidTransactionId]); + Hash.LoadFromHex(transactionId); } } + catch (Exception) + { + throw new AElfClientException(Error.Message[Error.InvalidTransactionId]); + } + } + + private Dictionary GetBaseFeeDictionary(MethodFees methodFees) + { + var dict = new Dictionary(); + foreach (var methodFee in methodFees.Fees) + if (dict.ContainsKey(methodFee.Symbol)) + dict[methodFee.Symbol] += methodFee.BasicFee; + else + dict[methodFee.Symbol] = methodFee.BasicFee; + + return dict; + } - #endregion + #endregion } \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.cs b/src/AElf.Client/AElfClient.cs index a45bb29..218e1f7 100644 --- a/src/AElf.Client/AElfClient.cs +++ b/src/AElf.Client/AElfClient.cs @@ -1,5 +1,5 @@ using System.Text.Json; -using AElf.Client.Service; +using AElf.Client.Services; namespace AElf.Client; diff --git a/src/AElf.Client/AElfClientConstants.cs b/src/AElf.Client/AElfClientConstants.cs index 6c1efc9..7fe104e 100644 --- a/src/AElf.Client/AElfClientConstants.cs +++ b/src/AElf.Client/AElfClientConstants.cs @@ -3,11 +3,11 @@ namespace AElf.Client; public class AElfClientConstants { public const string DefaultPrivateKey = "09da44778f8db2e602fb484334f37df19e221c84c4582ce5b7770ccfbc3ddbef"; - public const string LocalEndpoint = "http://127.0.0.1:1235"; + public const string LocalEndpoint = "http://127.0.0.1:1726"; public const string MainNetMainChain = "https://aelf-public-node.aelf.io"; - public const string MainNetSidechain = "https://tdvv-public-node.aelf.io"; + public const string MainNetSidechain = "https://explorer-.aelf.io"; public const string TestNetMainChain = "https://aelf-test-node.aelf.io"; - public const string TestNetSidechain = "https://tdvv-test-node.aelf.io"; + public const string TestNetSidechain = "https:/tdvv-test-node.aelf.io"; public const int MainChainId = 9992731; - public const int SidechainId = 9992731; + public const int SidechainId = 1866392; } \ No newline at end of file diff --git a/src/AElf.Client/Dto/BlockDto.cs b/src/AElf.Client/Dto/BlockDto.cs index 2c25367..a155653 100644 --- a/src/AElf.Client/Dto/BlockDto.cs +++ b/src/AElf.Client/Dto/BlockDto.cs @@ -7,4 +7,6 @@ public class BlockDto public BlockHeaderDto Header { get; set; } public BlockBodyDto Body { get; set; } + + public int BlockSize { get; set; } } \ No newline at end of file diff --git a/src/AElf.Client/Dto/ChainStatusDto.cs b/src/AElf.Client/Dto/ChainStatusDto.cs index 2cb6580..45feb0d 100644 --- a/src/AElf.Client/Dto/ChainStatusDto.cs +++ b/src/AElf.Client/Dto/ChainStatusDto.cs @@ -1,26 +1,28 @@ +using System.Text.Json.Serialization; + namespace AElf.Client.Dto; public class ChainStatusDto { public string ChainId { get; set; } - - public Dictionary Branches { get; set; } - - public Dictionary NotLinkedBlocks { get; set; } - + + public Dictionary Branches { get; set; } + + public Dictionary NotLinkedBlocks { get; set; } + public long LongestChainHeight { get; set; } - + public string LongestChainHash { get; set; } public string GenesisBlockHash { get; set; } - + public string GenesisContractAddress { get; set; } - + public string LastIrreversibleBlockHash { get; set; } - + public long LastIrreversibleBlockHeight { get; set; } - + public string BestChainHash { get; set; } - + public long BestChainHeight { get; set; } } \ No newline at end of file diff --git a/src/AElf.Client/Dto/MerklePathDto.cs b/src/AElf.Client/Dto/MerklePathDto.cs index ee0f9d1..dbd8994 100644 --- a/src/AElf.Client/Dto/MerklePathDto.cs +++ b/src/AElf.Client/Dto/MerklePathDto.cs @@ -2,7 +2,7 @@ namespace AElf.Client.Dto; public class MerklePathDto { - public List MerklePathNodes; + public List MerklePathNodes { get; set; } } public class MerklePathNodeDto diff --git a/src/AElf.Client/Dto/TransactionResultDto.cs b/src/AElf.Client/Dto/TransactionResultDto.cs index 30ff3fa..815aa47 100644 --- a/src/AElf.Client/Dto/TransactionResultDto.cs +++ b/src/AElf.Client/Dto/TransactionResultDto.cs @@ -3,20 +3,22 @@ namespace AElf.Client.Dto; public class TransactionResultDto { public string TransactionId { get; set; } - + public string Status { get; set; } - + public LogEventDto[] Logs { get; set; } - + public string Bloom { get; set; } - + public long BlockNumber { get; set; } - + public string BlockHash { get; set; } - + public TransactionDto Transaction { get; set; } - + public string ReturnValue { get; set; } public string Error { get; set; } + + public int TransactionSize { get; set; } } \ No newline at end of file diff --git a/src/AElf.Client/Services/HttpService.cs b/src/AElf.Client/Services/HttpService.cs index 74bbdde..1c6a79c 100644 --- a/src/AElf.Client/Services/HttpService.cs +++ b/src/AElf.Client/Services/HttpService.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; using System.Net; -using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Text.Json; -using System.Threading.Tasks; -namespace AElf.Client.Service; +namespace AElf.Client.Services; public interface IHttpService { @@ -46,7 +42,10 @@ public HttpService(int timeoutSeconds) { var response = await GetResponseAsync(url, version, expectedStatusCode); var stream = await response.Content.ReadAsStreamAsync(); - return await JsonSerializer.DeserializeAsync(stream); + return await JsonSerializer.DeserializeAsync(stream, options:new JsonSerializerOptions + { + //PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }); } /// diff --git a/test/AElf.Client.Test/ClientTest.cs b/test/AElf.Client.Test/ClientTest.cs index 4127c7f..ab2c51f 100644 --- a/test/AElf.Client.Test/ClientTest.cs +++ b/test/AElf.Client.Test/ClientTest.cs @@ -8,7 +8,7 @@ using AElf.Types; using AElf.Client.Dto; using AElf.Client.Extensions; -using AElf.Client.Service; +using AElf.Client.Services; using AElf.Contracts.MultiToken; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -25,7 +25,7 @@ namespace AElf.Client.Test; public class ClientTest { - private const string BaseUrl = "http://192.168.196.116:8000"; + private const string BaseUrl = "https://tdvv-test-node.aelf.io"; private string _genesisAddress; private string GenesisAddress => GetGenesisContractAddress(); From 779f4127e0966bb442ca6c5425efab40437b7a2a Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 8 Jun 2022 20:31:01 +0800 Subject: [PATCH 02/21] Add several empty projects :) --- all.sln | 128 +++++++++++++++++- examples/TokenManager/TokenManager.csproj | 2 +- examples/TokenManager/TokenManagerModule.cs | 4 +- examples/TokenManager/TokenManagerService.cs | 2 +- examples/TokenManager/appsettings.json | 2 +- .../AElf.Client.Abp.Association.csproj} | 4 - .../AElfClientAssociationModule.cs | 5 + .../AElf.Client.Abp.Bridge.csproj | 9 ++ .../AElfClientBridgeModule.cs | 5 + .../AElf.Client.Abp.Configuration.csproj | 9 ++ .../AElfClientConfigurationModule.cs | 5 + .../AElf.Client.Abp.Consensus.AEDPoS.csproj | 9 ++ .../AElfClientAEDPoSModule.cs | 5 + .../AElf.Client.Abp.Core.csproj | 18 +++ .../AElf.Client.Abp.CrossChain.csproj | 9 ++ .../AElfClientCrossChainModule.cs | 5 + .../AElf.Client.Abp.Election.csproj | 10 ++ .../AElfClientElectionModule.cs | 5 + .../AElf.Client.Abp.Genesis.csproj | 9 ++ .../AElfClientGenesisModule.cs | 5 + .../AElf.Client.Abp.NFTMarket.csproj | 9 ++ .../AElfClientNFTMarketModule.cs | 5 + .../AElf.Client.Abp.Oracle.csproj | 9 ++ .../AElfClientOracleModule.cs | 5 + .../AElf.Client.Abp.Parliament.csproj | 9 ++ .../AElfClientParliamentModule.cs | 5 + .../AElf.Client.Abp.Profit.csproj | 9 ++ .../AElfClientProfitModule.cs | 5 + .../AElf.Client.Abp.Referendum.csproj | 9 ++ .../AElfClientReferendumModule.cs | 5 + .../AElf.Client.Abp.Regiment.csproj | 9 ++ .../AElfClientRegimentModule.cs | 5 + .../AElf.Client.Abp.Token.csproj | 18 +++ .../AElfClientTokenModule.cs} | 6 +- .../AElfTokenConstants.cs} | 4 +- src/AElf.Client.Abp.Token/AElfTokenOptions.cs | 6 + src/AElf.Client.Abp.Token/ITokenService.cs | 17 +++ .../README.md | 0 .../TokenService.Send.cs | 14 +- .../TokenService.View.cs | 8 +- .../AElf.Client.Abp.TokenConverter.csproj | 9 ++ .../AElfClientTokenConverterModule.cs | 5 + .../AElf.Client.Abp.TokenHolder.csproj | 9 ++ .../AElfClientTokenHolderModule.cs | 5 + .../ITokenService.cs | 20 --- .../TokenManagerOptions.cs | 6 - .../AElf.Client.Abp.Vote.csproj | 9 ++ .../AElfClientVoteModule.cs | 5 + .../AElf.Client.Abp.Whitelist.csproj | 9 ++ .../AElfClientWhitelistModule.cs | 5 + src/AElf.Client.Abp/AElf.Client.Abp.csproj | 2 +- src/AElf.Client/AElf.Client.csproj | 4 +- src/AElf.Client/AElfClient.Client.cs | 28 ---- 53 files changed, 440 insertions(+), 83 deletions(-) rename src/{AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj => AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj} (66%) create mode 100644 src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs create mode 100644 src/AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj create mode 100644 src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs create mode 100644 src/AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj create mode 100644 src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs create mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj create mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs create mode 100644 src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj create mode 100644 src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj create mode 100644 src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs create mode 100644 src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj create mode 100644 src/AElf.Client.Abp.Election/AElfClientElectionModule.cs create mode 100644 src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj create mode 100644 src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs create mode 100644 src/AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj create mode 100644 src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs create mode 100644 src/AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj create mode 100644 src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs create mode 100644 src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj create mode 100644 src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs create mode 100644 src/AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj create mode 100644 src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs create mode 100644 src/AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj create mode 100644 src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs create mode 100644 src/AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj create mode 100644 src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs create mode 100644 src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj rename src/{AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs => AElf.Client.Abp.Token/AElfClientTokenModule.cs} (61%) rename src/{AElf.Client.Abp.TokenManager/TokenManagerConstants.cs => AElf.Client.Abp.Token/AElfTokenConstants.cs} (51%) create mode 100644 src/AElf.Client.Abp.Token/AElfTokenOptions.cs create mode 100644 src/AElf.Client.Abp.Token/ITokenService.cs rename src/{AElf.Client.Abp.TokenManager => AElf.Client.Abp.Token}/README.md (100%) rename src/{AElf.Client.Abp.TokenManager => AElf.Client.Abp.Token}/TokenService.Send.cs (74%) rename src/{AElf.Client.Abp.TokenManager => AElf.Client.Abp.Token}/TokenService.View.cs (77%) create mode 100644 src/AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj create mode 100644 src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs create mode 100644 src/AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj create mode 100644 src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs delete mode 100644 src/AElf.Client.Abp.TokenManager/ITokenService.cs delete mode 100644 src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs create mode 100644 src/AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj create mode 100644 src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs create mode 100644 src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj create mode 100644 src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs diff --git a/all.sln b/all.sln index 7e26974..bbff868 100644 --- a/all.sln +++ b/all.sln @@ -20,7 +20,43 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Test", "test\AE EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp", "src\AElf.Client.Abp\AElf.Client.Abp.csproj", "{BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TokenManager", "src\AElf.Client.Abp.TokenManager\AElf.Client.Abp.TokenManager.csproj", "{4E127996-AE35-4DCC-B4C0-057CB5B22A0E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Token", "src\AElf.Client.Abp.Token\AElf.Client.Abp.Token.csproj", "{4E127996-AE35-4DCC-B4C0-057CB5B22A0E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Election", "src\AElf.Client.Abp.Election\AElf.Client.Abp.Election.csproj", "{D27E0203-23E4-4B81-A3FC-EE5034FA631E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Vote", "src\AElf.Client.Abp.Vote\AElf.Client.Abp.Vote.csproj", "{B76DF7DD-1A8A-4876-A450-5669C9B31750}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Profit", "src\AElf.Client.Abp.Profit\AElf.Client.Abp.Profit.csproj", "{BD004F96-0173-489C-BA20-6C21A7F9C538}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Association", "src\AElf.Client.Abp.Association\AElf.Client.Abp.Association.csproj", "{7B40B739-18F8-4A40-A8EF-BA2758199092}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Configuration", "src\AElf.Client.Abp.Configuration\AElf.Client.Abp.Configuration.csproj", "{E467E8FB-933C-4E2C-BC75-490B852464A8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Consensus.AEDPoS", "src\AElf.Client.Abp.Consensus.AEDPoS\AElf.Client.Abp.Consensus.AEDPoS.csproj", "{84E06902-1D71-4F8F-9071-49CAFF3B8A05}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.CrossChain", "src\AElf.Client.Abp.CrossChain\AElf.Client.Abp.CrossChain.csproj", "{6D6FE332-73A4-4F40-BE96-E720A6B83201}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Genesis", "src\AElf.Client.Abp.Genesis\AElf.Client.Abp.Genesis.csproj", "{12506F28-C416-4377-B23D-301CE0AA2E8C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.NFTMarket", "src\AElf.Client.Abp.NFTMarket\AElf.Client.Abp.NFTMarket.csproj", "{5653A6D9-D170-4C71-AB5F-9B770E45604A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Parliament", "src\AElf.Client.Abp.Parliament\AElf.Client.Abp.Parliament.csproj", "{8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Referendum", "src\AElf.Client.Abp.Referendum\AElf.Client.Abp.Referendum.csproj", "{899F17C1-2FB6-418E-A9BD-5613C563365E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TokenHolder", "src\AElf.Client.Abp.TokenHolder\AElf.Client.Abp.TokenHolder.csproj", "{7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TokenConverter", "src\AElf.Client.Abp.TokenConverter\AElf.Client.Abp.TokenConverter.csproj", "{B3EE451C-200D-4CC0-AEFA-1553892C825F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Whitelist", "src\AElf.Client.Abp.Whitelist\AElf.Client.Abp.Whitelist.csproj", "{478E52D9-1BA5-4852-B1CC-79D5B8382D87}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Oracle", "src\AElf.Client.Abp.Oracle\AElf.Client.Abp.Oracle.csproj", "{D1C08C5C-9F59-41A9-9A7B-788377BC2B92}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Bridge", "src\AElf.Client.Abp.Bridge\AElf.Client.Abp.Bridge.csproj", "{4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Regiment", "src\AElf.Client.Abp.Regiment\AElf.Client.Abp.Regiment.csproj", "{F520E0B9-9EF7-4528-93FA-C182E8423F51}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Core", "src\AElf.Client.Abp.Core\AElf.Client.Abp.Core.csproj", "{1552B665-A065-41AE-A00E-A6E9AB974414}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -36,6 +72,24 @@ Global {4D019C99-8B1C-42B0-8630-F1E3661F414B} = {7CD2B508-C765-4720-B430-94E79135797A} {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F} = {940361AC-2167-4D30-A4F6-9A543C608196} {4E127996-AE35-4DCC-B4C0-057CB5B22A0E} = {940361AC-2167-4D30-A4F6-9A543C608196} + {D27E0203-23E4-4B81-A3FC-EE5034FA631E} = {940361AC-2167-4D30-A4F6-9A543C608196} + {B76DF7DD-1A8A-4876-A450-5669C9B31750} = {940361AC-2167-4D30-A4F6-9A543C608196} + {BD004F96-0173-489C-BA20-6C21A7F9C538} = {940361AC-2167-4D30-A4F6-9A543C608196} + {7B40B739-18F8-4A40-A8EF-BA2758199092} = {940361AC-2167-4D30-A4F6-9A543C608196} + {E467E8FB-933C-4E2C-BC75-490B852464A8} = {940361AC-2167-4D30-A4F6-9A543C608196} + {84E06902-1D71-4F8F-9071-49CAFF3B8A05} = {940361AC-2167-4D30-A4F6-9A543C608196} + {6D6FE332-73A4-4F40-BE96-E720A6B83201} = {940361AC-2167-4D30-A4F6-9A543C608196} + {12506F28-C416-4377-B23D-301CE0AA2E8C} = {940361AC-2167-4D30-A4F6-9A543C608196} + {5653A6D9-D170-4C71-AB5F-9B770E45604A} = {940361AC-2167-4D30-A4F6-9A543C608196} + {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF} = {940361AC-2167-4D30-A4F6-9A543C608196} + {899F17C1-2FB6-418E-A9BD-5613C563365E} = {940361AC-2167-4D30-A4F6-9A543C608196} + {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74} = {940361AC-2167-4D30-A4F6-9A543C608196} + {B3EE451C-200D-4CC0-AEFA-1553892C825F} = {940361AC-2167-4D30-A4F6-9A543C608196} + {478E52D9-1BA5-4852-B1CC-79D5B8382D87} = {940361AC-2167-4D30-A4F6-9A543C608196} + {D1C08C5C-9F59-41A9-9A7B-788377BC2B92} = {940361AC-2167-4D30-A4F6-9A543C608196} + {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610} = {940361AC-2167-4D30-A4F6-9A543C608196} + {F520E0B9-9EF7-4528-93FA-C182E8423F51} = {940361AC-2167-4D30-A4F6-9A543C608196} + {1552B665-A065-41AE-A00E-A6E9AB974414} = {940361AC-2167-4D30-A4F6-9A543C608196} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -70,5 +124,77 @@ Global {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Release|Any CPU.Build.0 = Release|Any CPU + {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Release|Any CPU.Build.0 = Release|Any CPU + {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Release|Any CPU.Build.0 = Release|Any CPU + {BD004F96-0173-489C-BA20-6C21A7F9C538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BD004F96-0173-489C-BA20-6C21A7F9C538}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BD004F96-0173-489C-BA20-6C21A7F9C538}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BD004F96-0173-489C-BA20-6C21A7F9C538}.Release|Any CPU.Build.0 = Release|Any CPU + {7B40B739-18F8-4A40-A8EF-BA2758199092}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B40B739-18F8-4A40-A8EF-BA2758199092}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B40B739-18F8-4A40-A8EF-BA2758199092}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B40B739-18F8-4A40-A8EF-BA2758199092}.Release|Any CPU.Build.0 = Release|Any CPU + {E467E8FB-933C-4E2C-BC75-490B852464A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E467E8FB-933C-4E2C-BC75-490B852464A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E467E8FB-933C-4E2C-BC75-490B852464A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E467E8FB-933C-4E2C-BC75-490B852464A8}.Release|Any CPU.Build.0 = Release|Any CPU + {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Release|Any CPU.Build.0 = Release|Any CPU + {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Release|Any CPU.Build.0 = Release|Any CPU + {12506F28-C416-4377-B23D-301CE0AA2E8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12506F28-C416-4377-B23D-301CE0AA2E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12506F28-C416-4377-B23D-301CE0AA2E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12506F28-C416-4377-B23D-301CE0AA2E8C}.Release|Any CPU.Build.0 = Release|Any CPU + {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Release|Any CPU.Build.0 = Release|Any CPU + {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Release|Any CPU.Build.0 = Release|Any CPU + {899F17C1-2FB6-418E-A9BD-5613C563365E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {899F17C1-2FB6-418E-A9BD-5613C563365E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {899F17C1-2FB6-418E-A9BD-5613C563365E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {899F17C1-2FB6-418E-A9BD-5613C563365E}.Release|Any CPU.Build.0 = Release|Any CPU + {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Release|Any CPU.Build.0 = Release|Any CPU + {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Release|Any CPU.Build.0 = Release|Any CPU + {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Debug|Any CPU.Build.0 = Debug|Any CPU + {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Release|Any CPU.ActiveCfg = Release|Any CPU + {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Release|Any CPU.Build.0 = Release|Any CPU + {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Release|Any CPU.Build.0 = Release|Any CPU + {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Release|Any CPU.Build.0 = Release|Any CPU + {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Release|Any CPU.Build.0 = Release|Any CPU + {1552B665-A065-41AE-A00E-A6E9AB974414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1552B665-A065-41AE-A00E-A6E9AB974414}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1552B665-A065-41AE-A00E-A6E9AB974414}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1552B665-A065-41AE-A00E-A6E9AB974414}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/examples/TokenManager/TokenManager.csproj b/examples/TokenManager/TokenManager.csproj index 0409bd7..6bf13c4 100644 --- a/examples/TokenManager/TokenManager.csproj +++ b/examples/TokenManager/TokenManager.csproj @@ -8,7 +8,7 @@ - + diff --git a/examples/TokenManager/TokenManagerModule.cs b/examples/TokenManager/TokenManagerModule.cs index 00f69fe..57c684b 100644 --- a/examples/TokenManager/TokenManagerModule.cs +++ b/examples/TokenManager/TokenManagerModule.cs @@ -1,5 +1,5 @@ using AElf.Client.Abp; -using AElf.Client.Abp.TokenManager; +using AElf.Client.Abp.Token; using AElf.Client.Options; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -9,7 +9,7 @@ namespace TokenManager; [DependsOn( typeof(AElfClientModule), - typeof(AElfClientTokenManagerModule) + typeof(AElfClientTokenModule) )] public class AEDPoSViewerModule : AbpModule { diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs index 014243d..a495258 100644 --- a/examples/TokenManager/TokenManagerService.cs +++ b/examples/TokenManager/TokenManagerService.cs @@ -1,6 +1,6 @@ using AElf.Client; using AElf.Client.Abp; -using AElf.Client.Abp.TokenManager; +using AElf.Client.Abp.Token; using AElf.Client.Dto; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index fd5a9ad..b2931bc 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -42,7 +42,7 @@ } ] }, - "TokenManager": { + "AElfToken": { "NFTContractAddress": "" }, "SyncTokenInfo": { diff --git a/src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj b/src/AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj similarity index 66% rename from src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj rename to src/AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj index a49c765..eb2460e 100644 --- a/src/AElf.Client.Abp.TokenManager/AElf.Client.Abp.TokenManager.csproj +++ b/src/AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj @@ -6,8 +6,4 @@ enable - - - - diff --git a/src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs b/src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs new file mode 100644 index 0000000..8a518db --- /dev/null +++ b/src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Association; + +public class AElfClientAssociationModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj b/src/AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs b/src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs new file mode 100644 index 0000000..fa7b6c6 --- /dev/null +++ b/src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Bridge; + +public class AElfClientBridgeModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj b/src/AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs b/src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs new file mode 100644 index 0000000..08cf6ce --- /dev/null +++ b/src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Configuration; + +public class AElfClientConfigurationModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj b/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs new file mode 100644 index 0000000..51f969f --- /dev/null +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Consensus.AEDPoS; + +public class AElfClientAEDPoSModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj b/src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj new file mode 100644 index 0000000..10e6feb --- /dev/null +++ b/src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj b/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs b/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs new file mode 100644 index 0000000..92e7f14 --- /dev/null +++ b/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.CrossChain; + +public class AElfClientCrossChainModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj b/src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj new file mode 100644 index 0000000..df06cf7 --- /dev/null +++ b/src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj @@ -0,0 +1,10 @@ + + + + net6.0 + enable + enable + AElf.Client.Abp.Election + + + diff --git a/src/AElf.Client.Abp.Election/AElfClientElectionModule.cs b/src/AElf.Client.Abp.Election/AElfClientElectionModule.cs new file mode 100644 index 0000000..5ac1487 --- /dev/null +++ b/src/AElf.Client.Abp.Election/AElfClientElectionModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Election; + +public class AElfClientElectionModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj b/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs b/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs new file mode 100644 index 0000000..6aa310f --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Genesis; + +public class AElfClientGenesisModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj b/src/AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs b/src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs new file mode 100644 index 0000000..d10ea29 --- /dev/null +++ b/src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.NFTMarket; + +public class AElfClientNFTMarketModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj b/src/AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs b/src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs new file mode 100644 index 0000000..8a9aaec --- /dev/null +++ b/src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Oracle; + +public class AElfClientOracleModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj b/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs b/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs new file mode 100644 index 0000000..f1ec434 --- /dev/null +++ b/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Parliament; + +public class AElfClientParliamentModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj b/src/AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs b/src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs new file mode 100644 index 0000000..2c59b61 --- /dev/null +++ b/src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Profit; + +public class AElfClientProfitModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj b/src/AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs b/src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs new file mode 100644 index 0000000..b809d28 --- /dev/null +++ b/src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Referendum; + +public class AElfClientReferendumModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj b/src/AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs b/src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs new file mode 100644 index 0000000..2b1307e --- /dev/null +++ b/src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Regiment; + +public class AElfClientRegimentModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj b/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj new file mode 100644 index 0000000..f007fef --- /dev/null +++ b/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + AElf.Client.Abp.Token + AElf.Client.Abp.Token + AElf token manager abp module. + AElf + true + + + + + + + diff --git a/src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs similarity index 61% rename from src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs rename to src/AElf.Client.Abp.Token/AElfClientTokenModule.cs index fe33352..ddf8445 100644 --- a/src/AElf.Client.Abp.TokenManager/AElfClientTokenManagerModule.cs +++ b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs @@ -2,16 +2,16 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; -namespace AElf.Client.Abp.TokenManager; +namespace AElf.Client.Abp.Token; [DependsOn( typeof(AElfClientModule) )] -public class AElfClientTokenManagerModule : AbpModule +public class AElfClientTokenModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - Configure(options => { configuration.GetSection("TokenManager").Bind(options); }); + Configure(options => { configuration.GetSection("AElfToken").Bind(options); }); } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs similarity index 51% rename from src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs rename to src/AElf.Client.Abp.Token/AElfTokenConstants.cs index c273150..8410a9b 100644 --- a/src/AElf.Client.Abp.TokenManager/TokenManagerConstants.cs +++ b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs @@ -1,6 +1,6 @@ -namespace AElf.Client.Abp.TokenManager; +namespace AElf.Client.Abp.Token; -public class TokenManagerConstants +public class AElfTokenConstants { public const string TokenSmartContractName = "AElf.ContractNames.Token"; } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElfTokenOptions.cs b/src/AElf.Client.Abp.Token/AElfTokenOptions.cs new file mode 100644 index 0000000..a4fab54 --- /dev/null +++ b/src/AElf.Client.Abp.Token/AElfTokenOptions.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.Token; + +public class AElfTokenOptions +{ + public string NFTContractAddress { get; set; } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Abp.Token/ITokenService.cs new file mode 100644 index 0000000..0899745 --- /dev/null +++ b/src/AElf.Client.Abp.Token/ITokenService.cs @@ -0,0 +1,17 @@ +using AElf.Contracts.MultiToken; +using AElf.Contracts.NFT; +using AElf.Types; + +namespace AElf.Client.Abp.Token; + +public interface ITokenService +{ + Task CreateTokenAsync(Contracts.MultiToken.CreateInput createInput); + Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput); + Task MintNFTAsync(MintInput mintInput); + Task SyncTokenInfoAsync(string symbol); + + Task GetTokenInfoAsync(string symbol); + Task GetTokenBalanceAsync(string symbol, Address owner); + Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/README.md b/src/AElf.Client.Abp.Token/README.md similarity index 100% rename from src/AElf.Client.Abp.TokenManager/README.md rename to src/AElf.Client.Abp.Token/README.md diff --git a/src/AElf.Client.Abp.TokenManager/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs similarity index 74% rename from src/AElf.Client.Abp.TokenManager/TokenService.Send.cs rename to src/AElf.Client.Abp.Token/TokenService.Send.cs index e44a495..5ee13a4 100644 --- a/src/AElf.Client.Abp.TokenManager/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -6,26 +6,26 @@ using Volo.Abp.DependencyInjection; using CreateInput = AElf.Contracts.MultiToken.CreateInput; -namespace AElf.Client.Abp.TokenManager; +namespace AElf.Client.Abp.Token; public partial class TokenService : ITokenService, ITransientDependency { private readonly IAElfClientService _clientService; - private readonly TokenManagerOptions _tokenManagerOptions; + private readonly AElfTokenOptions _aElfTokenOptions; private readonly AElfClientConfigOptions _clientConfigOptions; public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions, - IOptionsSnapshot tokenManagerOptions) + IOptionsSnapshot tokenManagerOptions) { _clientService = clientService; - _tokenManagerOptions = tokenManagerOptions.Value; + _aElfTokenOptions = tokenManagerOptions.Value; _clientConfigOptions = clientConfigOptions.Value; } public async Task CreateTokenAsync(CreateInput createInput) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var txId = await _clientService.SendSystemAsync(TokenManagerConstants.TokenSmartContractName, "Create", createInput, + var txId = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, "Create", createInput, useClientAlias); var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); return txResult; @@ -34,7 +34,7 @@ public async Task CreateTokenAsync(CreateInput createInput) public async Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var txId = await _clientService.SendAsync(_tokenManagerOptions.NFTContractAddress, "Create", createInput, + var txId = await _clientService.SendAsync(_aElfTokenOptions.NFTContractAddress, "Create", createInput, useClientAlias); var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); return txResult; @@ -43,7 +43,7 @@ public async Task CreateNFTProtocolAsync(Contracts.NFT.Create public async Task MintNFTAsync(MintInput mintInput) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var txId = await _clientService.SendAsync(_tokenManagerOptions.NFTContractAddress, "Mint", mintInput, + var txId = await _clientService.SendAsync(_aElfTokenOptions.NFTContractAddress, "Mint", mintInput, useClientAlias); var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); return txResult; diff --git a/src/AElf.Client.Abp.TokenManager/TokenService.View.cs b/src/AElf.Client.Abp.Token/TokenService.View.cs similarity index 77% rename from src/AElf.Client.Abp.TokenManager/TokenService.View.cs rename to src/AElf.Client.Abp.Token/TokenService.View.cs index 09dc600..25fea27 100644 --- a/src/AElf.Client.Abp.TokenManager/TokenService.View.cs +++ b/src/AElf.Client.Abp.Token/TokenService.View.cs @@ -2,14 +2,14 @@ using AElf.Types; using Google.Protobuf; -namespace AElf.Client.Abp.TokenManager; +namespace AElf.Client.Abp.Token; public partial class TokenService { public async Task GetTokenInfoAsync(string symbol) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var result = await _clientService.ViewSystemAsync(TokenManagerConstants.TokenSmartContractName, "GetTokenInfo", + var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetTokenInfo", new GetTokenInfoInput { Symbol = symbol @@ -22,7 +22,7 @@ public async Task GetTokenInfoAsync(string symbol) public async Task GetTokenBalanceAsync(string symbol, Address owner) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var result = await _clientService.ViewSystemAsync(TokenManagerConstants.TokenSmartContractName, "GetBalance", + var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetBalance", new GetBalanceInput { Owner = owner, @@ -36,7 +36,7 @@ public async Task GetTokenBalanceAsync(string symbol, Address public async Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var result = await _clientService.ViewSystemAsync(TokenManagerConstants.TokenSmartContractName, "GetAllowance", + var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetAllowance", new GetAllowanceInput { Owner = owner, diff --git a/src/AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj b/src/AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs b/src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs new file mode 100644 index 0000000..70cc362 --- /dev/null +++ b/src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.TokenConverter; + +public class AElfClientTokenConverterModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj b/src/AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs b/src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs new file mode 100644 index 0000000..b6e9bd1 --- /dev/null +++ b/src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.TokenHolder; + +public class AElfClientTokenHolderModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/ITokenService.cs b/src/AElf.Client.Abp.TokenManager/ITokenService.cs deleted file mode 100644 index aacd2a5..0000000 --- a/src/AElf.Client.Abp.TokenManager/ITokenService.cs +++ /dev/null @@ -1,20 +0,0 @@ -using AElf.Contracts.MultiToken; -using AElf.Contracts.NFT; -using AElf.Types; -using CreateInput = AElf.Contracts.MultiToken.CreateInput; -using GetAllowanceOutput = AElf.Contracts.MultiToken.GetAllowanceOutput; -using GetBalanceOutput = AElf.Contracts.MultiToken.GetBalanceOutput; - -namespace AElf.Client.Abp.TokenManager; - -public interface ITokenService -{ - Task CreateTokenAsync(CreateInput createInput); - Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput); - Task MintNFTAsync(MintInput mintInput); - Task SyncTokenInfoAsync(string symbol); - - Task GetTokenInfoAsync(string symbol); - Task GetTokenBalanceAsync(string symbol, Address owner); - Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender); -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs b/src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs deleted file mode 100644 index 4be0371..0000000 --- a/src/AElf.Client.Abp.TokenManager/TokenManagerOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Client.Abp.TokenManager; - -public class TokenManagerOptions -{ - public string NFTContractAddress { get; set; } -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj b/src/AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs b/src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs new file mode 100644 index 0000000..4f48dff --- /dev/null +++ b/src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Vote; + +public class AElfClientVoteModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj b/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs b/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs new file mode 100644 index 0000000..0619675 --- /dev/null +++ b/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Whitelist; + +public class AElfClientWhitelistModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElf.Client.Abp.csproj b/src/AElf.Client.Abp/AElf.Client.Abp.csproj index 7f59710..ef1e0ea 100644 --- a/src/AElf.Client.Abp/AElf.Client.Abp.csproj +++ b/src/AElf.Client.Abp/AElf.Client.Abp.csproj @@ -5,7 +5,7 @@ enable enable AElf.Client.Abp - C# sdk with abp module. + AElf C# sdk with abp module. AElf true diff --git a/src/AElf.Client/AElf.Client.csproj b/src/AElf.Client/AElf.Client.csproj index 063facb..bac79bd 100644 --- a/src/AElf.Client/AElf.Client.csproj +++ b/src/AElf.Client/AElf.Client.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/src/AElf.Client/AElfClient.Client.cs b/src/AElf.Client/AElfClient.Client.cs index f9039d8..655b57c 100644 --- a/src/AElf.Client/AElfClient.Client.cs +++ b/src/AElf.Client/AElfClient.Client.cs @@ -202,34 +202,6 @@ public KeyPairInfo GenerateKeyPairInfo() }; } - public async Task CalculateTransactionFeeBill(Transaction transaction) - { - var tokenContractAddress = - await GetContractAddressByNameAsync(HashHelper.ComputeFrom("AElf.ContractNames.Token")); - var fromAddress = GetAddressFromPrivateKey(AElfClientConstants.DefaultPrivateKey); - var toAddress = tokenContractAddress.ToBase58(); - var methodName = "GetMethodFee"; - var param = new StringValue { Value = transaction.MethodName }; - - var getMethodFeeTx = await GenerateTransactionAsync(fromAddress, toAddress, methodName, param); - var executeResult = await ExecuteTransactionAsync(new ExecuteTransactionDto - { - RawTransaction = getMethodFeeTx.ToByteArray().ToHex() - }); - - var methodFees = new MethodFees(); - methodFees.MergeFrom(ByteArrayHelper.HexStringToByteArray(executeResult)); - - var bill = new TransactionFeeBill(); - - if (methodFees.Fees.Any()) - { - var baseFees = GetBaseFeeDictionary(methodFees); - } - - return bill; - } - #region private methods private ECKeyPair GetAElfKeyPair(string? privateKeyHex) From ac44b065114512681283b27cdaae4920691dbc15 Mon Sep 17 00:00:00 2001 From: yiqi Date: Thu, 9 Jun 2022 19:17:02 +0800 Subject: [PATCH 03/21] Sync tokenInfo logic. --- examples/AEDPoSViewer/AEDPoSViewerService.cs | 4 +- examples/AEDPoSViewer/appsettings.json | 3 +- examples/TokenManager/TokenManagerService.cs | 82 ----------------- examples/TokenManager/appsettings.json | 5 +- .../AElfClientTokenModule.cs | 11 ++- .../AElfTokenConstants.cs | 4 + .../ISyncTokenInfoQueueService.cs | 6 ++ .../ISyncTokenInfoService.cs | 6 ++ src/AElf.Client.Abp.Token/ITokenService.cs | 9 +- .../SyncTokenInfoQueueService.cs | 24 +++++ .../SyncTokenInfoService.cs | 75 ++++++++++++++++ .../TokenService.Send.cs | 89 ++++++++++++++----- src/AElf.Client.Abp/AElf.Client.Abp.csproj | 7 +- .../AElfClientService.Blockchain.cs | 19 ++++ src/AElf.Client.Abp/AElfClientService.Send.cs | 10 ++- src/AElf.Client.Abp/AElfClientService.View.cs | 6 ++ src/AElf.Client.Abp/IAElfClientProvider.cs | 26 +++--- src/AElf.Client.Abp/IAElfClientService.cs | 9 +- .../Options/AElfClientConfigOptions.cs | 5 +- .../Options/AElfClientOptions.cs | 4 +- src/AElf.Client.Abp/SendTransactionResult.cs | 7 ++ .../Protobuf/token_contract.proto | 47 +++++++++- src/AElf.Client/AElfClient.Client.cs | 25 ++---- src/AElf.Client/AElfClient.cs | 12 +-- src/AElf.Client/AElfClientBuilder.cs | 16 +++- src/AElf.Client/AElfClientConstants.cs | 4 +- src/AElf.Client/Services/HttpService.cs | 42 ++++++--- test/AElf.Client.Test/ClientTest.cs | 2 +- 28 files changed, 377 insertions(+), 182 deletions(-) create mode 100644 src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs create mode 100644 src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs create mode 100644 src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs create mode 100644 src/AElf.Client.Abp.Token/SyncTokenInfoService.cs create mode 100644 src/AElf.Client.Abp/SendTransactionResult.cs diff --git a/examples/AEDPoSViewer/AEDPoSViewerService.cs b/examples/AEDPoSViewer/AEDPoSViewerService.cs index b678195..fc0569a 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerService.cs @@ -30,10 +30,10 @@ public async Task RunAsync() var clientService = scope.ServiceProvider.GetRequiredService(); var result = await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, - "GetCurrentRoundInformation", new Empty(), EndpointType.TestNetMainChain.ToString()); + "GetCurrentRoundInformation", new Empty(), EndpointType.MainNetMainChain.ToString()); var round = new Round(); round.MergeFrom(result); - Logger.LogInformation($"Current round: {round}"); + Logger.LogInformation("Current round: {Round}", round); } } \ No newline at end of file diff --git a/examples/AEDPoSViewer/appsettings.json b/examples/AEDPoSViewer/appsettings.json index 4c78fdb..91de2bc 100644 --- a/examples/AEDPoSViewer/appsettings.json +++ b/examples/AEDPoSViewer/appsettings.json @@ -39,6 +39,7 @@ }, "AElfClientConfig": { "UseClientAlias": "TestNetMainChain", - "UseAccountAlias": "Ean" + "UseAccountAlias": "Ean", + "UseCamelCase": false } } \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs index a495258..edc32ca 100644 --- a/examples/TokenManager/TokenManagerService.cs +++ b/examples/TokenManager/TokenManagerService.cs @@ -1,16 +1,9 @@ -using AElf.Client; using AElf.Client.Abp; using AElf.Client.Abp.Token; -using AElf.Client.Dto; -using AElf.Contracts.MultiToken; -using AElf.Contracts.NFT; -using AElf.Types; -using Google.Protobuf; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Serilog; using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectMapping; @@ -43,79 +36,4 @@ public async Task GetTokenInfoAsync() var tokenInfo = await _tokenService.GetTokenInfoAsync("ELF"); Logger.LogInformation("{TokenInfo}", tokenInfo.ToString()); } - - private async Task ValidateTokenInfoExistsAsync() - { - var client = new AElfClientBuilder().UsePublicEndpoint(EndpointType.TestNetMainChain).Build(); - var protocolCreateEvent = await GetNFTProtocolCreatedEventAsync(client); - - var validateTokenInfoExistsInput = new ValidateTokenInfoExistsInput - { - Symbol = protocolCreateEvent.Symbol, - TokenName = protocolCreateEvent.ProtocolName, - Decimals = 0, - IsBurnable = protocolCreateEvent.IsBurnable, - Issuer = protocolCreateEvent.Creator, - IssueChainId = protocolCreateEvent.IssueChainId, - TotalSupply = protocolCreateEvent.TotalSupply, - ExternalInfo = {protocolCreateEvent.Metadata.Value} - }; - - using var scope = ServiceScopeFactory.CreateScope(); - var clientService = scope.ServiceProvider.GetRequiredService(); - var txId = await clientService.SendSystemAsync(TokenManagerConstants.TokenSmartContractName, - "ValidateTokenInfoExists", validateTokenInfoExistsInput, EndpointType.TestNetMainChain.ToString(), - "eanz"); - Logger.LogInformation(txId); - var result = await client.GetTransactionResultAsync(txId); - Logger.LogInformation(result.Status); - Logger.LogInformation(result.Error); - } - - public async Task SyncTokenInfoAsync() - { - var client = new AElfClientBuilder().UsePublicEndpoint(EndpointType.TestNetMainChain).Build(); - var txId = _syncTokenInfoOptions.ValidateTokenInfoExistsTransactionId; - var txResult = await client.GetTransactionResultAsync(txId); - var merklePath = await client.GetMerklePathByTransactionIdAsync(txId); - - using var scope = ServiceScopeFactory.CreateScope(); - var clientService = scope.ServiceProvider.GetRequiredService(); - var tx = _objectMapper.Map(txResult.Transaction); - var crossChainCreateTokenInput = new CrossChainCreateTokenInput - { - FromChainId = AElfClientConstants.MainChainId, - MerklePath = new MerklePath - { - MerklePathNodes = - { - merklePath?.MerklePathNodes.Select(n => new MerklePathNode - { - Hash = Hash.LoadFromHex(n.Hash), - IsLeftChildNode = n.IsLeftChildNode - }) - } - }, - ParentChainHeight = txResult.BlockNumber, - TransactionBytes = tx.ToByteString() - }; - var resultTxId = await clientService.SendAsync("7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX", "CrossChainCreateToken", - crossChainCreateTokenInput, EndpointType.TestNetSidechain.ToString(), "eanz"); - - Logger.LogInformation(resultTxId); - var result = await client.GetTransactionResultAsync(resultTxId); - Logger.LogInformation(result.Status); - Logger.LogInformation(result.Error); - } - - private async Task GetNFTProtocolCreatedEventAsync(AElfClient client) - { - var transactionResultDto = await client.GetTransactionResultAsync(_syncTokenInfoOptions.CreateTransactionId); - var protocolCreated = new NFTProtocolCreated(); - var logEvent = ByteString.FromBase64(transactionResultDto.Logs.Single(l => l.Name == nameof(NFTProtocolCreated)) - .NonIndexed); - protocolCreated.MergeFrom(logEvent); - Logger.LogInformation(protocolCreated.ToString()); - return protocolCreated; - } } \ No newline at end of file diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index b2931bc..b43704c 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -50,7 +50,8 @@ "ValidateTokenInfoExistsTransactionId": "145243e8d95702d698198d2e1b65dc88ca741cef9e8a0d2436682fc366e0cf17" }, "AElfClientConfig": { - "UseClientAlias": "TestNetSidechain", - "UseAccountAlias": "Ean" + "UseClientAlias": "MainNetMainChain", + "UseAccountAlias": "Ean", + "UseCamelCase": false } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs index ddf8445..ab77b32 100644 --- a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs +++ b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs @@ -1,11 +1,13 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; using Volo.Abp.Modularity; namespace AElf.Client.Abp.Token; [DependsOn( - typeof(AElfClientModule) + typeof(AElfClientModule), + typeof(CoreAElfModule) )] public class AElfClientTokenModule : AbpModule { @@ -14,4 +16,11 @@ public override void ConfigureServices(ServiceConfigurationContext context) var configuration = context.Services.GetConfiguration(); Configure(options => { configuration.GetSection("AElfToken").Bind(options); }); } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var taskQueueManager = context.ServiceProvider.GetService(); + taskQueueManager?.CreateQueue(AElfTokenConstants.SyncTokenInfoQueueName, + AElfTokenConstants.SyncTokenInfoMaxDegreeOfParallelism); + } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs index 8410a9b..d34a8c2 100644 --- a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs +++ b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs @@ -3,4 +3,8 @@ namespace AElf.Client.Abp.Token; public class AElfTokenConstants { public const string TokenSmartContractName = "AElf.ContractNames.Token"; + public const string SyncTokenInfoQueueName = "SyncTokenInfo"; + public const int SyncTokenInfoMaxDegreeOfParallelism = int.MaxValue; + public const int TenSeconds = 10_000; + } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs b/src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs new file mode 100644 index 0000000..c6f0bf5 --- /dev/null +++ b/src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.Token; + +public interface ISyncTokenInfoQueueService +{ + void Enqueue(string symbol); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs new file mode 100644 index 0000000..e6fe8be --- /dev/null +++ b/src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.Token; + +public interface ISyncTokenInfoService +{ + Task SyncTokenInfoAsync(string symbol); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Abp.Token/ITokenService.cs index 0899745..0f21d8c 100644 --- a/src/AElf.Client.Abp.Token/ITokenService.cs +++ b/src/AElf.Client.Abp.Token/ITokenService.cs @@ -6,10 +6,11 @@ namespace AElf.Client.Abp.Token; public interface ITokenService { - Task CreateTokenAsync(Contracts.MultiToken.CreateInput createInput); - Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput); - Task MintNFTAsync(MintInput mintInput); - Task SyncTokenInfoAsync(string symbol); + Task CreateTokenAsync(Contracts.MultiToken.CreateInput createInput); + Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput); + Task MintNFTAsync(MintInput mintInput); + Task ValidateTokenInfoExistsAsync(ValidateTokenInfoExistsInput validateTokenInfoExistsInput); + Task CrossChainCreateTokenAsync(CrossChainCreateTokenInput crossChainCreateTokenInput); Task GetTokenInfoAsync(string symbol); Task GetTokenBalanceAsync(string symbol, Address owner); diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs new file mode 100644 index 0000000..450fdcc --- /dev/null +++ b/src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs @@ -0,0 +1,24 @@ +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Token; + +public class SyncTokenInfoQueueService : ISyncTokenInfoQueueService, ITransientDependency +{ + private readonly ISyncTokenInfoService _syncTokenInfoService; + private readonly ITaskQueueManager _taskQueueManager; + + public SyncTokenInfoQueueService(ISyncTokenInfoService syncTokenInfoService, + ITaskQueueManager taskQueueManager) + { + _syncTokenInfoService = syncTokenInfoService; + _taskQueueManager = taskQueueManager; + } + + public void Enqueue(string symbol) + { + _taskQueueManager.Enqueue(async () => + { + await _syncTokenInfoService.SyncTokenInfoAsync(symbol); + }, AElfTokenConstants.SyncTokenInfoQueueName); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs new file mode 100644 index 0000000..8a6f41b --- /dev/null +++ b/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs @@ -0,0 +1,75 @@ +using AElf.Client.Options; +using AElf.Contracts.MultiToken; +using AElf.Types; +using Google.Protobuf; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Token; + +public class SyncTokenInfoService : ISyncTokenInfoService, ITransientDependency +{ + private readonly ITokenService _tokenService; + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + public ILogger Logger { get; set; } + + public SyncTokenInfoService(ITokenService tokenService, IAElfClientService clientService, + IOptionsSnapshot clientConfigOptions) + { + _tokenService = tokenService; + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + + Logger = NullLogger.Instance; + } + + public async Task SyncTokenInfoAsync(string symbol) + { + var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); + var validateInput = new ValidateTokenInfoExistsInput + { + Symbol = tokenInfo.Symbol, + TokenName = tokenInfo.TokenName, + Decimals = tokenInfo.Decimals, + IsBurnable = tokenInfo.IsBurnable, + IssueChainId = tokenInfo.IssueChainId, + Issuer = tokenInfo.Issuer, + TotalSupply = tokenInfo.TotalSupply, + ExternalInfo = { tokenInfo.ExternalInfo.Value } + }; + + await Task.Delay(AElfTokenConstants.TenSeconds * 3); + + var validateResult = await _tokenService.ValidateTokenInfoExistsAsync(validateInput); + if (validateResult.TransactionResult.Status == TransactionResultStatus.Mined) + { + while (true) + { + var chainStatus = + await _clientService.GetChainStatusAsync(_clientConfigOptions.UseMainChainClientAlias); + if (chainStatus.LastIrreversibleBlockHeight - validateResult.TransactionResult.BlockNumber > 150) + break; + await Task.Delay(AElfTokenConstants.TenSeconds); + } + + var merklePath = await _clientService.GetMerklePathByTransactionIdAsync( + validateResult.TransactionResult.TransactionId.ToHex(), + _clientConfigOptions.UseMainChainClientAlias); + var createTokenParams = new CrossChainCreateTokenInput + { + FromChainId = AElfClientConstants.MainChainId, + ParentChainHeight = validateResult.TransactionResult.BlockNumber, + TransactionBytes = + ByteString.CopyFrom( + ByteArrayHelper.HexStringToByteArray(validateResult.Transaction.ToByteArray().ToHex())), + MerklePath = merklePath + }; + + var crossChainCreateTokenResult = await _tokenService.CrossChainCreateTokenAsync(createTokenParams); + Logger.LogInformation("CrossChainCreateToken: {Result}", crossChainCreateTokenResult.TransactionResult); + } + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index 5ee13a4..e0f6ec4 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -1,7 +1,7 @@ using AElf.Client.Options; +using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; using AElf.Types; -using Google.Protobuf; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using CreateInput = AElf.Contracts.MultiToken.CreateInput; @@ -11,46 +11,95 @@ namespace AElf.Client.Abp.Token; public partial class TokenService : ITokenService, ITransientDependency { private readonly IAElfClientService _clientService; - private readonly AElfTokenOptions _aElfTokenOptions; + private readonly AElfTokenOptions _tokenOptions; private readonly AElfClientConfigOptions _clientConfigOptions; public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions, IOptionsSnapshot tokenManagerOptions) { _clientService = clientService; - _aElfTokenOptions = tokenManagerOptions.Value; + _tokenOptions = tokenManagerOptions.Value; _clientConfigOptions = clientConfigOptions.Value; } - public async Task CreateTokenAsync(CreateInput createInput) + public async Task CreateTokenAsync(CreateInput createInput) { - var useClientAlias = _clientConfigOptions.UseClientAlias; - var txId = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, "Create", createInput, - useClientAlias); - var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); - return txResult; + var useClientAlias = PreferGetUseMainChainClientAlias(); + var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, "Create", + createInput, useClientAlias); + var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = txResult + }; } - public async Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput) + public async Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput) { - var useClientAlias = _clientConfigOptions.UseClientAlias; - var txId = await _clientService.SendAsync(_aElfTokenOptions.NFTContractAddress, "Create", createInput, + var useClientAlias = PreferGetUseMainChainClientAlias(); + var tx = await _clientService.SendAsync(_tokenOptions.NFTContractAddress, "Create", createInput, useClientAlias); - var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); - return txResult; + var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = txResult + }; } - public async Task MintNFTAsync(MintInput mintInput) + public async Task MintNFTAsync(MintInput mintInput) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var txId = await _clientService.SendAsync(_aElfTokenOptions.NFTContractAddress, "Mint", mintInput, + var tx = await _clientService.SendAsync(_tokenOptions.NFTContractAddress, "Mint", mintInput, useClientAlias); - var txResult = await _clientService.GetTransactionResultAsync(txId, useClientAlias); - return txResult; + var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = txResult + }; + } + + public async Task ValidateTokenInfoExistsAsync( + ValidateTokenInfoExistsInput validateTokenInfoExistsInput) + { + var useClientAlias = PreferGetUseMainChainClientAlias(); + var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, + "ValidateTokenInfoExists", validateTokenInfoExistsInput, useClientAlias); + var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = txResult + }; + } + + public async Task CrossChainCreateTokenAsync( + CrossChainCreateTokenInput crossChainCreateTokenInput) + { + var useClientAlias = PreferGetUseSidechainClientAlias(); + var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, + "CrossChainCreateToken", crossChainCreateTokenInput, useClientAlias); + var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = txResult + }; + } + + private string PreferGetUseMainChainClientAlias() + { + return string.IsNullOrEmpty(_clientConfigOptions.UseMainChainClientAlias) + ? _clientConfigOptions.UseMainChainClientAlias + : _clientConfigOptions.UseClientAlias; } - public async Task SyncTokenInfoAsync(string symbol) + private string PreferGetUseSidechainClientAlias() { - throw new NotImplementedException(); + return string.IsNullOrEmpty(_clientConfigOptions.UseSidechainClientAlias) + ? _clientConfigOptions.UseSidechainClientAlias + : _clientConfigOptions.UseClientAlias; } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElf.Client.Abp.csproj b/src/AElf.Client.Abp/AElf.Client.Abp.csproj index ef1e0ea..4d49632 100644 --- a/src/AElf.Client.Abp/AElf.Client.Abp.csproj +++ b/src/AElf.Client.Abp/AElf.Client.Abp.csproj @@ -9,14 +9,15 @@ AElf true - + + - + - + diff --git a/src/AElf.Client.Abp/AElfClientService.Blockchain.cs b/src/AElf.Client.Abp/AElfClientService.Blockchain.cs index 7042a90..75154b4 100644 --- a/src/AElf.Client.Abp/AElfClientService.Blockchain.cs +++ b/src/AElf.Client.Abp/AElfClientService.Blockchain.cs @@ -1,4 +1,5 @@ using AElf.Client.Dto; +using Microsoft.Extensions.Logging; namespace AElf.Client.Abp; @@ -29,4 +30,22 @@ public async Task GetTransactionResultAsync(string transactio return _objectMapper.Map(result!); } + + public async Task GetChainStatusAsync(string clientAlias) + { + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); + return await aelfClient.GetChainStatusAsync(); + } + + public async Task GetMerklePathByTransactionIdAsync(string transactionId, string clientAlias) + { + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); + var merklePathDto = await aelfClient.GetMerklePathByTransactionIdAsync(transactionId); + if (merklePathDto == null) + { + Logger.LogError("Cannot get merkle path of transaction {TransactionId}", transactionId); + } + + return _objectMapper.Map(merklePathDto); + } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientService.Send.cs b/src/AElf.Client.Abp/AElfClientService.Send.cs index b06001e..2f3216e 100644 --- a/src/AElf.Client.Abp/AElfClientService.Send.cs +++ b/src/AElf.Client.Abp/AElfClientService.Send.cs @@ -5,7 +5,7 @@ namespace AElf.Client.Abp; public partial class AElfClientService { - public async Task SendAsync(string contractAddress, string methodName, IMessage parameter, + public async Task SendAsync(string contractAddress, string methodName, IMessage parameter, string clientAlias, string accountAlias = "Default") { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); @@ -16,10 +16,11 @@ public async Task SendAsync(string contractAddress, string methodName, I .UseMethod(methodName) .UseParameter(parameter) .Build(); - return await PerformSendAsync(aelfClient, tx); + await PerformSendAsync(aelfClient, tx); + return tx; } - public async Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, + public async Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, string clientAlias, string accountAlias = "Default") { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); @@ -30,7 +31,8 @@ public async Task SendSystemAsync(string systemContractName, string meth .UseMethod(methodName) .UseParameter(parameter) .Build(); - return await PerformSendAsync(aelfClient, tx); + await PerformSendAsync(aelfClient, tx); + return tx; } private static async Task PerformSendAsync(AElfClient aelfClient, Transaction tx) diff --git a/src/AElf.Client.Abp/AElfClientService.View.cs b/src/AElf.Client.Abp/AElfClientService.View.cs index 185f9ce..e268bce 100644 --- a/src/AElf.Client.Abp/AElfClientService.View.cs +++ b/src/AElf.Client.Abp/AElfClientService.View.cs @@ -1,5 +1,7 @@ using AElf.Client.Dto; using Google.Protobuf; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectMapping; @@ -11,12 +13,16 @@ public partial class AElfClientService : IAElfClientService, ITransientDependenc private readonly IAElfAccountProvider _aelfAccountProvider; private readonly IObjectMapper _objectMapper; + public ILogger Logger { get; set; } + public AElfClientService(IAElfClientProvider aelfClientProvider, IAElfAccountProvider aelfAccountProvider, IObjectMapper objectMapper) { _aelfClientProvider = aelfClientProvider; _aelfAccountProvider = aelfAccountProvider; _objectMapper = objectMapper; + + Logger = NullLogger.Instance; } public async Task ViewAsync(string contractAddress, string methodName, IMessage parameter, diff --git a/src/AElf.Client.Abp/IAElfClientProvider.cs b/src/AElf.Client.Abp/IAElfClientProvider.cs index d138778..c27b8a9 100644 --- a/src/AElf.Client.Abp/IAElfClientProvider.cs +++ b/src/AElf.Client.Abp/IAElfClientProvider.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client; +namespace AElf.Client.Abp; public interface IAElfClientProvider { @@ -14,19 +14,21 @@ void SetClient(AElfClient client, string? environment = null, int? chainId = nul public class AElfClientProvider : Dictionary, IAElfClientProvider, ISingletonDependency { - public AElfClientProvider(IOptionsSnapshot aelfClientOptions) + public AElfClientProvider(IOptionsSnapshot aelfClientOptions, + IOptionsSnapshot aelfClientConfigOptions) { + var useCamelCase = aelfClientConfigOptions.Value.UseCamelCase; var clientBuilder = new AElfClientBuilder(); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetMainChain).Build(), "MainNet", - AElfClientConstants.MainChainId, "MainChain", EndpointType.MainNetMainChain.ToString()); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetSidechain).Build(), "MainNet", - AElfClientConstants.SidechainId, "Sidechain", EndpointType.MainNetSidechain.ToString()); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetMainChain).Build(), "TestNet", - AElfClientConstants.MainChainId, "MainChain", EndpointType.TestNetMainChain.ToString()); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetSidechain).Build(), "MainNet", - AElfClientConstants.SidechainId, "Sidechain", EndpointType.TestNetSidechain.ToString()); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.Local).Build(), "Local", AElfClientConstants.MainChainId, - "MainChain", EndpointType.Local.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetMainChain).UseCamelCase(useCamelCase).Build(), + "MainNet", AElfClientConstants.MainChainId, "MainChain", EndpointType.MainNetMainChain.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetSidechain).UseCamelCase(useCamelCase).Build(), + "MainNet", AElfClientConstants.SidechainId, "Sidechain", EndpointType.MainNetSidechain.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetMainChain).UseCamelCase(useCamelCase).Build(), + "TestNet", AElfClientConstants.MainChainId, "MainChain", EndpointType.TestNetMainChain.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetSidechain).UseCamelCase(useCamelCase).Build(), + "MainNet", AElfClientConstants.SidechainId, "Sidechain", EndpointType.TestNetSidechain.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.Local).UseCamelCase(useCamelCase).Build(), "Local", + AElfClientConstants.MainChainId, "MainChain", EndpointType.Local.ToString()); foreach (var clientConfig in aelfClientOptions.Value.ClientConfigList) { diff --git a/src/AElf.Client.Abp/IAElfClientService.cs b/src/AElf.Client.Abp/IAElfClientService.cs index 04400f5..09ab648 100644 --- a/src/AElf.Client.Abp/IAElfClientService.cs +++ b/src/AElf.Client.Abp/IAElfClientService.cs @@ -1,3 +1,4 @@ +using AElf.Client.Dto; using Google.Protobuf; namespace AElf.Client.Abp; @@ -10,11 +11,15 @@ Task ViewAsync(string contractAddress, string methodName, IMessage param Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, string clientAlias, string accountAlias = "Default"); - Task SendAsync(string contractAddress, string methodName, IMessage parameter, + Task SendAsync(string contractAddress, string methodName, IMessage parameter, string clientAlias, string accountAlias = "Default"); - Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, + Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, string clientAlias, string accountAlias = "Default"); Task GetTransactionResultAsync(string transactionId, string clientAlias); + + Task GetChainStatusAsync(string clientAlias); + + Task GetMerklePathByTransactionIdAsync(string transactionId, string clientAlias); } \ No newline at end of file diff --git a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs b/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs index 9c00c0e..2628eb9 100644 --- a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs +++ b/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs @@ -2,6 +2,9 @@ namespace AElf.Client.Options; public class AElfClientConfigOptions { - public string UseClientAlias { get; set; } + public string UseClientAlias { get; set; } = "TestNetSidechain"; + public string UseMainChainClientAlias { get; set; } = "TestNetMainChain"; + public string UseSidechainClientAlias { get; set; } = "TestNetSidechain"; public string UseAccountAlias { get; set; } = "Default"; + public bool UseCamelCase { get; set; } = false; } \ No newline at end of file diff --git a/src/AElf.Client.Abp/Options/AElfClientOptions.cs b/src/AElf.Client.Abp/Options/AElfClientOptions.cs index 1caf518..3d921ad 100644 --- a/src/AElf.Client.Abp/Options/AElfClientOptions.cs +++ b/src/AElf.Client.Abp/Options/AElfClientOptions.cs @@ -9,7 +9,7 @@ public class ClientConfig { public string Alias { get; set; } public string Endpoint { get; set; } - public string UserName { get; set; } - public string Password { get; set; } + public string? UserName { get; set; } + public string? Password { get; set; } public int Timeout { get; set; } = 60; } \ No newline at end of file diff --git a/src/AElf.Client.Abp/SendTransactionResult.cs b/src/AElf.Client.Abp/SendTransactionResult.cs new file mode 100644 index 0000000..81f8104 --- /dev/null +++ b/src/AElf.Client.Abp/SendTransactionResult.cs @@ -0,0 +1,7 @@ +namespace AElf.Client.Abp; + +public class SendTransactionResult +{ + public TransactionResult TransactionResult { get; set; } + public Transaction Transaction { get; set; } +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/Protobuf/token_contract.proto b/src/AElf.Client.Protobuf/Protobuf/token_contract.proto index 93d1433..90c1945 100644 --- a/src/AElf.Client.Protobuf/Protobuf/token_contract.proto +++ b/src/AElf.Client.Protobuf/Protobuf/token_contract.proto @@ -124,7 +124,15 @@ service TokenContract { // This method is used to initialize the governance organization for some functions, // including: the coefficient of the user transaction fee calculation formula, // the coefficient of the contract developer resource fee calculation formula, and the side chain rental fee. - rpc InitializeAuthorizedController(google.protobuf.Empty) returns (google.protobuf.Empty){ + rpc InitializeAuthorizedController (google.protobuf.Empty) returns (google.protobuf.Empty){ + } + + rpc ResetExternalInfo (ResetExternalInfoInput) returns (google.protobuf.Empty){ + } + + rpc AddAddressToCreateTokenWhiteList (aelf.Address) returns (google.protobuf.Empty) { + } + rpc RemoveAddressFromCreateTokenWhiteList (aelf.Address) returns (google.protobuf.Empty) { } // Query token information. @@ -200,6 +208,12 @@ service TokenContract { rpc IsTokenAvailableForMethodFee (google.protobuf.StringValue) returns (google.protobuf.BoolValue) { option (aelf.is_view) = true; } + rpc IsInCreateTokenWhiteList (aelf.Address) returns (google.protobuf.BoolValue) { + option (aelf.is_view) = true; + } + rpc GetReservedExternalInfoKeyList (google.protobuf.Empty) returns (StringList) { + option (aelf.is_view) = true; + } } message TokenInfo { @@ -221,6 +235,12 @@ message TokenInfo { int32 issue_chain_id = 8; // The amount of issued tokens. int64 issued = 9; + // The external information of the token. + ExternalInfo external_info = 10; +} + +message ExternalInfo { + map value = 1; } message CreateInput { @@ -240,6 +260,8 @@ message CreateInput { repeated aelf.Address lock_white_list = 7; // The chain id of the token. int32 issue_chain_id = 8; + // The external information of the token. + ExternalInfo external_info = 9; } message SetPrimaryTokenSymbolInput { @@ -462,6 +484,11 @@ message ChargeTransactionFeesOutput { string charging_information = 2; } +message CallbackInfo { + aelf.Address contract_address = 1; + string method_name = 2; +} + message ExtraTokenListModified { option (aelf.is_event) = true; // Transaction fee token information. @@ -592,6 +619,15 @@ message ChangeTokenIssuerInput aelf.Address new_token_Issuer = 2; } +message ResetExternalInfoInput { + string symbol = 1; + ExternalInfo external_info = 2; +} + +message StringList { + repeated string value = 1; +} + message Transferred { option (aelf.is_event) = true; // The source address of the transferred token. @@ -647,7 +683,6 @@ message ChainPrimaryTokenSymbolSet { string token_symbol = 1; } - message CalculateFeeAlgorithmUpdated { option (aelf.is_event) = true; // All calculate fee coefficients after modification. @@ -686,6 +721,8 @@ message TokenCreated { bool is_burnable = 6; // The chain id of the token. int32 issue_chain_id = 7; + // The external information of the token. + ExternalInfo external_info = 8; } message Issued { @@ -736,4 +773,10 @@ message CrossChainReceived { int32 issue_chain_id = 7; // The parent chain height of the transfer transaction. int64 parent_chain_height = 8; +} + +message ExternalInfoChanged { + option (aelf.is_event) = true; + string symbol = 1; + ExternalInfo external_info = 2; } \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.Client.cs b/src/AElf.Client/AElfClient.Client.cs index 655b57c..fd455c2 100644 --- a/src/AElf.Client/AElfClient.Client.cs +++ b/src/AElf.Client/AElfClient.Client.cs @@ -2,10 +2,8 @@ using AElf.Client.Extensions; using AElf.Client.Model; using AElf.Client.Services; -using AElf.Contracts.MultiToken; using AElf.Cryptography; using AElf.Cryptography.ECDSA; -using AElf.Standards.ACS1; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -21,8 +19,8 @@ public async Task IsConnectedAsync() { try { - var chainStatus = await GetChainStatusAsync(); - return chainStatus != null; + await GetChainStatusAsync(); + return true; } catch (Exception) { @@ -37,7 +35,7 @@ public async Task IsConnectedAsync() public async Task GetGenesisContractAddressAsync() { var statusDto = await GetChainStatusAsync(); - var genesisAddress = statusDto?.GenesisContractAddress; + var genesisAddress = statusDto.GenesisContractAddress; return genesisAddress; } @@ -120,7 +118,7 @@ public async Task GetFormattedAddressAsync(Address address) }); var symbol = StringValue.Parser.ParseFrom(ByteArrayHelper.HexStringToByteArray(result)); - var chainIdString = (await GetChainStatusAsync())?.ChainId; + var chainIdString = (await GetChainStatusAsync()).ChainId; return $"{symbol.Value}_{address.ToBase58()}_{chainIdString}"; } @@ -214,7 +212,8 @@ private ECKeyPair GetAElfKeyPair(string? privateKeyHex) private string GetRequestUrl(string baseUrl, string relativeUrl) { - return new Uri(new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/")), relativeUrl).ToString(); + var uri = new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/")); + return new Uri(uri, relativeUrl).ToString(); } private void AssertValidAddress(params string?[] addresses) @@ -262,17 +261,5 @@ private void AssertValidTransactionId(params string[] transactionIds) } } - private Dictionary GetBaseFeeDictionary(MethodFees methodFees) - { - var dict = new Dictionary(); - foreach (var methodFee in methodFees.Fees) - if (dict.ContainsKey(methodFee.Symbol)) - dict[methodFee.Symbol] += methodFee.BasicFee; - else - dict[methodFee.Symbol] = methodFee.BasicFee; - - return dict; - } - #endregion } \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.cs b/src/AElf.Client/AElfClient.cs index 218e1f7..b24163f 100644 --- a/src/AElf.Client/AElfClient.cs +++ b/src/AElf.Client/AElfClient.cs @@ -1,5 +1,4 @@ -using System.Text.Json; -using AElf.Client.Services; +using AElf.Client.Services; namespace AElf.Client; @@ -7,12 +6,13 @@ public partial class AElfClient : IDisposable { private readonly IHttpService _httpService; private readonly string _baseUrl; - private readonly string _userName; - private readonly string _password; + private readonly string? _userName; + private readonly string? _password; - public AElfClient(string baseUrl, int timeOut = 60, string userName = null, string password = null) + public AElfClient(string baseUrl, int timeOut = 60, string? userName = null, string? password = null, + bool useCamelCase = false) { - _httpService = new HttpService(timeOut); + _httpService = new HttpService(timeOut, useCamelCase); _baseUrl = baseUrl; _userName = userName; _password = password; diff --git a/src/AElf.Client/AElfClientBuilder.cs b/src/AElf.Client/AElfClientBuilder.cs index c2a04fe..e0ae620 100644 --- a/src/AElf.Client/AElfClientBuilder.cs +++ b/src/AElf.Client/AElfClientBuilder.cs @@ -5,8 +5,10 @@ public sealed class AElfClientBuilder private string NodeEndpoint { get; set; } private int Timeout { get; set; } - private string UserName { get; set; } - private string Password { get; set; } + private string? UserName { get; set; } + private string? Password { get; set; } + + private bool IsUseCamelCase { get; set; } public AElfClientBuilder() { @@ -51,15 +53,21 @@ public AElfClientBuilder SetHttpTimeout(int timeout) return this; } - public AElfClientBuilder ManagePeerInfo(string userName, string password) + public AElfClientBuilder ManagePeerInfo(string? userName, string? password) { UserName = userName; Password = password; return this; } + public AElfClientBuilder UseCamelCase(bool isUseCamelCase) + { + IsUseCamelCase = isUseCamelCase; + return this; + } + public AElfClient Build() { - return new AElfClient(NodeEndpoint, Timeout, UserName, Password); + return new AElfClient(NodeEndpoint, Timeout, UserName, Password, IsUseCamelCase); } } \ No newline at end of file diff --git a/src/AElf.Client/AElfClientConstants.cs b/src/AElf.Client/AElfClientConstants.cs index 7fe104e..2103de6 100644 --- a/src/AElf.Client/AElfClientConstants.cs +++ b/src/AElf.Client/AElfClientConstants.cs @@ -5,9 +5,9 @@ public class AElfClientConstants public const string DefaultPrivateKey = "09da44778f8db2e602fb484334f37df19e221c84c4582ce5b7770ccfbc3ddbef"; public const string LocalEndpoint = "http://127.0.0.1:1726"; public const string MainNetMainChain = "https://aelf-public-node.aelf.io"; - public const string MainNetSidechain = "https://explorer-.aelf.io"; + public const string MainNetSidechain = "https://tdvv-public-node.aelf.io"; public const string TestNetMainChain = "https://aelf-test-node.aelf.io"; - public const string TestNetSidechain = "https:/tdvv-test-node.aelf.io"; + public const string TestNetSidechain = "https://tdvv-test-node.aelf.io"; public const int MainChainId = 9992731; public const int SidechainId = 1866392; } \ No newline at end of file diff --git a/src/AElf.Client/Services/HttpService.cs b/src/AElf.Client/Services/HttpService.cs index 1c6a79c..388d59c 100644 --- a/src/AElf.Client/Services/HttpService.cs +++ b/src/AElf.Client/Services/HttpService.cs @@ -16,16 +16,18 @@ public interface IHttpService Task DeleteResponseAsObjectAsync(string url, string? version = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, - AuthenticationHeaderValue authenticationHeaderValue = null); + AuthenticationHeaderValue? authenticationHeaderValue = null); } public class HttpService : IHttpService { - private HttpClient Client { get; set; } + private readonly bool _useCamelCase; + private HttpClient? Client { get; set; } private int TimeoutSeconds { get; } - public HttpService(int timeoutSeconds) + public HttpService(int timeoutSeconds, bool useCamelCase = false) { + _useCamelCase = useCamelCase; TimeoutSeconds = timeoutSeconds; } @@ -42,10 +44,13 @@ public HttpService(int timeoutSeconds) { var response = await GetResponseAsync(url, version, expectedStatusCode); var stream = await response.Content.ReadAsStreamAsync(); - return await JsonSerializer.DeserializeAsync(stream, options:new JsonSerializerOptions - { - //PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }); + var jsonSerializerOptions = _useCamelCase + ? new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + } + : new JsonSerializerOptions(); + return await JsonSerializer.DeserializeAsync(stream, jsonSerializerOptions); } /// @@ -66,7 +71,13 @@ public HttpService(int timeoutSeconds) var response = await PostResponseAsync(url, parameters, version, true, expectedStatusCode, authenticationHeaderValue); var stream = await response.Content.ReadAsStreamAsync(); - return await JsonSerializer.DeserializeAsync(stream); + var jsonSerializerOptions = _useCamelCase + ? new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + } + : new JsonSerializerOptions(); + return await JsonSerializer.DeserializeAsync(stream, jsonSerializerOptions); } /// @@ -75,16 +86,23 @@ public HttpService(int timeoutSeconds) /// /// /// + /// /// /// /// public async Task DeleteResponseAsObjectAsync(string url, string? version = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, - AuthenticationHeaderValue authenticationHeaderValue = null) + AuthenticationHeaderValue? authenticationHeaderValue = null) { var response = await DeleteResponseAsync(url, version, expectedStatusCode, authenticationHeaderValue); var stream = await response.Content.ReadAsStreamAsync(); - return await JsonSerializer.DeserializeAsync(stream); + var jsonSerializerOptions = _useCamelCase + ? new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + } + : new JsonSerializerOptions(); + return await JsonSerializer.DeserializeAsync(stream, jsonSerializerOptions); } #region GetResponse @@ -161,7 +179,7 @@ private async Task PostResponseAsync(string url, private async Task DeleteResponseAsStringAsync(string url, string? version = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, - AuthenticationHeaderValue authenticationHeaderValue = null) + AuthenticationHeaderValue? authenticationHeaderValue = null) { var response = await DeleteResponseAsync(url, version, expectedStatusCode, authenticationHeaderValue); return await response.Content.ReadAsStringAsync(); @@ -169,7 +187,7 @@ private async Task DeleteResponseAsStringAsync(string url, string? versi private async Task DeleteResponseAsync(string url, string? version = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, - AuthenticationHeaderValue authenticationHeaderValue = null) + AuthenticationHeaderValue? authenticationHeaderValue = null) { version = !string.IsNullOrWhiteSpace(version) ? $";v={version}" : string.Empty; var client = GetHttpClient(version); diff --git a/test/AElf.Client.Test/ClientTest.cs b/test/AElf.Client.Test/ClientTest.cs index ab2c51f..e91b4c7 100644 --- a/test/AElf.Client.Test/ClientTest.cs +++ b/test/AElf.Client.Test/ClientTest.cs @@ -84,7 +84,7 @@ public async Task GetBlock_Test() public async Task GetBlockByHeight_Failed_Test() { const int timeOut = 60; - var httpService = new HttpService(timeOut); + var httpService = new HttpService(timeOut, false); const int heightNotExist = int.MaxValue; var errorResponse = await httpService.GetResponseAsync( $"{BaseUrl}/api/blockChain/blockByHeight?blockHeight={heightNotExist}&includeTransactions=false", From 9168f22943d267823860c90bf27cdda4f8c5ef48 Mon Sep 17 00:00:00 2001 From: yiqi Date: Fri, 10 Jun 2022 16:17:35 +0800 Subject: [PATCH 04/21] Tune SyncTokenInfoService --- .../TokenManager/TokenManagerHostedService.cs | 2 +- examples/TokenManager/TokenManagerService.cs | 9 + examples/TokenManager/appsettings.json | 6 +- .../AElfTokenConstants.cs | 2 +- .../SyncTokenInfoService.cs | 6 +- .../TokenService.Send.cs | 15 +- .../Profile/MerklePathProfile.cs | 2 + .../Profile/TransactionProfile.cs | 8 +- src/AElf.Client/AElfClient.Transaction.cs | 276 +++++++++--------- 9 files changed, 173 insertions(+), 153 deletions(-) diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs index 544bcfc..9d73968 100644 --- a/examples/TokenManager/TokenManagerHostedService.cs +++ b/examples/TokenManager/TokenManagerHostedService.cs @@ -33,7 +33,7 @@ public async Task StartAsync(CancellationToken cancellationToken) await _abpApplication.InitializeAsync(); var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); - await tokenManagerService.GetTokenInfoAsync(); + await tokenManagerService.SyncTokenInfoAsync(); } public async Task StopAsync(CancellationToken cancellationToken) diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs index edc32ca..d743f52 100644 --- a/examples/TokenManager/TokenManagerService.cs +++ b/examples/TokenManager/TokenManagerService.cs @@ -12,6 +12,7 @@ namespace TokenManager; public class TokenManagerService : ITransientDependency { private readonly ITokenService _tokenService; + private readonly ISyncTokenInfoQueueService _syncTokenInfoQueueService; private readonly IObjectMapper _objectMapper; private readonly SyncTokenInfoOptions _syncTokenInfoOptions; private IServiceScopeFactory ServiceScopeFactory { get; } @@ -20,10 +21,12 @@ public class TokenManagerService : ITransientDependency public TokenManagerService(IServiceScopeFactory serviceScopeFactory, ITokenService tokenService, + ISyncTokenInfoQueueService syncTokenInfoQueueService, IObjectMapper objectMapper, IOptionsSnapshot syncTokenInfoOptions) { _tokenService = tokenService; + _syncTokenInfoQueueService = syncTokenInfoQueueService; _objectMapper = objectMapper; _syncTokenInfoOptions = syncTokenInfoOptions.Value; ServiceScopeFactory = serviceScopeFactory; @@ -36,4 +39,10 @@ public async Task GetTokenInfoAsync() var tokenInfo = await _tokenService.GetTokenInfoAsync("ELF"); Logger.LogInformation("{TokenInfo}", tokenInfo.ToString()); } + + public async Task SyncTokenInfoAsync() + { + _syncTokenInfoQueueService.Enqueue("JUNETEN"); + Logger.LogInformation("Enqueued"); + } } \ No newline at end of file diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index b43704c..e59f3da 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -50,8 +50,10 @@ "ValidateTokenInfoExistsTransactionId": "145243e8d95702d698198d2e1b65dc88ca741cef9e8a0d2436682fc366e0cf17" }, "AElfClientConfig": { - "UseClientAlias": "MainNetMainChain", - "UseAccountAlias": "Ean", + "UseClientAlias": "TestNetMainChain", + "UseMainChainClientAlias": "TestNetMainChain", + "UseSidechainClientAlias": "TestNetSidechain", + "UseAccountAlias": "eanz", "UseCamelCase": false } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs index d34a8c2..6303a43 100644 --- a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs +++ b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs @@ -6,5 +6,5 @@ public class AElfTokenConstants public const string SyncTokenInfoQueueName = "SyncTokenInfo"; public const int SyncTokenInfoMaxDegreeOfParallelism = int.MaxValue; public const int TenSeconds = 10_000; - + public const string TestNetSidechainMultiTokenContractAddress = "7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX"; } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs index 8a6f41b..70f56a0 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs @@ -41,15 +41,17 @@ public async Task SyncTokenInfoAsync(string symbol) ExternalInfo = { tokenInfo.ExternalInfo.Value } }; - await Task.Delay(AElfTokenConstants.TenSeconds * 3); - var validateResult = await _tokenService.ValidateTokenInfoExistsAsync(validateInput); + Logger.LogInformation("ValidateTokenInfoExists: {Result}", validateResult.TransactionResult); if (validateResult.TransactionResult.Status == TransactionResultStatus.Mined) { while (true) { var chainStatus = await _clientService.GetChainStatusAsync(_clientConfigOptions.UseMainChainClientAlias); + Logger.LogInformation( + "Main chain lib height: {LibHeight}, Validate tx package height: {ValidateHeight}", + chainStatus.LastIrreversibleBlockHeight, validateResult.TransactionResult.BlockNumber); if (chainStatus.LastIrreversibleBlockHeight - validateResult.TransactionResult.BlockNumber > 150) break; await Task.Delay(AElfTokenConstants.TenSeconds); diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index e0f6ec4..00e576f 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -39,7 +39,7 @@ public async Task CreateNFTProtocolAsync(Contracts.NFT.Cr { var useClientAlias = PreferGetUseMainChainClientAlias(); var tx = await _clientService.SendAsync(_tokenOptions.NFTContractAddress, "Create", createInput, - useClientAlias); + useClientAlias, _clientConfigOptions.UseAccountAlias); var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); return new SendTransactionResult { @@ -52,7 +52,7 @@ public async Task MintNFTAsync(MintInput mintInput) { var useClientAlias = _clientConfigOptions.UseClientAlias; var tx = await _clientService.SendAsync(_tokenOptions.NFTContractAddress, "Mint", mintInput, - useClientAlias); + useClientAlias, _clientConfigOptions.UseAccountAlias); var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); return new SendTransactionResult { @@ -66,7 +66,8 @@ public async Task ValidateTokenInfoExistsAsync( { var useClientAlias = PreferGetUseMainChainClientAlias(); var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, - "ValidateTokenInfoExists", validateTokenInfoExistsInput, useClientAlias); + "ValidateTokenInfoExists", validateTokenInfoExistsInput, useClientAlias, + _clientConfigOptions.UseAccountAlias); var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); return new SendTransactionResult { @@ -79,8 +80,8 @@ public async Task CrossChainCreateTokenAsync( CrossChainCreateTokenInput crossChainCreateTokenInput) { var useClientAlias = PreferGetUseSidechainClientAlias(); - var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, - "CrossChainCreateToken", crossChainCreateTokenInput, useClientAlias); + var tx = await _clientService.SendAsync(AElfTokenConstants.TestNetSidechainMultiTokenContractAddress, + "CrossChainCreateToken", crossChainCreateTokenInput, useClientAlias, _clientConfigOptions.UseAccountAlias); var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); return new SendTransactionResult { @@ -91,14 +92,14 @@ public async Task CrossChainCreateTokenAsync( private string PreferGetUseMainChainClientAlias() { - return string.IsNullOrEmpty(_clientConfigOptions.UseMainChainClientAlias) + return !string.IsNullOrEmpty(_clientConfigOptions.UseMainChainClientAlias) ? _clientConfigOptions.UseMainChainClientAlias : _clientConfigOptions.UseClientAlias; } private string PreferGetUseSidechainClientAlias() { - return string.IsNullOrEmpty(_clientConfigOptions.UseSidechainClientAlias) + return !string.IsNullOrEmpty(_clientConfigOptions.UseSidechainClientAlias) ? _clientConfigOptions.UseSidechainClientAlias : _clientConfigOptions.UseClientAlias; } diff --git a/src/AElf.Client.Abp/Profile/MerklePathProfile.cs b/src/AElf.Client.Abp/Profile/MerklePathProfile.cs index d8b2a75..5574786 100644 --- a/src/AElf.Client.Abp/Profile/MerklePathProfile.cs +++ b/src/AElf.Client.Abp/Profile/MerklePathProfile.cs @@ -8,7 +8,9 @@ public class MerklePathProfile : Profile public MerklePathProfile() { CreateMap(); + CreateMap(); CreateMap(); + CreateMap(); } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/Profile/TransactionProfile.cs b/src/AElf.Client.Abp/Profile/TransactionProfile.cs index fce5de8..7027959 100644 --- a/src/AElf.Client.Abp/Profile/TransactionProfile.cs +++ b/src/AElf.Client.Abp/Profile/TransactionProfile.cs @@ -32,6 +32,7 @@ public TransactionProfile() CreateMap() .ForMember(d => d.ReturnValue, opt => opt.MapFrom(s => ByteString.CopyFrom(ByteArrayHelper.HexStringToByteArray(s.ReturnValue)))) + .ForMember(d => d.BlockHash, opt => opt.MapFrom(s => Hash.LoadFromHex(s.BlockHash))) .ForMember(d => d.Bloom, opt => opt.MapFrom(s => s.Status.ToUpper() == TransactionResultStatus.NotExisted.ToString().ToUpper() ? null @@ -40,10 +41,13 @@ public TransactionProfile() : ByteString.FromBase64(s.Bloom))) .ForMember(d => d.Status, opt => opt.MapFrom(s => - Enum.TryParse(s.Status, out status) + Enum.TryParse($"{s.Status[0]}{s.Status.Substring(1).ToLower()}", out status) ? status - : TransactionResultStatus.NotExisted)); + : TransactionResultStatus.NotExisted)) + .ForMember(d => d.Logs, opt => opt.MapFrom(s => s.Logs)) + .Ignore(d => d.Error); + CreateMap(); CreateMap(); } } diff --git a/src/AElf.Client/AElfClient.Transaction.cs b/src/AElf.Client/AElfClient.Transaction.cs index d1b6b4a..5afbc16 100644 --- a/src/AElf.Client/AElfClient.Transaction.cs +++ b/src/AElf.Client/AElfClient.Transaction.cs @@ -6,160 +6,160 @@ namespace AElf.Client; public partial class AElfClient : ITransactionAppService { /// - /// Get information about the current transaction pool. - /// - /// TransactionPoolStatusOutput - public async Task GetTransactionPoolStatusAsync() - { - var url = GetRequestUrl(_baseUrl, "api/blockChain/transactionPoolStatus"); - return await _httpService.GetResponseAsync(url); - } + /// Get information about the current transaction pool. + /// + /// TransactionPoolStatusOutput + public async Task GetTransactionPoolStatusAsync() + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/transactionPoolStatus"); + return await _httpService.GetResponseAsync(url); + } - /// - /// Call a read-only method of a contract. - /// - /// - /// - public async Task ExecuteTransactionAsync(ExecuteTransactionDto input) + /// + /// Call a read-only method of a contract. + /// + /// + /// + public async Task ExecuteTransactionAsync(ExecuteTransactionDto input) + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/executeTransaction"); + var parameters = new Dictionary { - var url = GetRequestUrl(_baseUrl, "api/blockChain/executeTransaction"); - var parameters = new Dictionary - { - {"RawTransaction", input.RawTransaction} - }; - - var result = await _httpService.PostResponseAsync(url, parameters); + { "RawTransaction", input.RawTransaction } + }; - if (result == null) - { - throw new AElfClientException("Failed to execute tx."); - } + var result = await _httpService.PostResponseAsync(url, parameters); - return result; - } - - /// - /// Call a method of a contract by given serialized strings. - /// - /// - /// Serialized result - public async Task ExecuteRawTransactionAsync(ExecuteRawTransactionDto input) + if (result == null) { - var url = GetRequestUrl(_baseUrl, "api/blockChain/executeRawTransaction"); - var parameters = new Dictionary - { - {"RawTransaction", input.RawTransaction}, - {"Signature", input.Signature} - }; - - return await _httpService.PostResponseAsync(url, parameters); + throw new AElfClientException("Failed to execute tx."); } - /// - /// Creates an unsigned serialized transaction. - /// - /// - /// CreateRawTransactionOutput - public async Task CreateRawTransactionAsync(CreateRawTransactionInput input) - { - var url = GetRequestUrl(_baseUrl, "api/blockChain/rawTransaction"); - var parameters = new Dictionary - { - {"From", input.From}, - {"To", input.To}, - {"RefBlockNumber", input.RefBlockNumber.ToString()}, - {"RefBlockHash", input.RefBlockHash}, - {"MethodName", input.MethodName}, - {"Params", input.Params} - }; - - return await _httpService.PostResponseAsync(url, parameters); - } + return result; + } - /// - /// Broadcast a serialized transaction. - /// - /// - /// SendRawTransactionOutput - public async Task SendRawTransactionAsync(SendRawTransactionInput input) + /// + /// Call a method of a contract by given serialized strings. + /// + /// + /// Serialized result + public async Task ExecuteRawTransactionAsync(ExecuteRawTransactionDto input) + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/executeRawTransaction"); + var parameters = new Dictionary { - var url = GetRequestUrl(_baseUrl, "api/blockChain/sendRawTransaction"); - var parameters = new Dictionary - { - {"Transaction", input.Transaction}, - {"Signature", input.Signature}, - {"ReturnTransaction", input.ReturnTransaction ? "true" : "false"} - }; - return await _httpService.PostResponseAsync(url, parameters); - } + { "RawTransaction", input.RawTransaction }, + { "Signature", input.Signature } + }; - /// - /// Broadcast a transaction. - /// - /// - /// TransactionId - public async Task SendTransactionAsync(SendTransactionInput input) - { - var url = GetRequestUrl(_baseUrl, "api/blockChain/sendTransaction"); - var parameters = new Dictionary - { - {"RawTransaction", input.RawTransaction} - }; - return await _httpService.PostResponseAsync(url, parameters); - } + return await _httpService.PostResponseAsync(url, parameters); + } - /// - /// Broadcast volume transactions. - /// - /// - /// TransactionIds - public async Task SendTransactionsAsync(SendTransactionsInput input) + /// + /// Creates an unsigned serialized transaction. + /// + /// + /// CreateRawTransactionOutput + public async Task CreateRawTransactionAsync(CreateRawTransactionInput input) + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/rawTransaction"); + var parameters = new Dictionary { - var url = GetRequestUrl(_baseUrl, "api/blockChain/sendTransactions"); - var parameters = new Dictionary - { - {"RawTransactions", input.RawTransactions} - }; - return await _httpService.PostResponseAsync(url, parameters); - } + { "From", input.From }, + { "To", input.To }, + { "RefBlockNumber", input.RefBlockNumber.ToString() }, + { "RefBlockHash", input.RefBlockHash }, + { "MethodName", input.MethodName }, + { "Params", input.Params } + }; - /// - /// Gets the result of transaction execution by the given transactionId. - /// - /// - /// TransactionResultDto - public async Task GetTransactionResultAsync(string transactionId) + return await _httpService.PostResponseAsync(url, parameters); + } + + /// + /// Broadcast a serialized transaction. + /// + /// + /// SendRawTransactionOutput + public async Task SendRawTransactionAsync(SendRawTransactionInput input) + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/sendRawTransaction"); + var parameters = new Dictionary { - AssertValidTransactionId(transactionId); - var url = GetRequestUrl(_baseUrl, $"api/blockChain/transactionResult?transactionId={transactionId}"); - return await _httpService.GetResponseAsync(url); - } + { "Transaction", input.Transaction }, + { "Signature", input.Signature }, + { "ReturnTransaction", input.ReturnTransaction ? "true" : "false" } + }; + return await _httpService.PostResponseAsync(url, parameters); + } - /// - /// Get results of multiple transactions by specified blockHash and the offset. - /// - /// - /// - /// - /// TransactionResultDtos - public async Task?> GetTransactionResultsAsync(string blockHash, int offset = 0, - int limit = 10) + /// + /// Broadcast a transaction. + /// + /// + /// TransactionId + public async Task SendTransactionAsync(SendTransactionInput input) + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/sendTransaction"); + var parameters = new Dictionary { - AssertValidHash(blockHash); - var url = GetRequestUrl(_baseUrl, - $"api/blockChain/transactionResults?blockHash={blockHash}&offset={offset}&limit={limit}"); - return await _httpService.GetResponseAsync>(url); - } + { "RawTransaction", input.RawTransaction } + }; + return await _httpService.PostResponseAsync(url, parameters); + } - /// - /// Get merkle path of a transaction. - /// - /// - /// MerklePathDto - public async Task GetMerklePathByTransactionIdAsync(string transactionId) + /// + /// Broadcast volume transactions. + /// + /// + /// TransactionIds + public async Task SendTransactionsAsync(SendTransactionsInput input) + { + var url = GetRequestUrl(_baseUrl, "api/blockChain/sendTransactions"); + var parameters = new Dictionary { - AssertValidTransactionId(transactionId); - var url = GetRequestUrl(_baseUrl, $"api/blockChain/merklePathByTransactionId?transactionId={transactionId}"); - return await _httpService.GetResponseAsync(url); - } + { "RawTransactions", input.RawTransactions } + }; + return await _httpService.PostResponseAsync(url, parameters); + } + + /// + /// Gets the result of transaction execution by the given transactionId. + /// + /// + /// TransactionResultDto + public async Task GetTransactionResultAsync(string transactionId) + { + AssertValidTransactionId(transactionId); + var url = GetRequestUrl(_baseUrl, $"api/blockChain/transactionResult?transactionId={transactionId}"); + return await _httpService.GetResponseAsync(url); + } + + /// + /// Get results of multiple transactions by specified blockHash and the offset. + /// + /// + /// + /// + /// TransactionResultDtos + public async Task?> GetTransactionResultsAsync(string blockHash, int offset = 0, + int limit = 10) + { + AssertValidHash(blockHash); + var url = GetRequestUrl(_baseUrl, + $"api/blockChain/transactionResults?blockHash={blockHash}&offset={offset}&limit={limit}"); + return await _httpService.GetResponseAsync>(url); + } + + /// + /// Get merkle path of a transaction. + /// + /// + /// MerklePathDto + public async Task GetMerklePathByTransactionIdAsync(string transactionId) + { + AssertValidTransactionId(transactionId); + var url = GetRequestUrl(_baseUrl, $"api/blockChain/merklePathByTransactionId?transactionId={transactionId}"); + return await _httpService.GetResponseAsync(url); + } } \ No newline at end of file From efa026b9b4c3ecb0e84e6c009f0b4a0b670df4dc Mon Sep 17 00:00:00 2001 From: yiqi Date: Fri, 10 Jun 2022 16:29:20 +0800 Subject: [PATCH 05/21] Fix ci config --- azure-pipelines.yml | 6 +++--- build.config | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 464e1d0..3f22733 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ jobs: - task: UseDotNet@2 displayName: 'Install .NET Core SDK' inputs: - version: 3.1.101 + version: 6.0.300 - powershell: ./scripts/aelf-node/start-window.ps1 displayName: 'Build and Test' # All tasks on Linux @@ -25,7 +25,7 @@ jobs: steps: - task: DotNetCoreInstaller@0 inputs: - version: '3.1.101' + version: '6.0.300' - script: cd scripts/aelf-node && bash start.sh displayName: 'Deploy a full node' - script: bash build.sh -target=test @@ -40,7 +40,7 @@ jobs: steps: - task: DotNetCoreInstaller@0 inputs: - version: '3.1.101' + version: '6.0.300' - script: cd scripts/aelf-node && bash start-mac.sh displayName: 'Deploy a full node' - script: bash build.sh -target=test diff --git a/build.config b/build.config index 803c029..015ef8e 100644 --- a/build.config +++ b/build.config @@ -1,3 +1,3 @@ #!/usr/bin/env bash CAKE_VERSION=0.37.0 -DOTNET_VERSION=3.1.101 +DOTNET_VERSION=6.0.300 From 42152b7ccab9072e0f6a7dd00289acc6ec9d634c Mon Sep 17 00:00:00 2001 From: yiqi Date: Mon, 13 Jun 2022 13:16:08 +0800 Subject: [PATCH 06/21] Token Service impl. --- examples/TokenManager/Program.cs | 4 +- examples/TokenManager/SyncTokenInfoOptions.cs | 7 -- .../TokenManager/TokenManagerHostedService.cs | 2 +- examples/TokenManager/TokenManagerModule.cs | 2 - examples/TokenManager/TokenManagerService.cs | 44 +++++++---- examples/TokenManager/appsettings.json | 6 +- .../AElfClientTokenModule.cs | 4 +- .../AElfTokenConstants.cs | 3 +- .../CrossChainTransferQueueService.cs | 28 +++++++ .../CrossChainTransferService.cs | 74 ++++++++++++++++++ .../ICrossChainTransferQueueService.cs | 8 ++ .../ICrossChainTransferService.cs | 8 ++ src/AElf.Client.Abp.Token/ITokenService.cs | 7 ++ .../ISyncTokenInfoQueueService.cs | 2 +- .../ISyncTokenInfoService.cs | 2 +- .../SyncTokenInfoQueueService.cs | 8 +- .../SyncTokenInfoService.cs | 7 +- .../TokenService.Send.cs | 78 ++++++++++++------- src/AElf.Client.Abp/AElfClientService.Send.cs | 11 ++- src/AElf.Client.Abp/AElfClientService.View.cs | 6 +- src/AElf.Client.Abp/ContractServiceBase.cs | 38 +++++++++ src/AElf.Client.Abp/IAElfClientService.cs | 4 +- .../Profile/TransactionProfile.cs | 3 +- src/AElf.Client/AElfClientConstants.cs | 2 +- 24 files changed, 277 insertions(+), 81 deletions(-) delete mode 100644 examples/TokenManager/SyncTokenInfoOptions.cs create mode 100644 src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs create mode 100644 src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs create mode 100644 src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs create mode 100644 src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs rename src/AElf.Client.Abp.Token/{ => SyncTokenInfo}/ISyncTokenInfoQueueService.cs (63%) rename src/AElf.Client.Abp.Token/{ => SyncTokenInfo}/ISyncTokenInfoService.cs (64%) rename src/AElf.Client.Abp.Token/{ => SyncTokenInfo}/SyncTokenInfoQueueService.cs (71%) rename src/AElf.Client.Abp.Token/{ => SyncTokenInfo}/SyncTokenInfoService.cs (92%) create mode 100644 src/AElf.Client.Abp/ContractServiceBase.cs diff --git a/examples/TokenManager/Program.cs b/examples/TokenManager/Program.cs index 4d45858..0f33bcb 100644 --- a/examples/TokenManager/Program.cs +++ b/examples/TokenManager/Program.cs @@ -9,12 +9,12 @@ .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning) #if DEBUG - .MinimumLevel.Override("AEDPoSViewer", LogEventLevel.Debug) + .MinimumLevel.Override("TokenManager", LogEventLevel.Debug) #else .MinimumLevel.Override("AEDPoSViewer", LogEventLevel.Information) #endif .Enrich.FromLogContext() - .WriteTo.Async(c => c.File($"Logs/aelf-consensus-viewer-{DateTime.UtcNow:yyyy-MM-dd}.logs")) + .WriteTo.Async(c => c.File($"Logs/aelf-token-manager-{DateTime.UtcNow:yyyy-MM-dd}.logs")) .WriteTo.Async(c => c.Console()) .CreateLogger(); diff --git a/examples/TokenManager/SyncTokenInfoOptions.cs b/examples/TokenManager/SyncTokenInfoOptions.cs deleted file mode 100644 index aa22f70..0000000 --- a/examples/TokenManager/SyncTokenInfoOptions.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace TokenManager; - -public class SyncTokenInfoOptions -{ - public string CreateTransactionId { get; set; } - public string ValidateTokenInfoExistsTransactionId { get; set; } -} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs index 9d73968..2957c58 100644 --- a/examples/TokenManager/TokenManagerHostedService.cs +++ b/examples/TokenManager/TokenManagerHostedService.cs @@ -33,7 +33,7 @@ public async Task StartAsync(CancellationToken cancellationToken) await _abpApplication.InitializeAsync(); var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); - await tokenManagerService.SyncTokenInfoAsync(); + await tokenManagerService.GetTokenInfoAsync("ELF"); } public async Task StopAsync(CancellationToken cancellationToken) diff --git a/examples/TokenManager/TokenManagerModule.cs b/examples/TokenManager/TokenManagerModule.cs index 57c684b..58931e7 100644 --- a/examples/TokenManager/TokenManagerModule.cs +++ b/examples/TokenManager/TokenManagerModule.cs @@ -1,6 +1,5 @@ using AElf.Client.Abp; using AElf.Client.Abp.Token; -using AElf.Client.Options; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; @@ -17,6 +16,5 @@ public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); Configure(options => { configuration.GetSection("TokenManager").Bind(options); }); - Configure(options => { configuration.GetSection("SyncTokenInfo").Bind(options); }); } } \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs index d743f52..f429adf 100644 --- a/examples/TokenManager/TokenManagerService.cs +++ b/examples/TokenManager/TokenManagerService.cs @@ -1,11 +1,13 @@ -using AElf.Client.Abp; +using AElf.Client; using AElf.Client.Abp.Token; +using AElf.Client.Abp.Token.CrossChainTransfer; +using AElf.Client.Abp.Token.SyncTokenInfo; +using AElf.Contracts.MultiToken; +using AElf.Types; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -using Volo.Abp.ObjectMapping; namespace TokenManager; @@ -13,8 +15,7 @@ public class TokenManagerService : ITransientDependency { private readonly ITokenService _tokenService; private readonly ISyncTokenInfoQueueService _syncTokenInfoQueueService; - private readonly IObjectMapper _objectMapper; - private readonly SyncTokenInfoOptions _syncTokenInfoOptions; + private readonly ICrossChainTransferQueueService _crossChainTransferQueueService; private IServiceScopeFactory ServiceScopeFactory { get; } public ILogger Logger { get; set; } @@ -22,27 +23,42 @@ public class TokenManagerService : ITransientDependency public TokenManagerService(IServiceScopeFactory serviceScopeFactory, ITokenService tokenService, ISyncTokenInfoQueueService syncTokenInfoQueueService, - IObjectMapper objectMapper, - IOptionsSnapshot syncTokenInfoOptions) + ICrossChainTransferQueueService crossChainTransferQueueService) { _tokenService = tokenService; _syncTokenInfoQueueService = syncTokenInfoQueueService; - _objectMapper = objectMapper; - _syncTokenInfoOptions = syncTokenInfoOptions.Value; + _crossChainTransferQueueService = crossChainTransferQueueService; ServiceScopeFactory = serviceScopeFactory; Logger = NullLogger.Instance; } - public async Task GetTokenInfoAsync() + public async Task GetTokenInfoAsync(string symbol) { - var tokenInfo = await _tokenService.GetTokenInfoAsync("ELF"); + var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); Logger.LogInformation("{TokenInfo}", tokenInfo.ToString()); } - public async Task SyncTokenInfoAsync() + public async Task SyncTokenInfoAsync(string symbol) { - _syncTokenInfoQueueService.Enqueue("JUNETEN"); - Logger.LogInformation("Enqueued"); + _syncTokenInfoQueueService.Enqueue(symbol); + Logger.LogInformation("Enqueued SyncTokenInfo"); + } + + public async Task CrossChainTransferAsync(Address to, string symbol, long amount, string toClientAlias) + { + _crossChainTransferQueueService.Enqueue( + to, symbol, amount, EndpointType.TestNetMainChain.ToString(), toClientAlias); + Logger.LogInformation("Enqueued CrossChainTransfer"); + } + + public async Task TransferAsync(Address to, string symbol, long amount) + { + await _tokenService.TransferAsync(new TransferInput + { + To = to, + Symbol = symbol, + Amount = amount, + }); } } \ No newline at end of file diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index e59f3da..86c878f 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -45,12 +45,8 @@ "AElfToken": { "NFTContractAddress": "" }, - "SyncTokenInfo": { - "CreateTransactionId": "c50498fdfa9213b7ffe6b39909514b3b0dc8d863511607944c337c8df9d72e06", - "ValidateTokenInfoExistsTransactionId": "145243e8d95702d698198d2e1b65dc88ca741cef9e8a0d2436682fc366e0cf17" - }, "AElfClientConfig": { - "UseClientAlias": "TestNetMainChain", + "UseClientAlias": "TestNetSidechain", "UseMainChainClientAlias": "TestNetMainChain", "UseSidechainClientAlias": "TestNetSidechain", "UseAccountAlias": "eanz", diff --git a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs index ab77b32..6621979 100644 --- a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs +++ b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs @@ -21,6 +21,8 @@ public override void OnApplicationInitialization(ApplicationInitializationContex { var taskQueueManager = context.ServiceProvider.GetService(); taskQueueManager?.CreateQueue(AElfTokenConstants.SyncTokenInfoQueueName, - AElfTokenConstants.SyncTokenInfoMaxDegreeOfParallelism); + AElfTokenConstants.DefaultMaxDegreeOfParallelism); + taskQueueManager?.CreateQueue(AElfTokenConstants.CrossChainTransferQueueName, + AElfTokenConstants.DefaultMaxDegreeOfParallelism); } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs index 6303a43..64facc7 100644 --- a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs +++ b/src/AElf.Client.Abp.Token/AElfTokenConstants.cs @@ -4,7 +4,8 @@ public class AElfTokenConstants { public const string TokenSmartContractName = "AElf.ContractNames.Token"; public const string SyncTokenInfoQueueName = "SyncTokenInfo"; - public const int SyncTokenInfoMaxDegreeOfParallelism = int.MaxValue; + public const string CrossChainTransferQueueName = "CrossChainTransfer"; + public const int DefaultMaxDegreeOfParallelism = int.MaxValue; public const int TenSeconds = 10_000; public const string TestNetSidechainMultiTokenContractAddress = "7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX"; } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs b/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs new file mode 100644 index 0000000..26d6c3a --- /dev/null +++ b/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs @@ -0,0 +1,28 @@ +using AElf.Types; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Token.CrossChainTransfer; + +public class CrossChainTransferQueueService : ICrossChainTransferQueueService, ITransientDependency +{ + private readonly ICrossChainTransferService _crossChainTransferService; + private readonly ITaskQueueManager _taskQueueManager; + + public CrossChainTransferQueueService(ICrossChainTransferService crossChainTransferService, + ITaskQueueManager taskQueueManager) + { + _crossChainTransferService = crossChainTransferService; + _taskQueueManager = taskQueueManager; + } + + public void Enqueue(Address to, string symbol, long amount, string fromClientAlias, string toClientAlias) + { + _taskQueueManager.Enqueue( + async () => + { + await _crossChainTransferService.CrossChainTransferAsync(to, symbol, amount, fromClientAlias, + toClientAlias); + }, + AElfTokenConstants.CrossChainTransferQueueName); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs b/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs new file mode 100644 index 0000000..6c6aa0b --- /dev/null +++ b/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs @@ -0,0 +1,74 @@ +using AElf.Client.Options; +using AElf.Contracts.MultiToken; +using AElf.Types; +using Google.Protobuf; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Token.CrossChainTransfer; + +public class CrossChainTransferService : ICrossChainTransferService, ITransientDependency +{ + private readonly ITokenService _tokenService; + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + public ILogger Logger { get; set; } + + public CrossChainTransferService(ITokenService tokenService, IAElfClientService clientService, + IOptionsSnapshot clientConfigOptions) + { + _tokenService = tokenService; + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + } + + public async Task CrossChainTransferAsync(Address to, string symbol, long amount, string fromClientAlias, + string toClientAlias) + { + var fromChainStatus = await _clientService.GetChainStatusAsync(fromClientAlias); + var toChainStatus = await _clientService.GetChainStatusAsync(toClientAlias); + var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); + var crossChainTransferInput = new CrossChainTransferInput + { + To = to, + Symbol = symbol, + Amount = amount, + ToChainId = ChainHelper.ConvertBase58ToChainId(toChainStatus.ChainId), + IssueChainId = tokenInfo.IssueChainId + }; + var transferResult = await _tokenService.CrossChainTransferAsync(crossChainTransferInput, fromClientAlias); + Logger.LogInformation("CrossChainTransfer: {Result}", transferResult.TransactionResult); + if (transferResult.TransactionResult.Status == TransactionResultStatus.Mined) + { + while (true) + { + var chainStatus = + await _clientService.GetChainStatusAsync(fromClientAlias); + Logger.LogInformation( + "From chain lib height: {LibHeight}, Transfer tx package height: {TransferHeight}", + chainStatus.LastIrreversibleBlockHeight, transferResult.TransactionResult.BlockNumber); + if (chainStatus.LastIrreversibleBlockHeight - transferResult.TransactionResult.BlockNumber > 300) + break; + await Task.Delay(AElfTokenConstants.TenSeconds); + } + + var merklePath = await _clientService.GetMerklePathByTransactionIdAsync( + transferResult.TransactionResult.TransactionId.ToHex(), + fromClientAlias); + var crossChainReceiveTokenInput = new CrossChainReceiveTokenInput + { + FromChainId = ChainHelper.ConvertBase58ToChainId(fromChainStatus.ChainId), + MerklePath = merklePath, + ParentChainHeight = transferResult.TransactionResult.BlockNumber, + TransferTransactionBytes = + ByteString.CopyFrom( + ByteArrayHelper.HexStringToByteArray(transferResult.Transaction.ToByteArray().ToHex())), + }; + + var crossChainReceiveTokenResult = + await _tokenService.CrossChainReceiveTokenAsync(crossChainReceiveTokenInput, toClientAlias); + Logger.LogInformation("CrossChainReceiveToken: {Result}", crossChainReceiveTokenResult.TransactionResult); + } + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs b/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs new file mode 100644 index 0000000..d53f01a --- /dev/null +++ b/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs @@ -0,0 +1,8 @@ +using AElf.Types; + +namespace AElf.Client.Abp.Token.CrossChainTransfer; + +public interface ICrossChainTransferQueueService +{ + void Enqueue(Address to, string symbol, long amount, string fromClientAlias, string toClientAlias); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs b/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs new file mode 100644 index 0000000..b523886 --- /dev/null +++ b/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs @@ -0,0 +1,8 @@ +using AElf.Types; + +namespace AElf.Client.Abp.Token.CrossChainTransfer; + +public interface ICrossChainTransferService +{ + Task CrossChainTransferAsync(Address to, string symbol, long amount, string fromClientAlias, string toClientAlias); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Abp.Token/ITokenService.cs index 0f21d8c..df431ff 100644 --- a/src/AElf.Client.Abp.Token/ITokenService.cs +++ b/src/AElf.Client.Abp.Token/ITokenService.cs @@ -1,6 +1,7 @@ using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; using AElf.Types; +using TransferInput = AElf.Contracts.MultiToken.TransferInput; namespace AElf.Client.Abp.Token; @@ -11,6 +12,12 @@ public interface ITokenService Task MintNFTAsync(MintInput mintInput); Task ValidateTokenInfoExistsAsync(ValidateTokenInfoExistsInput validateTokenInfoExistsInput); Task CrossChainCreateTokenAsync(CrossChainCreateTokenInput crossChainCreateTokenInput); + Task CrossChainTransferAsync(CrossChainTransferInput crossChainTransferInput, + string useClientAlias); + Task CrossChainReceiveTokenAsync(CrossChainReceiveTokenInput crossChainReceiveTokenInput, + string useClientAlias); + + Task TransferAsync(TransferInput transferInput); Task GetTokenInfoAsync(string symbol); Task GetTokenBalanceAsync(string symbol, Address owner); diff --git a/src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs similarity index 63% rename from src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs rename to src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs index c6f0bf5..1558f27 100644 --- a/src/AElf.Client.Abp.Token/ISyncTokenInfoQueueService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Abp.Token.SyncTokenInfo; public interface ISyncTokenInfoQueueService { diff --git a/src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoService.cs similarity index 64% rename from src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs rename to src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoService.cs index e6fe8be..279c5ae 100644 --- a/src/AElf.Client.Abp.Token/ISyncTokenInfoService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoService.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Abp.Token.SyncTokenInfo; public interface ISyncTokenInfoService { diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs similarity index 71% rename from src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs rename to src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs index 450fdcc..8b5a177 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfoQueueService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs @@ -1,6 +1,6 @@ using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Abp.Token.SyncTokenInfo; public class SyncTokenInfoQueueService : ISyncTokenInfoQueueService, ITransientDependency { @@ -16,9 +16,7 @@ public SyncTokenInfoQueueService(ISyncTokenInfoService syncTokenInfoService, public void Enqueue(string symbol) { - _taskQueueManager.Enqueue(async () => - { - await _syncTokenInfoService.SyncTokenInfoAsync(symbol); - }, AElfTokenConstants.SyncTokenInfoQueueName); + _taskQueueManager.Enqueue(async () => { await _syncTokenInfoService.SyncTokenInfoAsync(symbol); }, + AElfTokenConstants.SyncTokenInfoQueueName); } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs similarity index 92% rename from src/AElf.Client.Abp.Token/SyncTokenInfoService.cs rename to src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs index 70f56a0..cf8f5d3 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfoService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Abp.Token.SyncTokenInfo; public class SyncTokenInfoService : ISyncTokenInfoService, ITransientDependency { @@ -60,7 +60,7 @@ public async Task SyncTokenInfoAsync(string symbol) var merklePath = await _clientService.GetMerklePathByTransactionIdAsync( validateResult.TransactionResult.TransactionId.ToHex(), _clientConfigOptions.UseMainChainClientAlias); - var createTokenParams = new CrossChainCreateTokenInput + var crossChainCreateTokenInput = new CrossChainCreateTokenInput { FromChainId = AElfClientConstants.MainChainId, ParentChainHeight = validateResult.TransactionResult.BlockNumber, @@ -70,7 +70,8 @@ public async Task SyncTokenInfoAsync(string symbol) MerklePath = merklePath }; - var crossChainCreateTokenResult = await _tokenService.CrossChainCreateTokenAsync(createTokenParams); + var crossChainCreateTokenResult = + await _tokenService.CrossChainCreateTokenAsync(crossChainCreateTokenInput); Logger.LogInformation("CrossChainCreateToken: {Result}", crossChainCreateTokenResult.TransactionResult); } } diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index 00e576f..8ec4c93 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -1,63 +1,55 @@ using AElf.Client.Options; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; -using AElf.Types; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using CreateInput = AElf.Contracts.MultiToken.CreateInput; +using TransferInput = AElf.Contracts.MultiToken.TransferInput; namespace AElf.Client.Abp.Token; -public partial class TokenService : ITokenService, ITransientDependency +public partial class TokenService : ContractServiceBase, ITokenService, ITransientDependency { private readonly IAElfClientService _clientService; - private readonly AElfTokenOptions _tokenOptions; private readonly AElfClientConfigOptions _clientConfigOptions; - public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions, - IOptionsSnapshot tokenManagerOptions) + public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions) + : base(clientService, AElfTokenConstants.TokenSmartContractName) { _clientService = clientService; - _tokenOptions = tokenManagerOptions.Value; _clientConfigOptions = clientConfigOptions.Value; } public async Task CreateTokenAsync(CreateInput createInput) { var useClientAlias = PreferGetUseMainChainClientAlias(); - var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, "Create", - createInput, useClientAlias); - var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + var tx = await PerformSendTransactionAsync("Create", createInput, useClientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = txResult + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) }; } public async Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput) { var useClientAlias = PreferGetUseMainChainClientAlias(); - var tx = await _clientService.SendAsync(_tokenOptions.NFTContractAddress, "Create", createInput, - useClientAlias, _clientConfigOptions.UseAccountAlias); - var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + var tx = await PerformSendTransactionAsync("Create", createInput, useClientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = txResult + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) }; } public async Task MintNFTAsync(MintInput mintInput) { var useClientAlias = _clientConfigOptions.UseClientAlias; - var tx = await _clientService.SendAsync(_tokenOptions.NFTContractAddress, "Mint", mintInput, - useClientAlias, _clientConfigOptions.UseAccountAlias); - var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + var tx = await PerformSendTransactionAsync("Mint", mintInput, useClientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = txResult + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) }; } @@ -65,14 +57,12 @@ public async Task ValidateTokenInfoExistsAsync( ValidateTokenInfoExistsInput validateTokenInfoExistsInput) { var useClientAlias = PreferGetUseMainChainClientAlias(); - var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, - "ValidateTokenInfoExists", validateTokenInfoExistsInput, useClientAlias, - _clientConfigOptions.UseAccountAlias); - var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + var tx = await PerformSendTransactionAsync("ValidateTokenInfoExists", validateTokenInfoExistsInput, + useClientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = txResult + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) }; } @@ -80,13 +70,47 @@ public async Task CrossChainCreateTokenAsync( CrossChainCreateTokenInput crossChainCreateTokenInput) { var useClientAlias = PreferGetUseSidechainClientAlias(); - var tx = await _clientService.SendAsync(AElfTokenConstants.TestNetSidechainMultiTokenContractAddress, - "CrossChainCreateToken", crossChainCreateTokenInput, useClientAlias, _clientConfigOptions.UseAccountAlias); - var txResult = await _clientService.GetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias); + var tx = await PerformSendTransactionAsync("CrossChainCreateToken", crossChainCreateTokenInput, useClientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = txResult + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } + + public async Task CrossChainTransferAsync(CrossChainTransferInput crossChainTransferInput, + string useClientAlias) + { + var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, "CrossChainTransfer", + crossChainTransferInput, useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } + + public async Task CrossChainReceiveTokenAsync( + CrossChainReceiveTokenInput crossChainReceiveTokenInput, string useClientAlias) + { + var tx = await PerformSendTransactionAsync("CrossChainReceiveToken", crossChainReceiveTokenInput, + useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } + + public async Task TransferAsync(TransferInput transferInput) + { + var useClientAlias = _clientConfigOptions.UseClientAlias; + var tx = await PerformSendTransactionAsync("Transfer", transferInput, + useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) }; } diff --git a/src/AElf.Client.Abp/AElfClientService.Send.cs b/src/AElf.Client.Abp/AElfClientService.Send.cs index 2f3216e..334aa50 100644 --- a/src/AElf.Client.Abp/AElfClientService.Send.cs +++ b/src/AElf.Client.Abp/AElfClientService.Send.cs @@ -6,10 +6,10 @@ namespace AElf.Client.Abp; public partial class AElfClientService { public async Task SendAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default") + string clientAlias) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.UseAccountAlias); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseContract(contractAddress) @@ -21,10 +21,10 @@ public async Task SendAsync(string contractAddress, string methodNa } public async Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default") + string clientAlias) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.UseAccountAlias); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseSystemContract(systemContractName) @@ -35,12 +35,11 @@ public async Task SendSystemAsync(string systemContractName, string return tx; } - private static async Task PerformSendAsync(AElfClient aelfClient, Transaction tx) + private static async Task PerformSendAsync(AElfClient aelfClient, Transaction tx) { var result = await aelfClient.SendTransactionAsync(new SendTransactionInput { RawTransaction = tx.ToByteArray().ToHex() }); - return result.TransactionId; } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientService.View.cs b/src/AElf.Client.Abp/AElfClientService.View.cs index e268bce..c3bf71e 100644 --- a/src/AElf.Client.Abp/AElfClientService.View.cs +++ b/src/AElf.Client.Abp/AElfClientService.View.cs @@ -1,7 +1,9 @@ using AElf.Client.Dto; +using AElf.Client.Options; using Google.Protobuf; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectMapping; @@ -12,15 +14,17 @@ public partial class AElfClientService : IAElfClientService, ITransientDependenc private readonly IAElfClientProvider _aelfClientProvider; private readonly IAElfAccountProvider _aelfAccountProvider; private readonly IObjectMapper _objectMapper; + private readonly AElfClientConfigOptions _clientConfigOptions; public ILogger Logger { get; set; } public AElfClientService(IAElfClientProvider aelfClientProvider, IAElfAccountProvider aelfAccountProvider, - IObjectMapper objectMapper) + IObjectMapper objectMapper, IOptionsSnapshot clientConfigOptions) { _aelfClientProvider = aelfClientProvider; _aelfAccountProvider = aelfAccountProvider; _objectMapper = objectMapper; + _clientConfigOptions = clientConfigOptions.Value; Logger = NullLogger.Instance; } diff --git a/src/AElf.Client.Abp/ContractServiceBase.cs b/src/AElf.Client.Abp/ContractServiceBase.cs new file mode 100644 index 0000000..8cd70f1 --- /dev/null +++ b/src/AElf.Client.Abp/ContractServiceBase.cs @@ -0,0 +1,38 @@ +using Google.Protobuf; + +namespace AElf.Client.Abp; + +public class ContractServiceBase +{ + private readonly IAElfClientService _clientService; + private string SmartContractName { get; } + + protected ContractServiceBase(IAElfClientService clientService, string smartContractName) + { + _clientService = clientService; + SmartContractName = smartContractName; + } + + protected async Task PerformSendTransactionAsync(string methodName, IMessage parameter, + string useClientAlias, string? smartContractName = null) + { + if (smartContractName == null) + { + smartContractName = SmartContractName; + } + + return await _clientService.SendSystemAsync(smartContractName, methodName, parameter, useClientAlias); + } + + protected async Task PerformGetTransactionResultAsync(string transactionId, + string useClientAlias) + { + TransactionResult txResult; + do + { + txResult = await _clientService.GetTransactionResultAsync(transactionId, useClientAlias); + } while (txResult.Status == TransactionResultStatus.Pending); + + return txResult; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/IAElfClientService.cs b/src/AElf.Client.Abp/IAElfClientService.cs index 09ab648..d797385 100644 --- a/src/AElf.Client.Abp/IAElfClientService.cs +++ b/src/AElf.Client.Abp/IAElfClientService.cs @@ -12,10 +12,10 @@ Task ViewSystemAsync(string systemContractName, string methodName, IMess string clientAlias, string accountAlias = "Default"); Task SendAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default"); + string clientAlias); Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default"); + string clientAlias); Task GetTransactionResultAsync(string transactionId, string clientAlias); diff --git a/src/AElf.Client.Abp/Profile/TransactionProfile.cs b/src/AElf.Client.Abp/Profile/TransactionProfile.cs index 7027959..8bcf7c1 100644 --- a/src/AElf.Client.Abp/Profile/TransactionProfile.cs +++ b/src/AElf.Client.Abp/Profile/TransactionProfile.cs @@ -45,7 +45,8 @@ public TransactionProfile() ? status : TransactionResultStatus.NotExisted)) .ForMember(d => d.Logs, opt => opt.MapFrom(s => s.Logs)) - .Ignore(d => d.Error); + .Ignore(d => d.Error) + .Ignore(d => d.Bloom); CreateMap(); CreateMap(); diff --git a/src/AElf.Client/AElfClientConstants.cs b/src/AElf.Client/AElfClientConstants.cs index 2103de6..2e0f577 100644 --- a/src/AElf.Client/AElfClientConstants.cs +++ b/src/AElf.Client/AElfClientConstants.cs @@ -7,7 +7,7 @@ public class AElfClientConstants public const string MainNetMainChain = "https://aelf-public-node.aelf.io"; public const string MainNetSidechain = "https://tdvv-public-node.aelf.io"; public const string TestNetMainChain = "https://aelf-test-node.aelf.io"; - public const string TestNetSidechain = "https://tdvv-test-node.aelf.io"; + public const string TestNetSidechain = "https://tdvw-test-node.aelf.io"; public const int MainChainId = 9992731; public const int SidechainId = 1866392; } \ No newline at end of file From 45e464eec02a67167419d19c33ae0b666acb2a91 Mon Sep 17 00:00:00 2001 From: yiqi Date: Mon, 13 Jun 2022 18:49:26 +0800 Subject: [PATCH 07/21] Initial CrossChainService and iniital test base. --- all.sln | 21 ++++++++ examples/AEDPoSViewer/appsettings.json | 6 +-- .../CrossChainManager.csproj | 32 ++++++++++++ .../CrossChainManagerHostedService.cs | 45 ++++++++++++++++ .../CrossChainManagerModule.cs | 19 +++++++ .../CrossChainManagerService.cs | 27 ++++++++++ examples/CrossChainManager/Program.cs | 40 ++++++++++++++ examples/CrossChainManager/appsettings.json | 52 +++++++++++++++++++ examples/TokenManager/Program.cs | 2 +- .../TokenManager/TokenManagerHostedService.cs | 12 ++++- examples/TokenManager/TokenManagerModule.cs | 2 +- examples/TokenManager/appsettings.json | 10 ++-- .../AElf.Client.Abp.CrossChain.csproj | 4 ++ .../AElfClientCrossChainModule.cs | 10 +++- .../AElfCrossChainConstants.cs | 6 +++ .../CrossChainService.cs | 38 ++++++++++++++ .../ICrossChainService.cs | 6 +++ .../SyncTokenInfo/SyncTokenInfoService.cs | 4 +- .../TokenService.Send.cs | 16 +++--- .../TokenService.View.cs | 6 +-- src/AElf.Client.Abp/AElfClientService.Send.cs | 4 +- src/AElf.Client.Abp/ContractServiceBase.cs | 4 ++ src/AElf.Client.Abp/IAElfClientProvider.cs | 2 +- .../Options/AElfClientConfigOptions.cs | 10 ++-- src/AElf.Client/AElfClientConstants.cs | 2 +- .../AElf.Client.Abp.Test.csproj | 30 +++++++++++ .../AElfClientAbpContractServiceTestBase.cs | 9 ++++ .../AElfClientAbpContractServiceTestModule.cs | 14 +++++ .../Token/TokenServiceTests.cs | 23 ++++++++ test/AElf.Client.Abp.Test/Usings.cs | 1 + .../AElf.Client.Abp.TestBase.csproj | 44 ++++++++++++++++ .../AElfClientAbpTestBase.cs | 24 +++++++++ .../AElfClientAbpTestBaseModule.cs | 14 +++++ test/AElf.Client.Abp.TestBase/Usings.cs | 1 + .../AElf.Client.Abp.TestBase/appsettings.json | 9 ++++ .../appsettings.secrets.json | 9 ++++ 36 files changed, 522 insertions(+), 36 deletions(-) create mode 100644 examples/CrossChainManager/CrossChainManager.csproj create mode 100644 examples/CrossChainManager/CrossChainManagerHostedService.cs create mode 100644 examples/CrossChainManager/CrossChainManagerModule.cs create mode 100644 examples/CrossChainManager/CrossChainManagerService.cs create mode 100644 examples/CrossChainManager/Program.cs create mode 100644 examples/CrossChainManager/appsettings.json create mode 100644 src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs create mode 100644 src/AElf.Client.Abp.CrossChain/CrossChainService.cs create mode 100644 src/AElf.Client.Abp.CrossChain/ICrossChainService.cs create mode 100644 test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj create mode 100644 test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs create mode 100644 test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs create mode 100644 test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs create mode 100644 test/AElf.Client.Abp.Test/Usings.cs create mode 100644 test/AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj create mode 100644 test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs create mode 100644 test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs create mode 100644 test/AElf.Client.Abp.TestBase/Usings.cs create mode 100644 test/AElf.Client.Abp.TestBase/appsettings.json create mode 100644 test/AElf.Client.Abp.TestBase/appsettings.secrets.json diff --git a/all.sln b/all.sln index bbff868..f4557de 100644 --- a/all.sln +++ b/all.sln @@ -58,6 +58,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Regiment", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Core", "src\AElf.Client.Abp.Core\AElf.Client.Abp.Core.csproj", "{1552B665-A065-41AE-A00E-A6E9AB974414}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossChainManager", "examples\CrossChainManager\CrossChainManager.csproj", "{1BC40A93-079B-48C4-B116-62C6B50C2FFC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Test", "test\AElf.Client.Abp.Test\AElf.Client.Abp.Test.csproj", "{64ACA917-AFE2-4916-A772-A3F77B3C4FE8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TestBase", "test\AElf.Client.Abp.TestBase\AElf.Client.Abp.TestBase.csproj", "{D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -90,6 +96,9 @@ Global {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610} = {940361AC-2167-4D30-A4F6-9A543C608196} {F520E0B9-9EF7-4528-93FA-C182E8423F51} = {940361AC-2167-4D30-A4F6-9A543C608196} {1552B665-A065-41AE-A00E-A6E9AB974414} = {940361AC-2167-4D30-A4F6-9A543C608196} + {1BC40A93-079B-48C4-B116-62C6B50C2FFC} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} + {64ACA917-AFE2-4916-A772-A3F77B3C4FE8} = {7CD2B508-C765-4720-B430-94E79135797A} + {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401} = {7CD2B508-C765-4720-B430-94E79135797A} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -196,5 +205,17 @@ Global {1552B665-A065-41AE-A00E-A6E9AB974414}.Debug|Any CPU.Build.0 = Debug|Any CPU {1552B665-A065-41AE-A00E-A6E9AB974414}.Release|Any CPU.ActiveCfg = Release|Any CPU {1552B665-A065-41AE-A00E-A6E9AB974414}.Release|Any CPU.Build.0 = Release|Any CPU + {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Release|Any CPU.Build.0 = Release|Any CPU + {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Release|Any CPU.Build.0 = Release|Any CPU + {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/examples/AEDPoSViewer/appsettings.json b/examples/AEDPoSViewer/appsettings.json index 91de2bc..e7e1db1 100644 --- a/examples/AEDPoSViewer/appsettings.json +++ b/examples/AEDPoSViewer/appsettings.json @@ -38,8 +38,8 @@ ] }, "AElfClientConfig": { - "UseClientAlias": "TestNetMainChain", - "UseAccountAlias": "Ean", - "UseCamelCase": false + "ClientAlias": "TestNetMainChain", + "AccountAlias": "Ean", + "CamelCase": false } } \ No newline at end of file diff --git a/examples/CrossChainManager/CrossChainManager.csproj b/examples/CrossChainManager/CrossChainManager.csproj new file mode 100644 index 0000000..25943f0 --- /dev/null +++ b/examples/CrossChainManager/CrossChainManager.csproj @@ -0,0 +1,32 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + + + PreserveNewest + Always + + + + diff --git a/examples/CrossChainManager/CrossChainManagerHostedService.cs b/examples/CrossChainManager/CrossChainManagerHostedService.cs new file mode 100644 index 0000000..20bef82 --- /dev/null +++ b/examples/CrossChainManager/CrossChainManagerHostedService.cs @@ -0,0 +1,45 @@ +using AElf.Client; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using TokenManager; +using Volo.Abp; + +namespace CrossChainManager; + +public class CrossChainManagerHostedService : IHostedService +{ + private IAbpApplicationWithInternalServiceProvider _abpApplication; + + private readonly IConfiguration _configuration; + private readonly IHostEnvironment _hostEnvironment; + + public CrossChainManagerHostedService(IConfiguration configuration, IHostEnvironment hostEnvironment) + { + _configuration = configuration; + _hostEnvironment = hostEnvironment; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + _abpApplication = await AbpApplicationFactory.CreateAsync(options => + { + options.Services.ReplaceConfiguration(_configuration); + options.Services.AddSingleton(_hostEnvironment); + + options.UseAutofac(); + options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog()); + }); + + await _abpApplication.InitializeAsync(); + + var crossChainManagerService = _abpApplication.ServiceProvider.GetRequiredService(); + await crossChainManagerService.GetSyncedHeightByChainId(AElfClientConstants.MainChainId); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + await _abpApplication.ShutdownAsync(); + } +} \ No newline at end of file diff --git a/examples/CrossChainManager/CrossChainManagerModule.cs b/examples/CrossChainManager/CrossChainManagerModule.cs new file mode 100644 index 0000000..b13c96a --- /dev/null +++ b/examples/CrossChainManager/CrossChainManagerModule.cs @@ -0,0 +1,19 @@ +using AElf.Client.Abp; +using AElf.Client.Abp.CrossChain; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace TokenManager; + +[DependsOn( + typeof(AElfClientModule), + typeof(AElfClientCrossChainModule) +)] +public class CrossChainManagerModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + } +} \ No newline at end of file diff --git a/examples/CrossChainManager/CrossChainManagerService.cs b/examples/CrossChainManager/CrossChainManagerService.cs new file mode 100644 index 0000000..c479454 --- /dev/null +++ b/examples/CrossChainManager/CrossChainManagerService.cs @@ -0,0 +1,27 @@ +using AElf.Client.Abp.CrossChain; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Volo.Abp.DependencyInjection; + +namespace CrossChainManager; + +public class CrossChainManagerService : ITransientDependency +{ + private readonly ICrossChainService _crossChainService; + private IServiceScopeFactory ServiceScopeFactory { get; } + + public ILogger Logger { get; set; } + + public CrossChainManagerService(ICrossChainService crossChainService, IServiceScopeFactory serviceScopeFactory) + { + _crossChainService = crossChainService; + ServiceScopeFactory = serviceScopeFactory; + } + + public async Task GetSyncedHeightByChainId(int chainId) + { + var height = await _crossChainService.GetSyncedHeightByChainId(chainId); + Logger.LogInformation("Synced height of chain id {ChainId}: {Height}", chainId, height); + return height; + } +} \ No newline at end of file diff --git a/examples/CrossChainManager/Program.cs b/examples/CrossChainManager/Program.cs new file mode 100644 index 0000000..97073af --- /dev/null +++ b/examples/CrossChainManager/Program.cs @@ -0,0 +1,40 @@ +using CrossChainManager; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using Serilog.Events; + +Log.Logger = new LoggerConfiguration() + .MinimumLevel.Information() + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning) +#if DEBUG + .MinimumLevel.Override("CrossChainManager", LogEventLevel.Debug) +#else + .MinimumLevel.Override("CrossChainManager", LogEventLevel.Information) +#endif + .Enrich.FromLogContext() + .WriteTo.Async(c => c.File($"Logs/aelf-cross-chain-manager-{DateTime.UtcNow:yyyy-MM-dd}.logs")) + .WriteTo.Async(c => c.Console()) + .CreateLogger(); + +try +{ + await Host.CreateDefaultBuilder(args) + .ConfigureServices(services => + { + services.AddHostedService(); + }) + .UseSerilog() + .RunConsoleAsync(); + return 0; +} +catch (Exception ex) +{ + Log.Fatal(ex, "Host terminated unexpectedly!"); + return 1; +} +finally +{ + Log.CloseAndFlush(); +} \ No newline at end of file diff --git a/examples/CrossChainManager/appsettings.json b/examples/CrossChainManager/appsettings.json new file mode 100644 index 0000000..462b2aa --- /dev/null +++ b/examples/CrossChainManager/appsettings.json @@ -0,0 +1,52 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "AElfClient": { + "ClientConfigList": [ + { + "Alias": "Example", + "Endpoint": "http://192.168.0.31:6800", + "UserName": "", + "Password": "", + "Timeout": 100 + } + ] + }, + "AElfAccount": { + "KeyDirectory": "", + "AccountConfigList": [ + { + "Alias": "Ean", + "PrivateKey": "8cc296e44d9e8881942e75a21ebc116ed3f29e39e0eaace1c92dc21e86d215c3", + "Address": "2AiXjNszZwUMdonm2RYb3GsB3aLUU3hkD1fxoazMwqPAamerLQ", + "Password": "aelftest" + }, + { + "Alias": "Test1", + "Address": "215tht8WyakoxNK4SvsR132jChydxE27RtJN8HSk1UXxuDQnmM", + "Password": "aelftest" + }, + { + "Alias": "Test2", + "PrivateKey": "5e2f12d13e4527ad1128e07db00f1614ec6b8b51662e68d4fdb42125ab384195", + }, + { + "Alias": "eanz", + "Address": "2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT", + "Password": "zhaoyiqi" + } + ] + }, + "AElfClientConfig": { + "ClientAlias": "TestNetSidechain", + "MainChainClientAlias": "TestNetMainChain", + "SidechainClientAlias": "TestNetSidechain", + "AccountAlias": "eanz", + "CamelCase": false + } +} \ No newline at end of file diff --git a/examples/TokenManager/Program.cs b/examples/TokenManager/Program.cs index 0f33bcb..dae78b0 100644 --- a/examples/TokenManager/Program.cs +++ b/examples/TokenManager/Program.cs @@ -11,7 +11,7 @@ #if DEBUG .MinimumLevel.Override("TokenManager", LogEventLevel.Debug) #else - .MinimumLevel.Override("AEDPoSViewer", LogEventLevel.Information) + .MinimumLevel.Override("TokenManager", LogEventLevel.Information) #endif .Enrich.FromLogContext() .WriteTo.Async(c => c.File($"Logs/aelf-token-manager-{DateTime.UtcNow:yyyy-MM-dd}.logs")) diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs index 2957c58..1411a4d 100644 --- a/examples/TokenManager/TokenManagerHostedService.cs +++ b/examples/TokenManager/TokenManagerHostedService.cs @@ -1,3 +1,5 @@ +using AElf.Client; +using AElf.Types; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -21,7 +23,7 @@ public TokenManagerHostedService(IConfiguration configuration, IHostEnvironment public async Task StartAsync(CancellationToken cancellationToken) { - _abpApplication = await AbpApplicationFactory.CreateAsync(options => + _abpApplication = await AbpApplicationFactory.CreateAsync(options => { options.Services.ReplaceConfiguration(_configuration); options.Services.AddSingleton(_hostEnvironment); @@ -33,7 +35,13 @@ public async Task StartAsync(CancellationToken cancellationToken) await _abpApplication.InitializeAsync(); var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); - await tokenManagerService.GetTokenInfoAsync("ELF"); + await tokenManagerService.TransferAsync(Address.FromBase58("eyDPrhJdofZ9f7Qdyi8FtbA8BePubP1M3gwfVMs6MnMHHNwik"), + "ELF", 10000_00000000); +/* + await tokenManagerService.CrossChainTransferAsync( + Address.FromBase58("2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT"), "ELF", 100000_00000000, + EndpointType.TestNetSidechain.ToString()); + */ } public async Task StopAsync(CancellationToken cancellationToken) diff --git a/examples/TokenManager/TokenManagerModule.cs b/examples/TokenManager/TokenManagerModule.cs index 58931e7..a9e9837 100644 --- a/examples/TokenManager/TokenManagerModule.cs +++ b/examples/TokenManager/TokenManagerModule.cs @@ -10,7 +10,7 @@ namespace TokenManager; typeof(AElfClientModule), typeof(AElfClientTokenModule) )] -public class AEDPoSViewerModule : AbpModule +public class TokenManagerModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index 86c878f..ffec599 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -46,10 +46,10 @@ "NFTContractAddress": "" }, "AElfClientConfig": { - "UseClientAlias": "TestNetSidechain", - "UseMainChainClientAlias": "TestNetMainChain", - "UseSidechainClientAlias": "TestNetSidechain", - "UseAccountAlias": "eanz", - "UseCamelCase": false + "ClientAlias": "TestNetSidechain", + "MainChainClientAlias": "TestNetMainChain", + "SidechainClientAlias": "TestNetSidechain", + "AccountAlias": "eanz", + "CamelCase": false } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj b/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj index eb2460e..a49c765 100644 --- a/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj +++ b/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs b/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs index 92e7f14..78c0fb1 100644 --- a/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs +++ b/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs @@ -1,5 +1,11 @@ -namespace AElf.Client.Abp.CrossChain; +using Volo.Abp.Modularity; -public class AElfClientCrossChainModule +namespace AElf.Client.Abp.CrossChain; + +[DependsOn( + typeof(AElfClientModule), + typeof(CoreAElfModule) +)] +public class AElfClientCrossChainModule : AbpModule { } \ No newline at end of file diff --git a/src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs b/src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs new file mode 100644 index 0000000..e28a9c4 --- /dev/null +++ b/src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.CrossChain; + +public class AElfCrossChainConstants +{ + public const string CrossChainSmartContractName = "AElf.ContractNames.CrossChain"; +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.CrossChain/CrossChainService.cs b/src/AElf.Client.Abp.CrossChain/CrossChainService.cs new file mode 100644 index 0000000..e83e99c --- /dev/null +++ b/src/AElf.Client.Abp.CrossChain/CrossChainService.cs @@ -0,0 +1,38 @@ +using AElf.Client.Options; +using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.CrossChain; + +public class CrossChainService : ContractServiceBase, ICrossChainService, ITransientDependency +{ + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + + public CrossChainService(IAElfClientService clientService, + IOptionsSnapshot clientConfigOptions) : base(clientService, + AElfCrossChainConstants.CrossChainSmartContractName) + { + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + } + + public async Task GetSyncedHeightByChainId(int chainId) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = chainId == AElfClientConstants.MainChainId + ? await _clientService.ViewSystemAsync(AElfCrossChainConstants.CrossChainSmartContractName, + "GetParentChainHeight", + new Empty(), useClientAlias) + : await _clientService.ViewSystemAsync(AElfCrossChainConstants.CrossChainSmartContractName, + "GetSideChainHeight", new Int32Value + { + Value = chainId + }, useClientAlias); + var height = new Int64Value(); + height.MergeFrom(result); + return height.Value; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.CrossChain/ICrossChainService.cs b/src/AElf.Client.Abp.CrossChain/ICrossChainService.cs new file mode 100644 index 0000000..0dc7864 --- /dev/null +++ b/src/AElf.Client.Abp.CrossChain/ICrossChainService.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.CrossChain; + +public interface ICrossChainService +{ + Task GetSyncedHeightByChainId(int chainId); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs index cf8f5d3..cc4983a 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs @@ -48,7 +48,7 @@ public async Task SyncTokenInfoAsync(string symbol) while (true) { var chainStatus = - await _clientService.GetChainStatusAsync(_clientConfigOptions.UseMainChainClientAlias); + await _clientService.GetChainStatusAsync(_clientConfigOptions.MainChainClientAlias); Logger.LogInformation( "Main chain lib height: {LibHeight}, Validate tx package height: {ValidateHeight}", chainStatus.LastIrreversibleBlockHeight, validateResult.TransactionResult.BlockNumber); @@ -59,7 +59,7 @@ public async Task SyncTokenInfoAsync(string symbol) var merklePath = await _clientService.GetMerklePathByTransactionIdAsync( validateResult.TransactionResult.TransactionId.ToHex(), - _clientConfigOptions.UseMainChainClientAlias); + _clientConfigOptions.MainChainClientAlias); var crossChainCreateTokenInput = new CrossChainCreateTokenInput { FromChainId = AElfClientConstants.MainChainId, diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index 8ec4c93..39c1426 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -44,7 +44,7 @@ public async Task CreateNFTProtocolAsync(Contracts.NFT.Cr public async Task MintNFTAsync(MintInput mintInput) { - var useClientAlias = _clientConfigOptions.UseClientAlias; + var useClientAlias = _clientConfigOptions.ClientAlias; var tx = await PerformSendTransactionAsync("Mint", mintInput, useClientAlias); return new SendTransactionResult { @@ -104,7 +104,7 @@ public async Task CrossChainReceiveTokenAsync( public async Task TransferAsync(TransferInput transferInput) { - var useClientAlias = _clientConfigOptions.UseClientAlias; + var useClientAlias = _clientConfigOptions.ClientAlias; var tx = await PerformSendTransactionAsync("Transfer", transferInput, useClientAlias); return new SendTransactionResult @@ -116,15 +116,15 @@ public async Task TransferAsync(TransferInput transferInp private string PreferGetUseMainChainClientAlias() { - return !string.IsNullOrEmpty(_clientConfigOptions.UseMainChainClientAlias) - ? _clientConfigOptions.UseMainChainClientAlias - : _clientConfigOptions.UseClientAlias; + return !string.IsNullOrEmpty(_clientConfigOptions.MainChainClientAlias) + ? _clientConfigOptions.MainChainClientAlias + : _clientConfigOptions.ClientAlias; } private string PreferGetUseSidechainClientAlias() { - return !string.IsNullOrEmpty(_clientConfigOptions.UseSidechainClientAlias) - ? _clientConfigOptions.UseSidechainClientAlias - : _clientConfigOptions.UseClientAlias; + return !string.IsNullOrEmpty(_clientConfigOptions.SidechainClientAlias) + ? _clientConfigOptions.SidechainClientAlias + : _clientConfigOptions.ClientAlias; } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/TokenService.View.cs b/src/AElf.Client.Abp.Token/TokenService.View.cs index 25fea27..0476d3c 100644 --- a/src/AElf.Client.Abp.Token/TokenService.View.cs +++ b/src/AElf.Client.Abp.Token/TokenService.View.cs @@ -8,7 +8,7 @@ public partial class TokenService { public async Task GetTokenInfoAsync(string symbol) { - var useClientAlias = _clientConfigOptions.UseClientAlias; + var useClientAlias = _clientConfigOptions.ClientAlias; var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetTokenInfo", new GetTokenInfoInput { @@ -21,7 +21,7 @@ public async Task GetTokenInfoAsync(string symbol) public async Task GetTokenBalanceAsync(string symbol, Address owner) { - var useClientAlias = _clientConfigOptions.UseClientAlias; + var useClientAlias = _clientConfigOptions.ClientAlias; var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetBalance", new GetBalanceInput { @@ -35,7 +35,7 @@ public async Task GetTokenBalanceAsync(string symbol, Address public async Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender) { - var useClientAlias = _clientConfigOptions.UseClientAlias; + var useClientAlias = _clientConfigOptions.ClientAlias; var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetAllowance", new GetAllowanceInput { diff --git a/src/AElf.Client.Abp/AElfClientService.Send.cs b/src/AElf.Client.Abp/AElfClientService.Send.cs index 334aa50..759c85c 100644 --- a/src/AElf.Client.Abp/AElfClientService.Send.cs +++ b/src/AElf.Client.Abp/AElfClientService.Send.cs @@ -9,7 +9,7 @@ public async Task SendAsync(string contractAddress, string methodNa string clientAlias) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.UseAccountAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.AccountAlias); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseContract(contractAddress) @@ -24,7 +24,7 @@ public async Task SendSystemAsync(string systemContractName, string string clientAlias) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.UseAccountAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.AccountAlias); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseSystemContract(systemContractName) diff --git a/src/AElf.Client.Abp/ContractServiceBase.cs b/src/AElf.Client.Abp/ContractServiceBase.cs index 8cd70f1..d70756f 100644 --- a/src/AElf.Client.Abp/ContractServiceBase.cs +++ b/src/AElf.Client.Abp/ContractServiceBase.cs @@ -1,4 +1,5 @@ using Google.Protobuf; +using Microsoft.Extensions.Logging; namespace AElf.Client.Abp; @@ -7,6 +8,8 @@ public class ContractServiceBase private readonly IAElfClientService _clientService; private string SmartContractName { get; } + public ILogger Logger { get; set; } + protected ContractServiceBase(IAElfClientService clientService, string smartContractName) { _clientService = clientService; @@ -33,6 +36,7 @@ protected async Task PerformGetTransactionResultAsync(string txResult = await _clientService.GetTransactionResultAsync(transactionId, useClientAlias); } while (txResult.Status == TransactionResultStatus.Pending); + Logger.LogInformation("{TxResult}", txResult); return txResult; } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/IAElfClientProvider.cs b/src/AElf.Client.Abp/IAElfClientProvider.cs index c27b8a9..73b3f4c 100644 --- a/src/AElf.Client.Abp/IAElfClientProvider.cs +++ b/src/AElf.Client.Abp/IAElfClientProvider.cs @@ -17,7 +17,7 @@ public class AElfClientProvider : Dictionary, IAElfC public AElfClientProvider(IOptionsSnapshot aelfClientOptions, IOptionsSnapshot aelfClientConfigOptions) { - var useCamelCase = aelfClientConfigOptions.Value.UseCamelCase; + var useCamelCase = aelfClientConfigOptions.Value.CamelCase; var clientBuilder = new AElfClientBuilder(); SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetMainChain).UseCamelCase(useCamelCase).Build(), "MainNet", AElfClientConstants.MainChainId, "MainChain", EndpointType.MainNetMainChain.ToString()); diff --git a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs b/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs index 2628eb9..5461aef 100644 --- a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs +++ b/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs @@ -2,9 +2,9 @@ namespace AElf.Client.Options; public class AElfClientConfigOptions { - public string UseClientAlias { get; set; } = "TestNetSidechain"; - public string UseMainChainClientAlias { get; set; } = "TestNetMainChain"; - public string UseSidechainClientAlias { get; set; } = "TestNetSidechain"; - public string UseAccountAlias { get; set; } = "Default"; - public bool UseCamelCase { get; set; } = false; + public string ClientAlias { get; set; } = "TestNetSidechain"; + public string MainChainClientAlias { get; set; } = "TestNetMainChain"; + public string SidechainClientAlias { get; set; } = "TestNetSidechain"; + public string AccountAlias { get; set; } = "Default"; + public bool CamelCase { get; set; } = false; } \ No newline at end of file diff --git a/src/AElf.Client/AElfClientConstants.cs b/src/AElf.Client/AElfClientConstants.cs index 2e0f577..5e37626 100644 --- a/src/AElf.Client/AElfClientConstants.cs +++ b/src/AElf.Client/AElfClientConstants.cs @@ -6,7 +6,7 @@ public class AElfClientConstants public const string LocalEndpoint = "http://127.0.0.1:1726"; public const string MainNetMainChain = "https://aelf-public-node.aelf.io"; public const string MainNetSidechain = "https://tdvv-public-node.aelf.io"; - public const string TestNetMainChain = "https://aelf-test-node.aelf.io"; + public const string TestNetMainChain = "http://54.199.254.157:8000"; public const string TestNetSidechain = "https://tdvw-test-node.aelf.io"; public const int MainChainId = 9992731; public const int SidechainId = 1866392; diff --git a/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj b/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj new file mode 100644 index 0000000..9ceb643 --- /dev/null +++ b/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj @@ -0,0 +1,30 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + diff --git a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs b/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs new file mode 100644 index 0000000..ba7123f --- /dev/null +++ b/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs @@ -0,0 +1,9 @@ +using AElf.Client.Abp.TestBase; + +namespace AElf.Client.Abp.Test; + +public abstract class + AElfClientAbpContractServiceTestBase : AElfClientAbpTestBase +{ + +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs b/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs new file mode 100644 index 0000000..02791f1 --- /dev/null +++ b/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs @@ -0,0 +1,14 @@ +using AElf.Client.Abp.TestBase; +using AElf.Client.Abp.Token; +using Volo.Abp.Modularity; + +namespace AElf.Client.Abp.Test; + +[DependsOn( + typeof(AElfClientAbpTestBaseModule), + typeof(AElfClientTokenModule) + )] +public class AElfClientAbpContractServiceTestModule : AbpModule +{ + +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs new file mode 100644 index 0000000..1d2f073 --- /dev/null +++ b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs @@ -0,0 +1,23 @@ +using AElf.Client.Abp.Token; +using Shouldly; + +namespace AElf.Client.Abp.Test.Token; + +[Trait("Category", "TokenContractService")] +public sealed class TokenServiceTests : AElfClientAbpContractServiceTestBase +{ + private readonly ITokenService _tokenService; + + public TokenServiceTests() + { + _tokenService = GetRequiredService(); + } + + [Theory] + [InlineData("ELF")] + public async Task GetTokenInfoTest(string symbol) + { + var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); + tokenInfo.Symbol.ShouldBe(symbol); + } +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.Test/Usings.cs b/test/AElf.Client.Abp.Test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/test/AElf.Client.Abp.Test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj b/test/AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj new file mode 100644 index 0000000..866a363 --- /dev/null +++ b/test/AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj @@ -0,0 +1,44 @@ + + + + net6.0 + enable + enable + false + + + + + + PreserveNewest + true + PreserveNewest + + + + PreserveNewest + Always + + + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs b/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs new file mode 100644 index 0000000..215b499 --- /dev/null +++ b/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Modularity; +using Volo.Abp.Testing; + +namespace AElf.Client.Abp.TestBase; + +public abstract class AElfClientAbpTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + + protected override void BeforeAddApplication(IServiceCollection services) + { + var builder = new ConfigurationBuilder(); + builder.AddJsonFile("appsettings.json", false); + builder.AddJsonFile("appsettings.secrets.json", true); + services.ReplaceConfiguration(builder.Build()); + } +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs b/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs new file mode 100644 index 0000000..524b9f4 --- /dev/null +++ b/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs @@ -0,0 +1,14 @@ +using Volo.Abp; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; + +namespace AElf.Client.Abp.TestBase; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule) +)] +public class AElfClientAbpTestBaseModule : AbpModule +{ + +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/Usings.cs b/test/AElf.Client.Abp.TestBase/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/test/AElf.Client.Abp.TestBase/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.Abp.TestBase/appsettings.json new file mode 100644 index 0000000..27bbd50 --- /dev/null +++ b/test/AElf.Client.Abp.TestBase/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.secrets.json b/test/AElf.Client.Abp.TestBase/appsettings.secrets.json new file mode 100644 index 0000000..27bbd50 --- /dev/null +++ b/test/AElf.Client.Abp.TestBase/appsettings.secrets.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} \ No newline at end of file From 852e87a91aa3c67e07cd7a76a0d670b016e95d5f Mon Sep 17 00:00:00 2001 From: yiqi Date: Tue, 14 Jun 2022 11:01:18 +0800 Subject: [PATCH 08/21] Initial whitelist service and tests. --- .../TokenManager/TokenManagerHostedService.cs | 7 +- .../AElf.Client.Abp.Token.csproj | 1 + .../AElfClientTokenModule.cs | 6 +- .../SyncTokenInfo/SyncTokenInfoService.cs | 21 +- .../AElf.Client.Abp.Whitelist.csproj | 8 + .../AElfClientWhitelistModule.cs | 9 +- .../IWhitelistService.cs | 8 + .../WhitelistService.cs | 32 + src/AElf.Client.Abp/ContractServiceBase.cs | 14 +- .../AElf.Client.Protobuf.csproj | 3 + .../Protobuf/whitelist_contract.proto | 581 ++++++++++++++++++ .../Token/TokenServiceTests.cs | 25 + .../Whitelist/WhitelistServiceTests.cs | 15 + .../AElf.Client.Abp.TestBase/appsettings.json | 58 +- 14 files changed, 768 insertions(+), 20 deletions(-) create mode 100644 src/AElf.Client.Abp.Whitelist/IWhitelistService.cs create mode 100644 src/AElf.Client.Abp.Whitelist/WhitelistService.cs create mode 100644 src/AElf.Client.Protobuf/Protobuf/whitelist_contract.proto create mode 100644 test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs index 1411a4d..7766cc4 100644 --- a/examples/TokenManager/TokenManagerHostedService.cs +++ b/examples/TokenManager/TokenManagerHostedService.cs @@ -34,14 +34,15 @@ public async Task StartAsync(CancellationToken cancellationToken) await _abpApplication.InitializeAsync(); - var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); - await tokenManagerService.TransferAsync(Address.FromBase58("eyDPrhJdofZ9f7Qdyi8FtbA8BePubP1M3gwfVMs6MnMHHNwik"), - "ELF", 10000_00000000); + var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); + // await tokenManagerService.TransferAsync(Address.FromBase58("eyDPrhJdofZ9f7Qdyi8FtbA8BePubP1M3gwfVMs6MnMHHNwik"), + // "ELF", 10000_00000000); /* await tokenManagerService.CrossChainTransferAsync( Address.FromBase58("2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT"), "ELF", 100000_00000000, EndpointType.TestNetSidechain.ToString()); */ + await tokenManagerService.GetTokenInfoAsync("ELF"); } public async Task StopAsync(CancellationToken cancellationToken) diff --git a/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj b/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj index f007fef..a366b41 100644 --- a/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj +++ b/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj @@ -12,6 +12,7 @@ + diff --git a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs index 6621979..cd96563 100644 --- a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs +++ b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using AElf.Client.Abp.CrossChain; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; @@ -7,7 +8,8 @@ namespace AElf.Client.Abp.Token; [DependsOn( typeof(AElfClientModule), - typeof(CoreAElfModule) + typeof(CoreAElfModule), + typeof(AElfClientCrossChainModule) )] public class AElfClientTokenModule : AbpModule { diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs index cc4983a..0b15ddc 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs +++ b/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs @@ -1,3 +1,4 @@ +using AElf.Client.Abp.CrossChain; using AElf.Client.Options; using AElf.Contracts.MultiToken; using AElf.Types; @@ -12,14 +13,16 @@ namespace AElf.Client.Abp.Token.SyncTokenInfo; public class SyncTokenInfoService : ISyncTokenInfoService, ITransientDependency { private readonly ITokenService _tokenService; + private readonly ICrossChainService _crossChainService; private readonly IAElfClientService _clientService; private readonly AElfClientConfigOptions _clientConfigOptions; public ILogger Logger { get; set; } - public SyncTokenInfoService(ITokenService tokenService, IAElfClientService clientService, - IOptionsSnapshot clientConfigOptions) + public SyncTokenInfoService(ITokenService tokenService, ICrossChainService crossChainService, + IAElfClientService clientService, IOptionsSnapshot clientConfigOptions) { _tokenService = tokenService; + _crossChainService = crossChainService; _clientService = clientService; _clientConfigOptions = clientConfigOptions.Value; @@ -42,18 +45,22 @@ public async Task SyncTokenInfoAsync(string symbol) }; var validateResult = await _tokenService.ValidateTokenInfoExistsAsync(validateInput); + var packagedBlockHeight = validateResult.TransactionResult.BlockNumber; Logger.LogInformation("ValidateTokenInfoExists: {Result}", validateResult.TransactionResult); if (validateResult.TransactionResult.Status == TransactionResultStatus.Mined) { while (true) { - var chainStatus = - await _clientService.GetChainStatusAsync(_clientConfigOptions.MainChainClientAlias); + var syncedMainChainHeight = + await _crossChainService.GetSyncedHeightByChainId(AElfClientConstants.MainChainId); Logger.LogInformation( - "Main chain lib height: {LibHeight}, Validate tx package height: {ValidateHeight}", - chainStatus.LastIrreversibleBlockHeight, validateResult.TransactionResult.BlockNumber); - if (chainStatus.LastIrreversibleBlockHeight - validateResult.TransactionResult.BlockNumber > 150) + "Synced main chain height: {MainChainHeight}, Validate tx package height: {ValidateHeight}", + syncedMainChainHeight, validateResult.TransactionResult.BlockNumber); + if (syncedMainChainHeight >= packagedBlockHeight) + { break; + } + await Task.Delay(AElfTokenConstants.TenSeconds); } diff --git a/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj b/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj index eb2460e..a864077 100644 --- a/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj +++ b/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs b/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs index 0619675..84a2c3d 100644 --- a/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs +++ b/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs @@ -1,5 +1,12 @@ -namespace AElf.Client.Abp.Whitelist; +using Volo.Abp.Modularity; +namespace AElf.Client.Abp.Whitelist; + +[DependsOn( + typeof(AElfClientModule), + typeof(CoreAElfModule) +)] public class AElfClientWhitelistModule { + } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Whitelist/IWhitelistService.cs b/src/AElf.Client.Abp.Whitelist/IWhitelistService.cs new file mode 100644 index 0000000..0c85907 --- /dev/null +++ b/src/AElf.Client.Abp.Whitelist/IWhitelistService.cs @@ -0,0 +1,8 @@ +using AElf.Contracts.Whitelist; + +namespace AElf.Client.Abp.Whitelist; + +public interface IWhitelistService +{ + Task CreateWhitelistAsync(CreateWhitelistInput createWhitelistInput); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Whitelist/WhitelistService.cs b/src/AElf.Client.Abp.Whitelist/WhitelistService.cs new file mode 100644 index 0000000..7032ba4 --- /dev/null +++ b/src/AElf.Client.Abp.Whitelist/WhitelistService.cs @@ -0,0 +1,32 @@ +using AElf.Client.Options; +using AElf.Contracts.Whitelist; +using AElf.Types; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Whitelist; + +public class WhitelistService : ContractServiceBase, IWhitelistService, ITransientDependency +{ + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + + protected WhitelistService(IAElfClientService clientService, + IOptionsSnapshot clientConfigOptions) : base(clientService, + Address.FromBase58("aceGtyU2fVcBkViZcaqZXHHjd7eNAJ6NPwbuFwhqv6He49BS1")) + { + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + } + + public async Task CreateWhitelistAsync(CreateWhitelistInput createWhitelistInput) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var tx = await PerformSendTransactionAsync("CreateWhitelist", createWhitelistInput, useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/ContractServiceBase.cs b/src/AElf.Client.Abp/ContractServiceBase.cs index d70756f..ca3043d 100644 --- a/src/AElf.Client.Abp/ContractServiceBase.cs +++ b/src/AElf.Client.Abp/ContractServiceBase.cs @@ -6,7 +6,8 @@ namespace AElf.Client.Abp; public class ContractServiceBase { private readonly IAElfClientService _clientService; - private string SmartContractName { get; } + protected string SmartContractName { get; } + protected Address? ContractAddress { get; } public ILogger Logger { get; set; } @@ -16,6 +17,12 @@ protected ContractServiceBase(IAElfClientService clientService, string smartCont SmartContractName = smartContractName; } + protected ContractServiceBase(IAElfClientService clientService, Address contractAddress) + { + _clientService = clientService; + ContractAddress = contractAddress; + } + protected async Task PerformSendTransactionAsync(string methodName, IMessage parameter, string useClientAlias, string? smartContractName = null) { @@ -24,6 +31,11 @@ protected async Task PerformSendTransactionAsync(string methodName, smartContractName = SmartContractName; } + if (ContractAddress != null) + { + return await _clientService.SendAsync(ContractAddress.ToBase58(), methodName, parameter, useClientAlias); + } + return await _clientService.SendSystemAsync(smartContractName, methodName, parameter, useClientAlias); } diff --git a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj index 977fcda..3b1cfad 100644 --- a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj +++ b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj @@ -47,6 +47,9 @@ MSBuild:Compile + + MSBuild:Compile + diff --git a/src/AElf.Client.Protobuf/Protobuf/whitelist_contract.proto b/src/AElf.Client.Protobuf/Protobuf/whitelist_contract.proto new file mode 100644 index 0000000..37ce7af --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/whitelist_contract.proto @@ -0,0 +1,581 @@ +syntax = "proto3"; + +package whitelist; + +import "aelf/core.proto"; +import "aelf/options.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; +import "acs1.proto"; + +option csharp_namespace = "AElf.Contracts.Whitelist"; + +service WhitelistContract { + option (aelf.csharp_state) = "AElf.Contracts.Whitelist.WhitelistContractState"; + option (aelf.base) = "acs1.proto"; + + rpc Initialize (google.protobuf.Empty) returns (google.protobuf.Empty) { + } + + //For Managers. + //Create whitelist. + rpc CreateWhitelist (CreateWhitelistInput) returns (aelf.Hash){ + } + + //Add tag info or extraInfo. + rpc AddExtraInfo (AddExtraInfoInput) returns (aelf.Hash){ + } + + //Add multiple addresses to an existing whitelist. + rpc AddAddressInfoListToWhitelist (AddAddressInfoListToWhitelistInput) returns (google.protobuf.Empty){ + } + + //Remove multiple addresses from an existing whitelist. + rpc RemoveAddressInfoListFromWhitelist (RemoveAddressInfoListFromWhitelistInput) returns (google.protobuf.Empty){ + } + + //Remove tag info. + rpc RemoveTagInfo (RemoveTagInfoInput) returns (google.protobuf.Empty){ + } + + //Disable whitelist according to the whitelist_id. + rpc DisableWhitelist (aelf.Hash) returns (google.protobuf.Empty){ + } + + //Re-enable whitelist according to the whitelist_id. + rpc EnableWhitelist (aelf.Hash) returns (google.protobuf.Empty){ + } + + //Update state: Whether the whitelist is allowed to be cloned. + rpc ChangeWhitelistCloneable(ChangeWhitelistCloneableInput) returns (google.protobuf.Empty){ + } + + //Update whitelist extraInfo according to the whitelist_id and extraInfo. + rpc UpdateExtraInfo (UpdateExtraInfoInput) returns (google.protobuf.Empty){ + } + + //Transfer Manager. + rpc TransferManager (TransferManagerInput) returns (google.protobuf.Empty){ + } + + //Add manager. + rpc AddManagers (AddManagersInput) returns (google.protobuf.Empty){ + } + + //Remove manager. + rpc RemoveManagers (RemoveManagersInput) returns (google.protobuf.Empty){ + } + + //Reset whitelist according to the whitelist_id and project_id. + rpc ResetWhitelist (ResetWhitelistInput) returns (google.protobuf.Empty){ + } + + + //For Subscribers. + //Subscribe whitelist. + rpc SubscribeWhitelist (SubscribeWhitelistInput) returns (aelf.Hash){ + } + + // Cancel subscribe according to the subscribe_id. + rpc UnsubscribeWhitelist (aelf.Hash) returns (google.protobuf.Empty){ + } + + //After used,address and extra info will be added into the consumedList. + rpc ConsumeWhitelist (ConsumeWhitelistInput) returns (google.protobuf.Empty){ + } + + //Clone whitelist. + rpc CloneWhitelist (CloneWhitelistInput) returns (aelf.Hash){ + } + + //Add subscribe whitelist manager. + rpc AddSubscribeManagers (AddSubscribeManagersInput) returns (google.protobuf.Empty){ + } + + //Remove subscribe whitelist manager. + rpc RemoveSubscribeManagers (RemoveSubscribeManagersInput) returns (google.protobuf.Empty){ + } + + + //Views. + //Get whitelist_id list according to the manager. + rpc GetWhitelistByManager (aelf.Address) returns (WhitelistIdList){ + option (aelf.is_view) = true; + } + + //Get existing whitelist according to the whitelist_id. + rpc GetWhitelist (aelf.Hash) returns (WhitelistInfo){ + option (aelf.is_view) = true; + } + + //Get whitelist detail extraInfo according to the whitelist_id. + rpc GetWhitelistDetail (aelf.Hash) returns(ExtraInfoList){ + option (aelf.is_view) = true; + } + + //Get whitelist id by project_id. + rpc GetWhitelistByProject(aelf.Hash) returns (WhitelistIdList){ + option (aelf.is_view) = true; + } + + //Get extraInfo according to the tag_id. + rpc GetExtraInfoByTag (GetExtraInfoByTagInput) returns (ExtraInfo){ + option (aelf.is_view) = true; + } + + //Get tag info according to the tag_info_id. + rpc GetTagInfoByHash (aelf.Hash) returns (TagInfo){ + option (aelf.is_view) = true; + } + + //Get tagInfoId list according to the whitelist_id and project_id. + rpc GetExtraInfoIdList(GetExtraInfoIdListInput) returns (HashList){ + option (aelf.is_view) = true; + } + + //Get tagId according to the whitelist_id and address. + rpc GetTagIdByAddress(GetTagIdByAddressInput) returns (aelf.Hash){ + option (aelf.is_view) = true; + } + + //Get TagInfo according to the address and whitelist_id. + rpc GetExtraInfoByAddress(GetExtraInfoByAddressInput) returns (TagInfo){ + option (aelf.is_view) = true; + } + + //Whether the address exists in the whitelist according to the whitelist_id and address. + rpc GetAddressFromWhitelist(GetAddressFromWhitelistInput) returns (google.protobuf.BoolValue){ + option (aelf.is_view) = true; + } + + //Whether the extraInfo (address+TagInfoId) exists in the whitelist according to the whitelist_id and address. + rpc GetExtraInfoFromWhitelist(GetExtraInfoFromWhitelistInput) returns (google.protobuf.BoolValue){ + option (aelf.is_view) = true; + } + + //Whether the tagInfo exists in the whitelist according to the whitelist_id,project_id,tagInfo(tagName,info). + rpc GetTagInfoFromWhitelist(GetTagInfoFromWhitelistInput) returns (google.protobuf.BoolValue){ + option (aelf.is_view) = true; + } + + //Get manager list according to the whitelist_id. + rpc GetManagerList(aelf.Hash) returns (AddressList){ + option (aelf.is_view) = true; + } + + //Get subscribe manager list according to the subscribe_id. + rpc GetSubscribeManagerList(aelf.Hash) returns (AddressList){ + option (aelf.is_view) = true; + } + + //Whether manager exist in whitelist. + rpc GetManagerExistFromWhitelist(GetManagerExistFromWhitelistInput) returns (google.protobuf.BoolValue){ + option (aelf.is_view) = true; + } + + //Get subscribe whitelist info according to the subscribe_id. + rpc GetSubscribeWhitelist (aelf.Hash) returns (SubscribeWhitelistInfo){ + option (aelf.is_view) = true; + } + + //Get subscribe_id list according to the manager. + rpc GetSubscribeIdByManager (aelf.Address) returns (HashList){ + option (aelf.is_view) = true; + } + + //Get consumed list according to the subscribe_id. + rpc GetConsumedList (aelf.Hash) returns (ConsumedList){ + option (aelf.is_view) = true; + } + + //After consumed,get available whitelist according to the subscribe_id. + rpc GetAvailableWhitelist (aelf.Hash) returns (ExtraInfoIdList){ + option (aelf.is_view) = true; + } + + //Whether the extraInfo exist in the available whitelist. + rpc GetFromAvailableWhitelist (GetFromAvailableWhitelistInput) returns (google.protobuf.BoolValue){ + option (aelf.is_view) = true; + } + + +} + +//Structs. + +message WhitelistInfo { + //The whitelist id. + aelf.Hash whitelist_id = 1; + //The project id. + aelf.Hash project_id = 2; + //The list of address and extra info in this whitelist. + ExtraInfoIdList extra_info_id_list = 3; + //Whether the whitelist is available. + bool is_available = 4; + //Whether the whiteList can be cloned. + bool is_cloneable = 5; + string remark = 6; + aelf.Hash clone_from = 7; + aelf.Address creator = 8; + AddressList manager = 9; + StrategyType strategy_type = 10; +} + +//Pricing strategy +message PriceTag{ + string symbol = 1; + int64 amount = 2; +} + +enum StrategyType{ + Basic = 0; + Price = 1; + Customize = 2; +} + +message ExtraInfoIdList { + repeated ExtraInfoId value = 1; +} + +message ExtraInfoId { + AddressList address_list = 1; + aelf.Hash id = 2; +} + +message ExtraInfoList { + repeated ExtraInfo value = 1; +} + +message ExtraInfo { + AddressList address_list = 1; + TagInfo info = 2; +} + +message TagInfo { + string tag_name = 1; + bytes info = 2; +} + +message TagInfoList{ + repeated TagInfo value = 1; +} + +message WhitelistIdList{ + repeated aelf.Hash whitelist_id = 1; +} + +message SubscribeWhitelistInfo { + //The subscribe id. + aelf.Hash subscribe_id = 1; + //The project id. + aelf.Hash project_id = 2; + //The whitelist id. + aelf.Hash whitelist_id = 3; + aelf.Address subscriber = 4; + //Manager list. + AddressList manager_list = 5; +} + +message ConsumedList { + //The subscribe id. + aelf.Hash subscribe_id = 1; + //The whitelist id. + aelf.Hash whitelist_id = 2; + //The consumed address and extra info list in this whitelist. + ExtraInfoIdList extra_info_id_list = 3; +} + +message AddressList { + repeated aelf.Address value = 1; +} + +message HashList{ + repeated aelf.Hash value = 1; +} + +//Inputs. + +//message InitializeInput{ +// +//} + +message CreateWhitelistInput { + ExtraInfoList extra_info_list = 1; + bool is_cloneable = 2; + string remark = 3; + aelf.Address creator = 4; + AddressList manager_list = 5; + aelf.Hash project_id = 6; + StrategyType strategy_type = 7; +} + +message AddAddressInfoListToWhitelistInput { + aelf.Hash whitelist_id = 1; + ExtraInfoIdList extra_info_id_list = 2; +} + +message RemoveAddressInfoListFromWhitelistInput{ + aelf.Hash whitelist_id = 1; + ExtraInfoIdList extra_info_id_list = 2; +} + +message ChangeWhitelistCloneableInput{ + aelf.Hash whitelist_id = 1; + bool is_cloneable = 2; +} + +message AddExtraInfoInput{ + aelf.Hash whitelist_id = 1; + aelf.Hash project_id = 2; + TagInfo tag_info = 3; + AddressList address_list = 4; +} + +message RemoveTagInfoInput{ + aelf.Hash whitelist_id = 1; + aelf.Hash project_id = 2; + aelf.Hash tag_id = 3; +} + +message UpdateExtraInfoInput{ + aelf.Hash whitelist_id = 1; + ExtraInfoId extra_info_list = 2; +} + +message SubscribeWhitelistInput{ + //The project id. + aelf.Hash project_id = 1; + //The whitelist id. + aelf.Hash whitelist_id = 2; + //Subscriber. + aelf.Address subscriber = 3; + //Manager list. + AddressList manager_list = 4; +} + +message ConsumeWhitelistInput{ + aelf.Hash subscribe_id = 1; + aelf.Hash whitelist_id = 2; + ExtraInfoId extra_info_id = 3; +} + +message CloneWhitelistInput{ + aelf.Hash whitelist_id = 1; + aelf.Address creator = 2; + AddressList manager_list = 3; + aelf.Hash project_id = 4; +} + +message TransferManagerInput{ + aelf.Hash whitelist_id = 1; + aelf.Address manager = 2; +} + +message GetFromAvailableWhitelistInput{ + aelf.Hash subscribe_id = 1; + ExtraInfoId extra_info_id = 2; +} + +message AddManagersInput{ + aelf.Hash whitelist_id = 1; + AddressList manager_list = 2; +} + +message AddSubscribeManagersInput{ + aelf.Hash subscribe_id = 1; + AddressList manager_list = 2; +} + +message RemoveManagersInput{ + aelf.Hash whitelist_id = 1; + AddressList manager_list = 2; +} + +message RemoveSubscribeManagersInput{ + aelf.Hash subscribe_id = 1; + AddressList manager_list = 2; +} + +message GetTagIdByAddressInput{ + aelf.Hash whitelist_id = 1; + aelf.Address address = 2; +} + +message GetExtraInfoByAddressInput{ + aelf.Hash whitelist_id = 1; + aelf.Address address = 2; +} + +message GetExtraInfoIdListInput{ + aelf.Hash whitelist_id = 1; + aelf.Hash project_id = 2; +} + +message GetExtraInfoByTagInput{ + aelf.Hash whitelist_id = 1; + aelf.Hash tag_info_id = 2; +} + +message GetAddressFromWhitelistInput{ + aelf.Hash whitelist_id = 1; + aelf.Address address = 2; +} + +message GetExtraInfoFromWhitelistInput{ + aelf.Hash whitelist_id = 1; + ExtraInfoId extra_info_id = 2; +} + +message GetTagInfoFromWhitelistInput{ + aelf.Hash whitelist_id = 1; + aelf.Hash project_id = 2; + TagInfo tag_info = 3; +} + +message GetManagerExistFromWhitelistInput{ + aelf.Hash whitelist_id = 1; + aelf.Address manager = 2; +} + +message ResetWhitelistInput{ + aelf.Hash whitelist_id = 1; + aelf.Hash project_id = 2; +} + +//Events. + +message WhitelistCreated { + option (aelf.is_event) = true; + //The whitelist id. + aelf.Hash whitelist_id = 1; + //The list of address and extra info in this whitelist. + ExtraInfoIdList extra_info_id_list = 2; + //Whether the whitelist is available. + bool is_available = 3; + bool is_cloneable = 4; + string remark = 5; + aelf.Hash clone_from = 6; + aelf.Address creator = 7; + AddressList manager = 8; + aelf.Hash project_id = 9; + StrategyType strategy_type = 10; + +} + +message WhitelistSubscribed { + option (aelf.is_event) = true; + //The subscribe id. + aelf.Hash subscribe_id = 1; + //The project id. + aelf.Hash project_id = 2; + //The whitelist id. + aelf.Hash whitelist_id = 3; + //Subscriber. + aelf.Address subscriber = 4; + //Manager list. + AddressList manager_list = 5; +} + +message WhitelistUnsubscribed{ + option (aelf.is_event) = true; + aelf.Hash subscribe_id = 1; + aelf.Hash project_id = 2; + aelf.Hash whitelist_id = 3; +} + +message WhitelistAddressInfoAdded { + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + ExtraInfoIdList extra_info_id_list = 2; +} + +message WhitelistAddressInfoRemoved { + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + ExtraInfoIdList extra_info_id_list = 2; +} + +message WhitelistDisabled { + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + bool is_available = 2; +} + +message WhitelistReenable{ + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + bool is_available = 2; +} + +message ConsumedListAdded { + option (aelf.is_event) = true; + aelf.Hash subscribe_id = 1; + aelf.Hash whitelist_id = 2; + ExtraInfoIdList extra_info_id_list = 3; +} + +message IsCloneableChanged{ + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + bool is_cloneable = 2; +} + +message TagInfoAdded{ + option (aelf.is_event) = true; + aelf.Hash tag_info_id = 1; + TagInfo tag_info = 2; + aelf.Hash project_id = 3; + aelf.Hash whitelist_id = 4; +} + +message TagInfoRemoved{ + option (aelf.is_event) = true; + aelf.Hash tag_info_id = 1; + TagInfo tag_info = 2; + aelf.Hash project_id = 3; + aelf.Hash whitelist_id = 4; +} + +message ExtraInfoUpdated { + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + ExtraInfoId extra_info_id_before = 2; + ExtraInfoId extra_info_id_after = 3; +} + +message ManagerTransferred{ + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + aelf.Address transfer_from = 2; + aelf.Address transfer_to = 3; +} + +message ManagerAdded{ + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + AddressList manager_list = 2; +} + +message ManagerRemoved{ + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + AddressList manager_list = 2; +} + +message WhitelistReset{ + option (aelf.is_event) = true; + aelf.Hash whitelist_id = 1; + aelf.Hash project_id = 2; +} + +message SubscribeManagerAdded{ + option (aelf.is_event) = true; + aelf.Hash subscribe_id = 1; + AddressList manager_list = 2; +} + +message SubscribeManagerRemoved{ + option (aelf.is_event) = true; + aelf.Hash subscribe_id = 1; + AddressList manager_list = 2; +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs index 1d2f073..2c1623f 100644 --- a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs @@ -1,4 +1,7 @@ using AElf.Client.Abp.Token; +using AElf.Client.Abp.Token.SyncTokenInfo; +using AElf.Contracts.MultiToken; +using AElf.Types; using Shouldly; namespace AElf.Client.Abp.Test.Token; @@ -7,10 +10,12 @@ namespace AElf.Client.Abp.Test.Token; public sealed class TokenServiceTests : AElfClientAbpContractServiceTestBase { private readonly ITokenService _tokenService; + private readonly ISyncTokenInfoQueueService _syncTokenInfoQueueService; public TokenServiceTests() { _tokenService = GetRequiredService(); + _syncTokenInfoQueueService = GetRequiredService(); } [Theory] @@ -20,4 +25,24 @@ public async Task GetTokenInfoTest(string symbol) var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); tokenInfo.Symbol.ShouldBe(symbol); } + + [Theory] + [InlineData("2nSXrp4iM3A1gB5WKXjkwJQwy56jzcw1ESNpVnWywnyjXFixGc", "ELF", 10_00000000)] + public async Task TransferTest(string address, string symbol, long amount) + { + var result = await _tokenService.TransferAsync(new TransferInput + { + To = Address.FromBase58(address), + Symbol = symbol, + Amount = amount + }); + result.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined); + } + + [Theory] + [InlineData("BA994198147")] + public async Task SyncTokenInfoTest(string symbol) + { + _syncTokenInfoQueueService.Enqueue(symbol); + } } \ No newline at end of file diff --git a/test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs b/test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs new file mode 100644 index 0000000..9a7ba17 --- /dev/null +++ b/test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs @@ -0,0 +1,15 @@ +using AElf.Contracts.Whitelist; + +namespace AElf.Client.Abp.Test.Whitelist; + +[Trait("Category", "WhitelistContractService")] +public class WhitelistServiceTests : AElfClientAbpContractServiceTestBase +{ + [Theory] + [InlineData(true)] + public async Task CreateWhitelistTest(bool isClonable) + { + var extraInfoList = new ExtraInfoList(); + + } +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.Abp.TestBase/appsettings.json index 27bbd50..5bff94b 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.json +++ b/test/AElf.Client.Abp.TestBase/appsettings.json @@ -1,9 +1,55 @@ { - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" } + }, + "AElfClient": { + "ClientConfigList": [ + { + "Alias": "Example", + "Endpoint": "http://192.168.0.31:6800", + "UserName": "", + "Password": "", + "Timeout": 100 + } + ] + }, + "AElfAccount": { + "KeyDirectory": "", + "AccountConfigList": [ + { + "Alias": "Ean", + "PrivateKey": "8cc296e44d9e8881942e75a21ebc116ed3f29e39e0eaace1c92dc21e86d215c3", + "Address": "2AiXjNszZwUMdonm2RYb3GsB3aLUU3hkD1fxoazMwqPAamerLQ", + "Password": "aelftest" + }, + { + "Alias": "Test1", + "Address": "215tht8WyakoxNK4SvsR132jChydxE27RtJN8HSk1UXxuDQnmM", + "Password": "aelftest" + }, + { + "Alias": "Test2", + "PrivateKey": "5e2f12d13e4527ad1128e07db00f1614ec6b8b51662e68d4fdb42125ab384195" + }, + { + "Alias": "eanz", + "Address": "2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT", + "Password": "zhaoyiqi" + } + ] + }, + "AElfToken": { + "NFTContractAddress": "" + }, + "AElfClientConfig": { + "ClientAlias": "TestNetSidechain", + "MainChainClientAlias": "TestNetMainChain", + "SidechainClientAlias": "TestNetSidechain", + "AccountAlias": "eanz", + "CamelCase": false + } } \ No newline at end of file From 512b3bd11f8c947a439126a39b2a8f403ffac19f Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 15 Jun 2022 14:44:13 +0800 Subject: [PATCH 09/21] Cross chain create nft protocol. --- examples/TokenManager/TokenManagerService.cs | 5 ++ src/AElf.Client.Abp.Token/ITokenService.cs | 6 +- .../TokenService.Send.cs | 70 ++++++++++++------- .../TokenService.View.cs | 4 +- src/AElf.Client.Abp/ContractServiceBase.cs | 2 +- .../Token/TokenServiceTests.cs | 13 +++- .../AElf.Client.Abp.TestBase/appsettings.json | 2 +- 7 files changed, 70 insertions(+), 32 deletions(-) diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs index f429adf..5f952bf 100644 --- a/examples/TokenManager/TokenManagerService.cs +++ b/examples/TokenManager/TokenManagerService.cs @@ -61,4 +61,9 @@ await _tokenService.TransferAsync(new TransferInput Amount = amount, }); } + + public async Task GetBalanceAsync(Address owner, string symbol) + { + return (await _tokenService.GetTokenBalanceAsync(symbol, owner)).Balance; + } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Abp.Token/ITokenService.cs index df431ff..a49efdb 100644 --- a/src/AElf.Client.Abp.Token/ITokenService.cs +++ b/src/AElf.Client.Abp.Token/ITokenService.cs @@ -13,9 +13,11 @@ public interface ITokenService Task ValidateTokenInfoExistsAsync(ValidateTokenInfoExistsInput validateTokenInfoExistsInput); Task CrossChainCreateTokenAsync(CrossChainCreateTokenInput crossChainCreateTokenInput); Task CrossChainTransferAsync(CrossChainTransferInput crossChainTransferInput, - string useClientAlias); + string clientAlias); Task CrossChainReceiveTokenAsync(CrossChainReceiveTokenInput crossChainReceiveTokenInput, - string useClientAlias); + string clientAlias); + + Task CrossChainCreateNFTProtocolAsync(CrossChainCreateInput crossChainCreateInput); Task TransferAsync(TransferInput transferInput); diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index 39c1426..a4ae17f 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -1,6 +1,7 @@ using AElf.Client.Options; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; +using AElf.Types; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using CreateInput = AElf.Contracts.MultiToken.CreateInput; @@ -11,106 +12,123 @@ namespace AElf.Client.Abp.Token; public partial class TokenService : ContractServiceBase, ITokenService, ITransientDependency { private readonly IAElfClientService _clientService; + private readonly AElfTokenOptions _tokenOptions; private readonly AElfClientConfigOptions _clientConfigOptions; - public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions) - : base(clientService, AElfTokenConstants.TokenSmartContractName) + public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions, + IOptionsSnapshot tokenOptions) : base(clientService, + AElfTokenConstants.TokenSmartContractName) { _clientService = clientService; + _tokenOptions = tokenOptions.Value; _clientConfigOptions = clientConfigOptions.Value; } public async Task CreateTokenAsync(CreateInput createInput) { - var useClientAlias = PreferGetUseMainChainClientAlias(); - var tx = await PerformSendTransactionAsync("Create", createInput, useClientAlias); + var clientAlias = PreferGetUseMainChainClientAlias(); + var tx = await PerformSendTransactionAsync("Create", createInput, clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task CreateNFTProtocolAsync(Contracts.NFT.CreateInput createInput) { - var useClientAlias = PreferGetUseMainChainClientAlias(); - var tx = await PerformSendTransactionAsync("Create", createInput, useClientAlias); + var clientAlias = PreferGetUseMainChainClientAlias(); + var tx = await PerformSendTransactionAsync("Create", createInput, clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task MintNFTAsync(MintInput mintInput) { - var useClientAlias = _clientConfigOptions.ClientAlias; - var tx = await PerformSendTransactionAsync("Mint", mintInput, useClientAlias); + var clientAlias = _clientConfigOptions.ClientAlias; + var tx = await PerformSendTransactionAsync("Mint", mintInput, clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task ValidateTokenInfoExistsAsync( ValidateTokenInfoExistsInput validateTokenInfoExistsInput) { - var useClientAlias = PreferGetUseMainChainClientAlias(); + var clientAlias = PreferGetUseMainChainClientAlias(); var tx = await PerformSendTransactionAsync("ValidateTokenInfoExists", validateTokenInfoExistsInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task CrossChainCreateTokenAsync( CrossChainCreateTokenInput crossChainCreateTokenInput) { - var useClientAlias = PreferGetUseSidechainClientAlias(); - var tx = await PerformSendTransactionAsync("CrossChainCreateToken", crossChainCreateTokenInput, useClientAlias); + var clientAlias = PreferGetUseSidechainClientAlias(); + var tx = await PerformSendTransactionAsync("CrossChainCreateToken", crossChainCreateTokenInput, clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task CrossChainTransferAsync(CrossChainTransferInput crossChainTransferInput, - string useClientAlias) + string clientAlias) { var tx = await _clientService.SendSystemAsync(AElfTokenConstants.TokenSmartContractName, "CrossChainTransfer", - crossChainTransferInput, useClientAlias); + crossChainTransferInput, clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task CrossChainReceiveTokenAsync( - CrossChainReceiveTokenInput crossChainReceiveTokenInput, string useClientAlias) + CrossChainReceiveTokenInput crossChainReceiveTokenInput, string clientAlias) { var tx = await PerformSendTransactionAsync("CrossChainReceiveToken", crossChainReceiveTokenInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) + }; + } + + public async Task CrossChainCreateNFTProtocolAsync( + CrossChainCreateInput crossChainCreateInput) + { + var clientAlias = PreferGetUseSidechainClientAlias(); + ContractAddress = Address.FromBase58(_tokenOptions.NFTContractAddress); + var tx = await PerformSendTransactionAsync("CrossChainCreate", crossChainCreateInput, + clientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task TransferAsync(TransferInput transferInput) { - var useClientAlias = _clientConfigOptions.ClientAlias; + var clientAlias = _clientConfigOptions.ClientAlias; var tx = await PerformSendTransactionAsync("Transfer", transferInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } diff --git a/src/AElf.Client.Abp.Token/TokenService.View.cs b/src/AElf.Client.Abp.Token/TokenService.View.cs index 0476d3c..7a2bb8d 100644 --- a/src/AElf.Client.Abp.Token/TokenService.View.cs +++ b/src/AElf.Client.Abp.Token/TokenService.View.cs @@ -1,6 +1,7 @@ using AElf.Contracts.MultiToken; using AElf.Types; using Google.Protobuf; +using Microsoft.Extensions.Logging; namespace AElf.Client.Abp.Token; @@ -8,7 +9,7 @@ public partial class TokenService { public async Task GetTokenInfoAsync(string symbol) { - var useClientAlias = _clientConfigOptions.ClientAlias; + var useClientAlias = PreferGetUseMainChainClientAlias(); var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetTokenInfo", new GetTokenInfoInput { @@ -30,6 +31,7 @@ public async Task GetTokenBalanceAsync(string symbol, Address }, useClientAlias); var balance = new GetBalanceOutput(); balance.MergeFrom(result); + Logger.LogInformation("{Address} {Symbol} {Balance}", owner, symbol, balance.Balance); return balance; } diff --git a/src/AElf.Client.Abp/ContractServiceBase.cs b/src/AElf.Client.Abp/ContractServiceBase.cs index ca3043d..3cfaf17 100644 --- a/src/AElf.Client.Abp/ContractServiceBase.cs +++ b/src/AElf.Client.Abp/ContractServiceBase.cs @@ -7,7 +7,7 @@ public class ContractServiceBase { private readonly IAElfClientService _clientService; protected string SmartContractName { get; } - protected Address? ContractAddress { get; } + protected Address? ContractAddress { get; set; } public ILogger Logger { get; set; } diff --git a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs index 2c1623f..ef669e8 100644 --- a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs @@ -1,8 +1,9 @@ using AElf.Client.Abp.Token; using AElf.Client.Abp.Token.SyncTokenInfo; -using AElf.Contracts.MultiToken; +using AElf.Contracts.NFT; using AElf.Types; using Shouldly; +using TransferInput = AElf.Contracts.MultiToken.TransferInput; namespace AElf.Client.Abp.Test.Token; @@ -45,4 +46,14 @@ public async Task SyncTokenInfoTest(string symbol) { _syncTokenInfoQueueService.Enqueue(symbol); } + + [Theory] + [InlineData("CO429872652")] + public async Task CrossChainCreateNFTProtocolTest(string symbol) + { + await _tokenService.CrossChainCreateNFTProtocolAsync(new CrossChainCreateInput + { + Symbol = symbol + }); + } } \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.Abp.TestBase/appsettings.json index 5bff94b..f24b815 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.json +++ b/test/AElf.Client.Abp.TestBase/appsettings.json @@ -43,7 +43,7 @@ ] }, "AElfToken": { - "NFTContractAddress": "" + "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" }, "AElfClientConfig": { "ClientAlias": "TestNetSidechain", From 65dbeab4dbc6f491ddb62bb588b0f1ec45bdf4e3 Mon Sep 17 00:00:00 2001 From: yiqi Date: Thu, 16 Jun 2022 11:12:14 +0800 Subject: [PATCH 10/21] A new SetPrivateKey method. --- src/AElf.Client.Abp.Token/ITokenService.cs | 2 ++ .../TokenService.Send.cs | 13 +++++++++ src/AElf.Client.Abp/IAElfAccountProvider.cs | 27 ++++++++++++++++--- .../Token/TokenServiceTests.cs | 15 +++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Abp.Token/ITokenService.cs index a49efdb..11da2ef 100644 --- a/src/AElf.Client.Abp.Token/ITokenService.cs +++ b/src/AElf.Client.Abp.Token/ITokenService.cs @@ -21,6 +21,8 @@ Task CrossChainReceiveTokenAsync(CrossChainReceiveTokenIn Task TransferAsync(TransferInput transferInput); + Task AddMintersAsync(AddMintersInput addMintersInput); + Task GetTokenInfoAsync(string symbol); Task GetTokenBalanceAsync(string symbol, Address owner); Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender); diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index a4ae17f..96f3dd9 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -132,6 +132,19 @@ public async Task TransferAsync(TransferInput transferInp }; } + public async Task AddMintersAsync(AddMintersInput addMintersInput) + { + var clientAlias = _clientConfigOptions.ClientAlias; + ContractAddress = Address.FromBase58(_tokenOptions.NFTContractAddress); + var tx = await PerformSendTransactionAsync("AddMinters", addMintersInput, + clientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) + }; + } + private string PreferGetUseMainChainClientAlias() { return !string.IsNullOrEmpty(_clientConfigOptions.MainChainClientAlias) diff --git a/src/AElf.Client.Abp/IAElfAccountProvider.cs b/src/AElf.Client.Abp/IAElfAccountProvider.cs index f3a1809..a0648e8 100644 --- a/src/AElf.Client.Abp/IAElfAccountProvider.cs +++ b/src/AElf.Client.Abp/IAElfAccountProvider.cs @@ -13,11 +13,14 @@ public interface IAElfAccountProvider { byte[] GetPrivateKey(string? alias = null, string? address = null); void SetPrivateKey(byte[] privateKey, string? alias = null, string? address = null); + void SetPrivateKey(string address, string password, string? alias = null); } public class AElfAccountProvider : Dictionary, IAElfAccountProvider, ISingletonDependency { private readonly IKeyDirectoryProvider _keyDirectoryProvider; + private readonly AElfAccountOptions _aelfAccountOptions; + private readonly KeyStoreService _keyStoreService; public ILogger Logger { get; set; } @@ -26,10 +29,10 @@ public AElfAccountProvider(IKeyDirectoryProvider keyDirectoryProvider, { Logger = NullLogger.Instance; _keyDirectoryProvider = keyDirectoryProvider; + _aelfAccountOptions = aelfAccountOptions.Value; var defaultPrivateKey = ByteArrayHelper.HexStringToByteArray(AElfClientConstants.DefaultPrivateKey); - SetPrivateKey(defaultPrivateKey, "Default", Address.FromPublicKey(defaultPrivateKey).ToBase58()); - - var keyStoreService = new KeyStoreService(); + SetPrivateKey(defaultPrivateKey, "Default", Address.FromPublicKey(defaultPrivateKey).ToBase58()); + _keyStoreService = new KeyStoreService(); foreach (var accountConfig in aelfAccountOptions.Value.AccountConfigList) { @@ -40,7 +43,7 @@ public AElfAccountProvider(IKeyDirectoryProvider keyDirectoryProvider, { using var textReader = File.OpenText(keyFilePath); var json = textReader.ReadToEnd(); - return keyStoreService.DecryptKeyStoreFromJson(accountConfig.Password, json); + return _keyStoreService.DecryptKeyStoreFromJson(accountConfig.Password, json); })); SetPrivateKey(privateKey, accountConfig.Alias, accountConfig.Address); } @@ -75,6 +78,22 @@ public void SetPrivateKey(byte[] privateKey, string? alias = null, string? addre }, privateKey); } + public void SetPrivateKey(string address, string password, string? alias = null) + { + var keyFilePath = GetKeyFileFullPath(address, _aelfAccountOptions.KeyDirectory); + var privateKey = AsyncHelper.RunSync(() => Task.Run(() => + { + using var textReader = File.OpenText(keyFilePath); + var json = textReader.ReadToEnd(); + return _keyStoreService.DecryptKeyStoreFromJson(password, json); + })); + TryAdd(new AElfAccountInfo + { + Alias = alias, + Address = address + }, privateKey); + } + private string GetKeyFileFullPath(string address, string configuredKeyDirectory) { var dirPath = GetKeystoreDirectoryPath(configuredKeyDirectory); diff --git a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs index ef669e8..85039dc 100644 --- a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs @@ -56,4 +56,19 @@ await _tokenService.CrossChainCreateNFTProtocolAsync(new CrossChainCreateInput Symbol = symbol }); } + + [Theory] + [InlineData("BA417054001", "JQkVTWz5HXxEmNXzTtsAVHC7EUTeiFktzoFUu9TyA6MWngkem")] + public async Task AddMintersTest(string symbol, string addressBase58) + { + var address = Address.FromBase58(addressBase58); + await _tokenService.AddMintersAsync(new AddMintersInput + { + Symbol = symbol, + MinterList = new MinterList + { + Value = { address } + } + }); + } } \ No newline at end of file From 69d2592aecb9575d84aa21164397fba4fe9b2225 Mon Sep 17 00:00:00 2001 From: YueZh127 Date: Fri, 17 Jun 2022 16:54:12 +0800 Subject: [PATCH 11/21] Deploy contract --- .../AElf.Client.Abp.Consensus.AEDPoS.csproj | 8 + .../AElfClientAEDPoSModule.cs | 10 +- .../AElfConsensusConstants.cs | 7 + .../ConsensusService.Send.cs | 18 ++ .../ConsensusService.View.cs | 19 ++ .../IConsensusService.cs | 8 + .../AElf.Client.Abp.Genesis.csproj | 11 ++ .../AElfClientGenesisModule.cs | 22 ++- .../AElfContractOption.cs | 9 + .../AElfGenesisConstants.cs | 5 + .../DeployContract/DeployContractService.cs | 168 ++++++++++++++++++ .../DeployContract/IDeployContractService.cs | 8 + .../GenesisService.Send.cs | 72 ++++++++ .../GenesisService.View.cs | 28 +++ .../IGenesisService.cs | 19 ++ .../AElf.Client.Abp.Parliament.csproj | 9 + .../AElfClientParliamentModule.cs | 10 +- .../AElfParliamentConstants.cs | 6 + .../IParliamentService.cs | 15 ++ .../ParliamentService.Send.cs | 32 ++++ .../ParliamentService.View.cs | 29 +++ .../AElfClientTokenModule.cs | 2 +- src/AElf.Client.Abp.Token/AElfTokenOptions.cs | 1 + src/AElf.Client.Abp/AElfClientModule.cs | 1 + src/AElf.Client.Abp/AElfClientService.Send.cs | 27 ++- src/AElf.Client.Abp/ContractServiceBase.cs | 1 + src/AElf.Client.Abp/IAElfAccountProvider.cs | 19 +- src/AElf.Client.Abp/IAElfClientService.cs | 4 +- .../Options/AElfMinerAccountOptions.cs | 6 + .../AElf.Client.Protobuf.csproj | 12 ++ .../AElf.Client.Abp.Test.csproj | 1 + .../AElfClientAbpContractServiceTestModule.cs | 6 +- .../Genesis/GenesisServiceTests.cs | 27 +++ .../AElf.Client.Abp.TestBase/appsettings.json | 4 +- .../appsettings.secrets.json | 3 + 35 files changed, 610 insertions(+), 17 deletions(-) create mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/AElfConsensusConstants.cs create mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.Send.cs create mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.View.cs create mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/IConsensusService.cs create mode 100644 src/AElf.Client.Abp.Genesis/AElfContractOption.cs create mode 100644 src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs create mode 100644 src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs create mode 100644 src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs create mode 100644 src/AElf.Client.Abp.Genesis/GenesisService.Send.cs create mode 100644 src/AElf.Client.Abp.Genesis/GenesisService.View.cs create mode 100644 src/AElf.Client.Abp.Genesis/IGenesisService.cs create mode 100644 src/AElf.Client.Abp.Parliament/AElfParliamentConstants.cs create mode 100644 src/AElf.Client.Abp.Parliament/IParliamentService.cs create mode 100644 src/AElf.Client.Abp.Parliament/ParliamentService.Send.cs create mode 100644 src/AElf.Client.Abp.Parliament/ParliamentService.View.cs create mode 100644 src/AElf.Client.Abp/Options/AElfMinerAccountOptions.cs create mode 100644 test/AElf.Client.Abp.Test/Genesis/GenesisServiceTests.cs diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj b/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj index eb2460e..a864077 100644 --- a/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs index 51f969f..0b9cb9b 100644 --- a/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs @@ -1,5 +1,11 @@ -namespace AElf.Client.Abp.Consensus.AEDPoS; +using Volo.Abp.Modularity; -public class AElfClientAEDPoSModule +namespace AElf.Client.Abp.Consensus.AEDPoS; + +[DependsOn( + typeof(AElfClientModule), + typeof(CoreAElfModule) +)] +public class AElfClientAEDPoSModule : AbpModule { } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElfConsensusConstants.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfConsensusConstants.cs new file mode 100644 index 0000000..a7b84e7 --- /dev/null +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfConsensusConstants.cs @@ -0,0 +1,7 @@ +namespace AElf.Client.Abp.Consensus.AEDPoS; + +public class AElfConsensusConstants +{ + public const string ConsensusSmartContractName = "AElf.ContractNames.Consensus"; + +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.Send.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.Send.cs new file mode 100644 index 0000000..d38532d --- /dev/null +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.Send.cs @@ -0,0 +1,18 @@ +using AElf.Client.Options; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Consensus.AEDPoS; + +public partial class ConsensusService : ContractServiceBase, IConsensusService, ITransientDependency +{ + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + + public ConsensusService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions) + : base(clientService, AElfConsensusConstants.ConsensusSmartContractName) + { + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.View.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.View.cs new file mode 100644 index 0000000..d577842 --- /dev/null +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/ConsensusService.View.cs @@ -0,0 +1,19 @@ +using AElf.Contracts.Consensus.AEDPoS; +using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; + +namespace AElf.Client.Abp.Consensus.AEDPoS; + +public partial class ConsensusService +{ + + public async Task GetCurrentMinerList() + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewSystemAsync(AElfConsensusConstants.ConsensusSmartContractName, "GetCurrentMinerList", + new Empty(), useClientAlias); + var minerList = new MinerList(); + minerList.MergeFrom(result); + return minerList; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/IConsensusService.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/IConsensusService.cs new file mode 100644 index 0000000..0d8b8fd --- /dev/null +++ b/src/AElf.Client.Abp.Consensus.AEDPoS/IConsensusService.cs @@ -0,0 +1,8 @@ +using AElf.Contracts.Consensus.AEDPoS; + +namespace AElf.Client.Abp.Consensus.AEDPoS; + +public interface IConsensusService +{ + Task GetCurrentMinerList(); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj b/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj index eb2460e..1d3f043 100644 --- a/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj +++ b/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj @@ -6,4 +6,15 @@ enable + + + + + + + + + + + diff --git a/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs b/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs index 6aa310f..831b92b 100644 --- a/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs +++ b/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs @@ -1,5 +1,23 @@ -namespace AElf.Client.Abp.Genesis; +using AElf.Client.Abp.Consensus.AEDPoS; +using AElf.Client.Abp.Parliament; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Modularity; -public class AElfClientGenesisModule +namespace AElf.Client.Abp.Genesis; + +[DependsOn(typeof(AElfClientModule), + typeof(CoreAElfModule), + typeof(AElfClientParliamentModule), + typeof(AElfClientAEDPoSModule))] +public class AElfClientGenesisModule : AbpModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(configuration.GetSection("AElfContract")); + } + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/AElfContractOption.cs b/src/AElf.Client.Abp.Genesis/AElfContractOption.cs new file mode 100644 index 0000000..0a9de55 --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/AElfContractOption.cs @@ -0,0 +1,9 @@ +namespace AElf.Client.Abp.Genesis; + +public class AElfContractOption +{ + public string NFTContractAddress { get; set; } + + public string GenesisContractAddress { get; set; } + public string ContractDirectory { get; set; } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs b/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs new file mode 100644 index 0000000..bda4812 --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Abp.Genesis; + +public class AElfGenesisConstants +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs b/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs new file mode 100644 index 0000000..f21889f --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs @@ -0,0 +1,168 @@ +using AElf.Client.Abp.Consensus.AEDPoS; +using AElf.Client.Abp.Infrastructure; +using AElf.Client.Abp.Parliament; +using AElf.Standards.ACS0; +using AElf.Standards.ACS3; +using AElf.Types; +using Google.Protobuf; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Genesis.DeployContract; + +public class DeployContractService : IDeployContractService, ITransientDependency +{ + private readonly IGenesisService _genesisService; + private readonly IParliamentService _parliamentService; + private readonly IConsensusService _consensusService; + + private readonly IKeyDirectoryProvider _keyDirectoryProvider; + private readonly AElfContractOption _contractOption; + + + private ILogger Logger { get; set; } + + public DeployContractService( + IGenesisService genesisService, + IConsensusService consensusService, + IParliamentService parliamentService, + IKeyDirectoryProvider keyDirectoryProvider, + IOptionsSnapshot contractOption) + { + _parliamentService = parliamentService; + _genesisService = genesisService; + _consensusService = consensusService; + _keyDirectoryProvider = keyDirectoryProvider; + _contractOption = contractOption.Value; + + Logger = NullLogger.Instance; + } + + public async Task DeployContract(string contractFileName) + { + Logger.LogInformation($"Deploy contract: {contractFileName}"); + var input = await ContractDeploymentInput(contractFileName); + var proposalNewContact = await _genesisService.ProposeNewContract(input); + Logger.LogInformation("ProposalNewContact: {Result}", proposalNewContact.TransactionResult); + if (proposalNewContact.TransactionResult.Status != TransactionResultStatus.Mined) return null; + + var proposalNewLogs = proposalNewContact.TransactionResult.Logs; + var proposalId = ProposalCreated.Parser + .ParseFrom(proposalNewLogs.First(l => l.Name.Contains(nameof(ProposalCreated))).NonIndexed) + .ProposalId; + var proposalHash = ContractProposed.Parser + .ParseFrom(proposalNewLogs.First(l => l.Name.Contains(nameof(ContractProposed))).NonIndexed) + .ProposedContractInputHash; + + var toBeRelease = await ApproveThroughMiners(proposalId); + if (!toBeRelease) return null; + var releaseApprovedInput = new ReleaseContractInput + { + ProposalId = proposalId, + ProposedContractInputHash = proposalHash + }; + var releaseApprovedContract = await _genesisService.ReleaseApprovedContract(releaseApprovedInput); + Logger.LogInformation("ReleaseApprovedContract: {Result}", releaseApprovedContract.TransactionResult); + if (releaseApprovedContract.TransactionResult.Status != TransactionResultStatus.Mined) return null; + + var releaseApprovedLogs = releaseApprovedContract.TransactionResult.Logs; + var deployProposalId = ProposalCreated.Parser + .ParseFrom(releaseApprovedLogs.First(l => l.Name.Contains(nameof(ProposalCreated))).NonIndexed) + .ProposalId; + + var releaseCodeCheckedInput = new ReleaseContractInput + { + ProposalId = deployProposalId, + ProposedContractInputHash = proposalHash + }; + + if (await CheckProposal(deployProposalId)) + { + var releaseCodeCheckedResult = await _genesisService.ReleaseCodeCheckedContract(releaseCodeCheckedInput); + Logger.LogInformation("ReleaseCodeCheckedResult: {Result}", releaseCodeCheckedResult.TransactionResult); + if (releaseCodeCheckedResult.TransactionResult.Status != TransactionResultStatus.Mined) return null; + var deployAddress = CodeUpdated.Parser.ParseFrom(releaseCodeCheckedResult.TransactionResult.Logs + .First(l => l.Name.Contains(nameof(CodeUpdated))).Indexed + .First()).Address; + Logger.LogInformation($"Contract deploy passed authority, contract address: {deployAddress}"); + return deployAddress; + } + + Logger.LogError("Contract code didn't pass the code check"); + return null; + } + + private async Task ContractDeploymentInput(string name) + { + var contractPath = GetFileFullPath(name, _contractOption.ContractDirectory); + var code = await File.ReadAllBytesAsync(contractPath); + var checkCode = await CheckCode(code); + + if (checkCode) + { + var input = new ContractDeploymentInput + { + Category = 0, + Code = ByteString.CopyFrom(code) + }; + return input; + } + + Logger.LogError("The code is already deployed."); + return new ContractDeploymentInput(); + } + + private async Task ApproveThroughMiners(Hash proposalId) + { + var miners = await _consensusService.GetCurrentMinerList(); + foreach (var minersPubkey in miners.Pubkeys) + { + var miner = Address.FromPublicKey(minersPubkey.ToByteArray()); + var approveResult = await _parliamentService.ApproveAsync(proposalId, null, miner.ToBase58()); + Logger.LogInformation("Approve: {Result}", approveResult.TransactionResult); + } + var toBeRelease = (await _parliamentService.CheckProposal(proposalId)).ToBeReleased; + return toBeRelease; + } + + private async Task CheckProposal(Hash proposalId) + { + var toBeReleased = false; + var sleepTimes = 0; + while (!toBeReleased && sleepTimes < 20) + { + Thread.Sleep(1000); + toBeReleased = (await _parliamentService.CheckProposal(proposalId)).ToBeReleased; + Console.Write("\rCheck proposal status"); + sleepTimes++; + } + + return toBeReleased; + } + + private string GetFileFullPath(string contractName, string contractFileDirectory) + { + var dirPath = GetDirectoryPath(contractFileDirectory); + var filePath = Path.Combine(dirPath, $"{contractName}.dll"); + var filePathWithExtension = File.Exists(filePath) + ? filePath + : Path.Combine(dirPath, $"{contractName}.dll.patched"); + return filePathWithExtension; + } + + private string GetDirectoryPath(string? configuredKeyDirectory) + { + return string.IsNullOrWhiteSpace(configuredKeyDirectory) + ? Path.Combine(_keyDirectoryProvider.GetAppDataPath(), "contracts") + : configuredKeyDirectory; + } + + private async Task CheckCode(byte[] code) + { + var hash = HashHelper.ComputeFrom(code); + var registration = await _genesisService.GetSmartContractRegistrationByCodeHash(hash); + return registration.Equals(new SmartContractRegistration()); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs b/src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs new file mode 100644 index 0000000..35a41fd --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs @@ -0,0 +1,8 @@ +using AElf.Types; + +namespace AElf.Client.Abp.Genesis.DeployContract; + +public interface IDeployContractService +{ + Task DeployContract(string contractFileName); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/GenesisService.Send.cs b/src/AElf.Client.Abp.Genesis/GenesisService.Send.cs new file mode 100644 index 0000000..1c883ab --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/GenesisService.Send.cs @@ -0,0 +1,72 @@ +using AElf.Client.Options; +using AElf.Standards.ACS0; +using AElf.Types; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Genesis; + +public partial class GenesisService : ContractServiceBase, IGenesisService, ITransientDependency +{ + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + private readonly string _contractAddress; + + public GenesisService(IAElfClientService clientService, + IOptionsSnapshot clientConfigOptions, + IOptionsSnapshot contractOptions) : base(clientService, + Address.FromBase58(contractOptions.Value.GenesisContractAddress)) + { + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + _contractAddress = contractOptions.Value.GenesisContractAddress; + } + + public async Task ProposeNewContract(ContractDeploymentInput contractDeploymentInput) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var tx = await _clientService.SendAsync(_contractAddress, "ProposeNewContract", contractDeploymentInput, + useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } + + public async Task ProposeUpdateContract(ContractUpdateInput contractUpdateInput) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var tx = await _clientService.SendAsync(_contractAddress, "ProposeUpdateContract", contractUpdateInput, + useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } + + public async Task ReleaseApprovedContract(ReleaseContractInput releaseContractInput) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var tx = await _clientService.SendAsync(_contractAddress, "ReleaseApprovedContract", releaseContractInput, + useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } + + public async Task ReleaseCodeCheckedContract(ReleaseContractInput releaseContractInput) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var tx = await _clientService.SendAsync(_contractAddress, "ReleaseCodeCheckedContract", releaseContractInput, + useClientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/GenesisService.View.cs b/src/AElf.Client.Abp.Genesis/GenesisService.View.cs new file mode 100644 index 0000000..6ee081e --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/GenesisService.View.cs @@ -0,0 +1,28 @@ +using AElf.Types; +using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; + +namespace AElf.Client.Abp.Genesis; + +public partial class GenesisService +{ + public async Task GetContractDeploymentController() + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewAsync(_contractAddress, "GetContractDeploymentController", + new Empty(), useClientAlias); + var authorityInfo = new AuthorityInfo(); + authorityInfo.MergeFrom(result); + return authorityInfo; + } + + public async Task GetSmartContractRegistrationByCodeHash(Hash codeHash) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewAsync(_contractAddress, "GetSmartContractRegistrationByCodeHash", + codeHash , useClientAlias); + var smartContractRegistration = new SmartContractRegistration(); + smartContractRegistration.MergeFrom(result); + return smartContractRegistration; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/IGenesisService.cs b/src/AElf.Client.Abp.Genesis/IGenesisService.cs new file mode 100644 index 0000000..d6aa3cd --- /dev/null +++ b/src/AElf.Client.Abp.Genesis/IGenesisService.cs @@ -0,0 +1,19 @@ +using AElf.Standards.ACS0; +using AElf.Types; + +namespace AElf.Client.Abp.Genesis; + +public interface IGenesisService +{ + Task ProposeNewContract(ContractDeploymentInput contractDeploymentInput); + + Task ProposeUpdateContract(ContractUpdateInput contractUpdateInput); + + Task ReleaseApprovedContract(ReleaseContractInput releaseContractInput); + + Task ReleaseCodeCheckedContract(ReleaseContractInput releaseContractInput); + + + Task GetContractDeploymentController(); + Task GetSmartContractRegistrationByCodeHash(Hash codeHash); +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj b/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj index eb2460e..6ce9f44 100644 --- a/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj +++ b/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj @@ -6,4 +6,13 @@ enable + + + + + + + + + diff --git a/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs b/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs index f1ec434..a4af851 100644 --- a/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs +++ b/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs @@ -1,5 +1,11 @@ -namespace AElf.Client.Abp.Parliament; +using Volo.Abp.Modularity; -public class AElfClientParliamentModule +namespace AElf.Client.Abp.Parliament; + +[DependsOn( + typeof(AElfClientModule), + typeof(CoreAElfModule) +)] +public class AElfClientParliamentModule : AbpModule { } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Parliament/AElfParliamentConstants.cs b/src/AElf.Client.Abp.Parliament/AElfParliamentConstants.cs new file mode 100644 index 0000000..56a96a4 --- /dev/null +++ b/src/AElf.Client.Abp.Parliament/AElfParliamentConstants.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Abp.Parliament; + +public class AElfParliamentConstants +{ + public const string ParliamentSmartContractName = "AElf.ContractNames.Parliament"; +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Parliament/IParliamentService.cs b/src/AElf.Client.Abp.Parliament/IParliamentService.cs new file mode 100644 index 0000000..50a71e6 --- /dev/null +++ b/src/AElf.Client.Abp.Parliament/IParliamentService.cs @@ -0,0 +1,15 @@ +using AElf.Types; +using AElf.Standards.ACS3; +using AElf.Contracts.Parliament; + +namespace AElf.Client.Abp.Parliament; + +public interface IParliamentService +{ + Task ApproveAsync(Hash proposalId, string? accountAlias, string accountAddress); + + Task CheckProposal(Hash proposalId); + + Task GetOrganization(Address organizationAddress); + +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Parliament/ParliamentService.Send.cs b/src/AElf.Client.Abp.Parliament/ParliamentService.Send.cs new file mode 100644 index 0000000..87b4848 --- /dev/null +++ b/src/AElf.Client.Abp.Parliament/ParliamentService.Send.cs @@ -0,0 +1,32 @@ +using AElf.Client.Options; +using AElf.Standards.ACS3; +using AElf.Types; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace AElf.Client.Abp.Parliament; + +public partial class ParliamentService : ContractServiceBase, IParliamentService, ITransientDependency +{ + private readonly IAElfClientService _clientService; + private readonly AElfClientConfigOptions _clientConfigOptions; + + public ParliamentService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions) + : base(clientService, AElfParliamentConstants.ParliamentSmartContractName) + { + _clientService = clientService; + _clientConfigOptions = clientConfigOptions.Value; + } + + public async Task ApproveAsync(Hash proposalId, string? accountAlias, string address) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var tx = await _clientService.SendSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, "Approve", + proposalId, useClientAlias, accountAlias, address); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + }; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Parliament/ParliamentService.View.cs b/src/AElf.Client.Abp.Parliament/ParliamentService.View.cs new file mode 100644 index 0000000..eb80ef6 --- /dev/null +++ b/src/AElf.Client.Abp.Parliament/ParliamentService.View.cs @@ -0,0 +1,29 @@ +using AElf.Contracts.Parliament; +using AElf.Standards.ACS3; +using AElf.Types; +using Google.Protobuf; + +namespace AElf.Client.Abp.Parliament; + +public partial class ParliamentService +{ + public async Task CheckProposal(Hash proposalId) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, "GetProposal", + proposalId, useClientAlias); + var proposalOutput = new ProposalOutput(); + proposalOutput.MergeFrom(result); + return proposalOutput; + } + + public async Task GetOrganization(Address organizationAddress) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, "GetOrganization", + organizationAddress, useClientAlias); + var organization = new Organization(); + organization.MergeFrom(result); + return organization; + } +} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs index cd96563..340169b 100644 --- a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs +++ b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs @@ -16,7 +16,7 @@ public class AElfClientTokenModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - Configure(options => { configuration.GetSection("AElfToken").Bind(options); }); + Configure(options => { configuration.GetSection("AElfContract").Bind(options); }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/src/AElf.Client.Abp.Token/AElfTokenOptions.cs b/src/AElf.Client.Abp.Token/AElfTokenOptions.cs index a4fab54..a129ee0 100644 --- a/src/AElf.Client.Abp.Token/AElfTokenOptions.cs +++ b/src/AElf.Client.Abp.Token/AElfTokenOptions.cs @@ -3,4 +3,5 @@ namespace AElf.Client.Abp.Token; public class AElfTokenOptions { public string NFTContractAddress { get; set; } + public string ContractDirectory { get; set; } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElfClientModule.cs b/src/AElf.Client.Abp/AElfClientModule.cs index 6b83d19..14b42ca 100644 --- a/src/AElf.Client.Abp/AElfClientModule.cs +++ b/src/AElf.Client.Abp/AElfClientModule.cs @@ -19,6 +19,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) Configure(options => { configuration.GetSection("AElfClient").Bind(options); }); Configure(options => { configuration.GetSection("AElfAccount").Bind(options); }); Configure(options => { configuration.GetSection("AElfClientConfig").Bind(options); }); + Configure(options => { configuration.GetSection("AElfMinerAccount").Bind(options); }); context.Services.AddAutoMapperObjectMapper(); diff --git a/src/AElf.Client.Abp/AElfClientService.Send.cs b/src/AElf.Client.Abp/AElfClientService.Send.cs index 759c85c..a0602a4 100644 --- a/src/AElf.Client.Abp/AElfClientService.Send.cs +++ b/src/AElf.Client.Abp/AElfClientService.Send.cs @@ -1,4 +1,5 @@ using AElf.Client.Dto; +using Castle.Core.Logging; using Google.Protobuf; namespace AElf.Client.Abp; @@ -6,10 +7,10 @@ namespace AElf.Client.Abp; public partial class AElfClientService { public async Task SendAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias) + string clientAlias, string? alias = null, string? address = null) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.AccountAlias); + var aelfAccount = SetAccount(alias, address); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseContract(contractAddress) @@ -21,10 +22,10 @@ public async Task SendAsync(string contractAddress, string methodNa } public async Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias) + string clientAlias, string? alias = null, string? address = null) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.AccountAlias); + var aelfAccount = SetAccount(alias, address); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseSystemContract(systemContractName) @@ -42,4 +43,22 @@ private static async Task PerformSendAsync(AElfClient aelfClient, Transaction tx RawTransaction = tx.ToByteArray().ToHex() }); } + + private byte[] SetAccount(string? alias, string? address) + { + byte[] aelfAccount; + if (!string.IsNullOrWhiteSpace(address)) + { + _aelfAccountProvider.SetPrivateKey(address, _aelfAccountProvider.GetDefaultPassword()); + aelfAccount = _aelfAccountProvider.GetPrivateKey(null, address); + } + else + { + if (string.IsNullOrWhiteSpace(alias)) + alias = _clientConfigOptions.AccountAlias; + aelfAccount = _aelfAccountProvider.GetPrivateKey(alias); + } + + return aelfAccount; + } } \ No newline at end of file diff --git a/src/AElf.Client.Abp/ContractServiceBase.cs b/src/AElf.Client.Abp/ContractServiceBase.cs index 3cfaf17..46f8617 100644 --- a/src/AElf.Client.Abp/ContractServiceBase.cs +++ b/src/AElf.Client.Abp/ContractServiceBase.cs @@ -1,5 +1,6 @@ using Google.Protobuf; using Microsoft.Extensions.Logging; +using Volo.Abp.Threading; namespace AElf.Client.Abp; diff --git a/src/AElf.Client.Abp/IAElfAccountProvider.cs b/src/AElf.Client.Abp/IAElfAccountProvider.cs index a0648e8..87cfbad 100644 --- a/src/AElf.Client.Abp/IAElfAccountProvider.cs +++ b/src/AElf.Client.Abp/IAElfAccountProvider.cs @@ -14,22 +14,27 @@ public interface IAElfAccountProvider byte[] GetPrivateKey(string? alias = null, string? address = null); void SetPrivateKey(byte[] privateKey, string? alias = null, string? address = null); void SetPrivateKey(string address, string password, string? alias = null); + string GetDefaultPassword(); } public class AElfAccountProvider : Dictionary, IAElfAccountProvider, ISingletonDependency { private readonly IKeyDirectoryProvider _keyDirectoryProvider; private readonly AElfAccountOptions _aelfAccountOptions; + private readonly string _aelfMinerAccountPassword; + private readonly KeyStoreService _keyStoreService; public ILogger Logger { get; set; } public AElfAccountProvider(IKeyDirectoryProvider keyDirectoryProvider, - IOptionsSnapshot aelfAccountOptions) + IOptionsSnapshot aelfAccountOptions, + IOptionsSnapshot aelfMinerAccountOptions) { Logger = NullLogger.Instance; _keyDirectoryProvider = keyDirectoryProvider; _aelfAccountOptions = aelfAccountOptions.Value; + _aelfMinerAccountPassword = aelfMinerAccountOptions.Value.DefaultPassword; var defaultPrivateKey = ByteArrayHelper.HexStringToByteArray(AElfClientConstants.DefaultPrivateKey); SetPrivateKey(defaultPrivateKey, "Default", Address.FromPublicKey(defaultPrivateKey).ToBase58()); _keyStoreService = new KeyStoreService(); @@ -55,6 +60,11 @@ public AElfAccountProvider(IKeyDirectoryProvider keyDirectoryProvider, } } + public string GetDefaultPassword() + { + return _aelfMinerAccountPassword; + } + public byte[] GetPrivateKey(string? alias = null, string? address = null) { var keys = Keys @@ -87,6 +97,13 @@ public void SetPrivateKey(string address, string password, string? alias = null) var json = textReader.ReadToEnd(); return _keyStoreService.DecryptKeyStoreFromJson(password, json); })); + + var keys = Keys + .WhereIf(!alias.IsNullOrWhiteSpace(), a => a.Alias == alias) + .WhereIf(!address.IsNullOrWhiteSpace(), a => a.Address == address) + .ToList(); + + if (keys.Count == 1) return; TryAdd(new AElfAccountInfo { Alias = alias, diff --git a/src/AElf.Client.Abp/IAElfClientService.cs b/src/AElf.Client.Abp/IAElfClientService.cs index d797385..28dd18b 100644 --- a/src/AElf.Client.Abp/IAElfClientService.cs +++ b/src/AElf.Client.Abp/IAElfClientService.cs @@ -12,10 +12,10 @@ Task ViewSystemAsync(string systemContractName, string methodName, IMess string clientAlias, string accountAlias = "Default"); Task SendAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias); + string clientAlias, string? accountAlias = null, string? accountAddress = null); Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias); + string clientAlias, string? accountAlias = null, string? accountAddress = null); Task GetTransactionResultAsync(string transactionId, string clientAlias); diff --git a/src/AElf.Client.Abp/Options/AElfMinerAccountOptions.cs b/src/AElf.Client.Abp/Options/AElfMinerAccountOptions.cs new file mode 100644 index 0000000..2fe1d06 --- /dev/null +++ b/src/AElf.Client.Abp/Options/AElfMinerAccountOptions.cs @@ -0,0 +1,6 @@ +namespace AElf.Client.Options; + +public class AElfMinerAccountOptions +{ + public string DefaultPassword { get; set; } +} diff --git a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj index 3b1cfad..d4b69d2 100644 --- a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj +++ b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj @@ -26,12 +26,18 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile @@ -44,6 +50,12 @@ MSBuild:Compile + + MSBuild:Compile + + + MSBuild:Compile + MSBuild:Compile diff --git a/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj b/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj index 9ceb643..bc3ebe0 100644 --- a/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj +++ b/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj @@ -23,6 +23,7 @@ + diff --git a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs b/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs index 02791f1..60da415 100644 --- a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs +++ b/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs @@ -1,3 +1,4 @@ +using AElf.Client.Abp.Genesis; using AElf.Client.Abp.TestBase; using AElf.Client.Abp.Token; using Volo.Abp.Modularity; @@ -6,8 +7,9 @@ namespace AElf.Client.Abp.Test; [DependsOn( typeof(AElfClientAbpTestBaseModule), - typeof(AElfClientTokenModule) - )] + typeof(AElfClientTokenModule), + typeof(AElfClientGenesisModule) +)] public class AElfClientAbpContractServiceTestModule : AbpModule { diff --git a/test/AElf.Client.Abp.Test/Genesis/GenesisServiceTests.cs b/test/AElf.Client.Abp.Test/Genesis/GenesisServiceTests.cs new file mode 100644 index 0000000..3483742 --- /dev/null +++ b/test/AElf.Client.Abp.Test/Genesis/GenesisServiceTests.cs @@ -0,0 +1,27 @@ +using AElf.Client.Abp.Genesis; +using AElf.Client.Abp.Genesis.DeployContract; +using Shouldly; + +namespace AElf.Client.Abp.Test.Genesis; + +[Trait("Category", "GenesisContractService")] + +public sealed class GenesisServiceTests : AElfClientAbpContractServiceTestBase +{ + private readonly IGenesisService _genesisService; + private readonly IDeployContractService _deploy; + + public GenesisServiceTests() + { + _genesisService = GetRequiredService(); + _deploy = GetRequiredService(); + } + + [Theory] + [InlineData("AElf.Contracts.NFT")] + public async Task DeployContract(string contractName) + { + var address = await _deploy.DeployContract(contractName); + address.ShouldNotBeNull(); + } +} \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.Abp.TestBase/appsettings.json index f24b815..42042f6 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.json +++ b/test/AElf.Client.Abp.TestBase/appsettings.json @@ -42,7 +42,9 @@ } ] }, - "AElfToken": { + "AElfContract": { + "ContractDirectory": "", + "GenesisContractAddress": "pykr77ft9UUKJZLVq15wCH8PinBSjVRQ12sD1Ayq92mKFsJ1i", "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" }, "AElfClientConfig": { diff --git a/test/AElf.Client.Abp.TestBase/appsettings.secrets.json b/test/AElf.Client.Abp.TestBase/appsettings.secrets.json index 27bbd50..8e6b25d 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.secrets.json +++ b/test/AElf.Client.Abp.TestBase/appsettings.secrets.json @@ -5,5 +5,8 @@ "System": "Information", "Microsoft": "Information" } + }, + "AElfMinerAccount": { + "DefaultPassword": "" } } \ No newline at end of file From 854fddd9e7a605749eec0acc26c59941a7fa122d Mon Sep 17 00:00:00 2001 From: YueZh127 Date: Fri, 17 Jun 2022 19:40:43 +0800 Subject: [PATCH 12/21] fix wait --- src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs | 1 + .../DeployContract/DeployContractService.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs b/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs index bda4812..c8f7cea 100644 --- a/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs +++ b/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs @@ -2,4 +2,5 @@ namespace AElf.Client.Abp.Genesis; public class AElfGenesisConstants { + public const int TenSeconds = 10_000; } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs b/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs index f21889f..3903d4e 100644 --- a/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs +++ b/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs @@ -133,7 +133,7 @@ private async Task CheckProposal(Hash proposalId) var sleepTimes = 0; while (!toBeReleased && sleepTimes < 20) { - Thread.Sleep(1000); + await Task.Delay(AElfGenesisConstants.TenSeconds); toBeReleased = (await _parliamentService.CheckProposal(proposalId)).ToBeReleased; Console.Write("\rCheck proposal status"); sleepTimes++; From 7f068203fdb3b70f6a733980e36dc972c2b7ef1a Mon Sep 17 00:00:00 2001 From: yiqi Date: Tue, 21 Jun 2022 16:44:38 +0800 Subject: [PATCH 13/21] Fix AElfClient.Net --- examples/TokenManager/appsettings.json | 2 +- .../AElfClientTokenModule.cs | 3 +- src/AElf.Client.Abp.Token/AElfTokenOptions.cs | 6 - src/AElf.Client.Abp.Token/ITokenService.cs | 2 + .../TokenService.Send.cs | 25 ++- src/AElf.Client.Abp/IAElfAccountProvider.cs | 9 +- .../Options/AElfContractOptions.cs | 7 + .../AElf.Client.Protobuf.csproj | 12 + src/AElf.Client.Protobuf/Protobuf/acs13.proto | 21 ++ .../Protobuf/bridge_contract.proto | 207 ++++++++++++++++++ .../Protobuf/callback_input.proto | 9 + .../Protobuf/receipt_maker.proto | 35 +++ src/AElf.Client/AElfClient.Net.cs | 116 +++++----- src/AElf.Client/AElfClient.cs | 4 +- .../Token/TokenServiceTests.cs | 14 ++ .../AElf.Client.Abp.TestBase/appsettings.json | 7 +- 16 files changed, 397 insertions(+), 82 deletions(-) delete mode 100644 src/AElf.Client.Abp.Token/AElfTokenOptions.cs create mode 100644 src/AElf.Client.Abp/Options/AElfContractOptions.cs create mode 100644 src/AElf.Client.Protobuf/Protobuf/acs13.proto create mode 100644 src/AElf.Client.Protobuf/Protobuf/bridge_contract.proto create mode 100644 src/AElf.Client.Protobuf/Protobuf/callback_input.proto create mode 100644 src/AElf.Client.Protobuf/Protobuf/receipt_maker.proto diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index ffec599..b1d4965 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -42,7 +42,7 @@ } ] }, - "AElfToken": { + "AElfContract": { "NFTContractAddress": "" }, "AElfClientConfig": { diff --git a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs index cd96563..04f73db 100644 --- a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs +++ b/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs @@ -1,4 +1,5 @@ using AElf.Client.Abp.CrossChain; +using AElf.Client.Options; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; @@ -16,7 +17,7 @@ public class AElfClientTokenModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - Configure(options => { configuration.GetSection("AElfToken").Bind(options); }); + Configure(options => { configuration.GetSection("AElfContract").Bind(options); }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/src/AElf.Client.Abp.Token/AElfTokenOptions.cs b/src/AElf.Client.Abp.Token/AElfTokenOptions.cs deleted file mode 100644 index a4fab54..0000000 --- a/src/AElf.Client.Abp.Token/AElfTokenOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Client.Abp.Token; - -public class AElfTokenOptions -{ - public string NFTContractAddress { get; set; } -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Abp.Token/ITokenService.cs index 11da2ef..668e9f5 100644 --- a/src/AElf.Client.Abp.Token/ITokenService.cs +++ b/src/AElf.Client.Abp.Token/ITokenService.cs @@ -1,3 +1,4 @@ +using AElf.Contracts.Bridge; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; using AElf.Types; @@ -22,6 +23,7 @@ Task CrossChainReceiveTokenAsync(CrossChainReceiveTokenIn Task TransferAsync(TransferInput transferInput); Task AddMintersAsync(AddMintersInput addMintersInput); + Task SwapTokenAsync(SwapTokenInput swapTokenInput); Task GetTokenInfoAsync(string symbol); Task GetTokenBalanceAsync(string symbol, Address owner); diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Abp.Token/TokenService.Send.cs index 96f3dd9..de47732 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Abp.Token/TokenService.Send.cs @@ -1,4 +1,5 @@ using AElf.Client.Options; +using AElf.Contracts.Bridge; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; using AElf.Types; @@ -12,15 +13,15 @@ namespace AElf.Client.Abp.Token; public partial class TokenService : ContractServiceBase, ITokenService, ITransientDependency { private readonly IAElfClientService _clientService; - private readonly AElfTokenOptions _tokenOptions; + private readonly AElfContractOptions _contractOptions; private readonly AElfClientConfigOptions _clientConfigOptions; public TokenService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions, - IOptionsSnapshot tokenOptions) : base(clientService, + IOptionsSnapshot contractOptions) : base(clientService, AElfTokenConstants.TokenSmartContractName) { _clientService = clientService; - _tokenOptions = tokenOptions.Value; + _contractOptions = contractOptions.Value; _clientConfigOptions = clientConfigOptions.Value; } @@ -110,7 +111,7 @@ public async Task CrossChainCreateNFTProtocolAsync( CrossChainCreateInput crossChainCreateInput) { var clientAlias = PreferGetUseSidechainClientAlias(); - ContractAddress = Address.FromBase58(_tokenOptions.NFTContractAddress); + ContractAddress = Address.FromBase58(_contractOptions.NFTContractAddress); var tx = await PerformSendTransactionAsync("CrossChainCreate", crossChainCreateInput, clientAlias); return new SendTransactionResult @@ -135,7 +136,7 @@ public async Task TransferAsync(TransferInput transferInp public async Task AddMintersAsync(AddMintersInput addMintersInput) { var clientAlias = _clientConfigOptions.ClientAlias; - ContractAddress = Address.FromBase58(_tokenOptions.NFTContractAddress); + ContractAddress = Address.FromBase58(_contractOptions.NFTContractAddress); var tx = await PerformSendTransactionAsync("AddMinters", addMintersInput, clientAlias); return new SendTransactionResult @@ -145,6 +146,20 @@ public async Task AddMintersAsync(AddMintersInput addMint }; } + public async Task SwapTokenAsync(SwapTokenInput swapTokenInput) + { + var clientAlias = _clientConfigOptions.ClientAlias; + ContractAddress = Address.FromBase58(_contractOptions.BridgeContractAddress); + var tx = await PerformSendTransactionAsync("SwapToken", swapTokenInput, + clientAlias); + var txResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias); + return new SendTransactionResult + { + Transaction = tx, + TransactionResult = txResult + }; + } + private string PreferGetUseMainChainClientAlias() { return !string.IsNullOrEmpty(_clientConfigOptions.MainChainClientAlias) diff --git a/src/AElf.Client.Abp/IAElfAccountProvider.cs b/src/AElf.Client.Abp/IAElfAccountProvider.cs index a0648e8..303669f 100644 --- a/src/AElf.Client.Abp/IAElfAccountProvider.cs +++ b/src/AElf.Client.Abp/IAElfAccountProvider.cs @@ -81,12 +81,9 @@ public void SetPrivateKey(byte[] privateKey, string? alias = null, string? addre public void SetPrivateKey(string address, string password, string? alias = null) { var keyFilePath = GetKeyFileFullPath(address, _aelfAccountOptions.KeyDirectory); - var privateKey = AsyncHelper.RunSync(() => Task.Run(() => - { - using var textReader = File.OpenText(keyFilePath); - var json = textReader.ReadToEnd(); - return _keyStoreService.DecryptKeyStoreFromJson(password, json); - })); + using var textReader = File.OpenText(keyFilePath); + var json = textReader.ReadToEnd(); + var privateKey = _keyStoreService.DecryptKeyStoreFromJson(password, json); TryAdd(new AElfAccountInfo { Alias = alias, diff --git a/src/AElf.Client.Abp/Options/AElfContractOptions.cs b/src/AElf.Client.Abp/Options/AElfContractOptions.cs new file mode 100644 index 0000000..5ee87d7 --- /dev/null +++ b/src/AElf.Client.Abp/Options/AElfContractOptions.cs @@ -0,0 +1,7 @@ +namespace AElf.Client.Options; + +public class AElfContractOptions +{ + public string NFTContractAddress { get; set; } + public string BridgeContractAddress { get; set; } +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj index 3b1cfad..e418e44 100644 --- a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj +++ b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj @@ -32,6 +32,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile @@ -50,6 +53,15 @@ MSBuild:Compile + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + diff --git a/src/AElf.Client.Protobuf/Protobuf/acs13.proto b/src/AElf.Client.Protobuf/Protobuf/acs13.proto new file mode 100644 index 0000000..2f80e12 --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/acs13.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package acs13; +import "aelf/options.proto"; +import "aelf/core.proto"; +import "google/protobuf/wrappers.proto"; + +option (aelf.identity) = "acs13"; +option csharp_namespace = "AElf.Standards.ACS13"; + +service OracleAggregatorContract { + rpc Aggregate (AggregateInput) returns (google.protobuf.StringValue) { + } +} + + +message AggregateInput { + repeated string results = 1; + repeated int32 frequencies = 2; + int32 aggregate_option = 3; +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/Protobuf/bridge_contract.proto b/src/AElf.Client.Protobuf/Protobuf/bridge_contract.proto new file mode 100644 index 0000000..47e8672 --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/bridge_contract.proto @@ -0,0 +1,207 @@ +syntax = "proto3"; + +import "aelf/core.proto"; +import "aelf/options.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; +import "callback_input.proto"; +import "acs13.proto"; +import "receipt_maker.proto"; + +option csharp_namespace = "AElf.Contracts.Bridge"; + +service BridgeContract { + option (aelf.csharp_state) = "AElf.Contracts.Bridge.BridgeContractState"; + option (aelf.base) = "acs13.proto"; + option (aelf.base) = "receipt_maker.proto"; + + rpc Initialize (InitializeInput) returns (google.protobuf.Empty) {} + + rpc CreateSwap (CreateSwapInput) returns (aelf.Hash) { + } + rpc SwapToken (SwapTokenInput) returns (google.protobuf.Empty) { + } + rpc ChangeSwapRatio (ChangeSwapRatioInput) returns (google.protobuf.Empty) { + } + rpc Deposit (DepositInput) returns (google.protobuf.Empty) { + } + rpc Withdraw (WithdrawInput) returns (google.protobuf.Empty) { + } + rpc UpdateMerkleTree (UpdateMerkleTreeInput) returns (google.protobuf.Empty) { + } + rpc RecordReceiptHash (CallbackInput) returns (google.protobuf.Empty) { + } + + rpc ChangeMaximalLeafCount (google.protobuf.Int32Value) returns (google.protobuf.Empty) { + } + + // view methods + + rpc GetSwapInfo (aelf.Hash) returns (SwapInfo) { + option (aelf.is_view) = true; + } + rpc GetSwapPair (GetSwapPairInput) returns (SwapPair) { + option (aelf.is_view) = true; + } + rpc GetSwapAmounts (GetSwapAmountsInput) returns (SwapAmounts) { + option (aelf.is_view) = true; + } + rpc GetRegimentAddressByRecorderId (google.protobuf.Int64Value) returns (aelf.Address) { + option (aelf.is_view) = true; + } + rpc GetSwappedReceiptIdList (GetSwappedReceiptIdListInput) returns (ReceiptIdList) { + option (aelf.is_view) = true; + } + rpc GetSwappedReceiptInfoList (GetSwappedReceiptInfoListInput) returns (ReceiptInfoList) { + option (aelf.is_view) = true; + } +} + +message InitializeInput { + aelf.Address oracle_contract_address = 1; + aelf.Address merkle_tree_recorder_contract_address = 2; + aelf.Address regiment_contract_address = 3; + aelf.Address merkle_tree_generator_contract_address = 4; + int32 merkle_tree_leaf_limit = 5; +} + +message CreateSwapInput { + int32 origin_token_size_in_byte = 1; + bool origin_token_numeric_big_endian = 2; + repeated SwapTargetToken swap_target_token_list = 3; + aelf.Address regiment_address = 4; +} + +message SwapTargetToken { + string target_token_symbol = 1; + SwapRatio swap_ratio = 2; + int64 deposit_amount = 3; +} + +message SwapInfo { + aelf.Hash swap_id = 1; + int32 origin_token_size_in_byte = 2; + bool origin_token_numeric_big_endian = 3; + map swap_target_token_map = 4; + aelf.Address regiment_address = 5; + int64 recorder_id = 6; +} + +message SwapPair { + aelf.Hash swap_id = 1; + int32 origin_token_size_in_byte = 2; + bool origin_token_numeric_big_endian = 3; + string target_token_symbol = 4; + SwapRatio swap_ratio = 5; + int64 swapped_amount = 6; + int64 swapped_times = 7; + int64 deposit_amount = 8; +} + +message SwapRatio { + int64 origin_share = 1; + int64 target_share = 2; +} + +message ChangeSwapRatioInput { + aelf.Hash swap_id = 1; + SwapRatio swap_ratio = 2; + string target_token_symbol = 3; +} + +message SwapTokenInput { + aelf.Hash swap_id = 1; + int64 receipt_id = 2; + string origin_amount = 3; +} + +message DepositInput { + aelf.Hash swap_id = 1; + string target_token_symbol = 2; + int64 amount = 3; +} + +message GetSwapPairInput { + aelf.Hash swap_id = 1; + string target_token_symbol = 2; +} + +message GetSwapAmountsInput { + aelf.Hash swap_id = 1; + int64 receipt_id = 2; +} + +message SwapAmounts { + aelf.Address receiver = 1; + map received_amounts = 2; +} + +message WithdrawInput { + aelf.Hash swap_id = 1; + string target_token_symbol = 2; + int64 amount = 3; +} + +message ReceiptHashMap { + map value = 1; + int64 recorder_id = 2; +} + +message UpdateMerkleTreeInput { + int64 recorder_id = 1; + aelf.Address regiment_address = 2; +} + +message ReceiptIdList { + repeated int64 value = 1; +} + +message GetSwappedReceiptIdListInput { + aelf.Hash swap_id = 1; + aelf.Address receiver_address = 2; +} + +message GetSwappedReceiptInfoListInput { + aelf.Hash swap_id = 1; + aelf.Address receiving_address = 2; +} + +message ReceiptInfo { + int64 receipt_id = 1; + aelf.Hash receiving_tx_id = 2; + google.protobuf.Timestamp receiving_time = 3; + int64 amount = 4; + map amount_map = 5; +} + +message ReceiptInfoList { + repeated ReceiptInfo value = 1; +} + +message SendingInfo { + int64 receipt_id = 1; + string sending_tx_id = 2; + string sending_time = 3; +} + +// Events + +message SwapRatioChanged { + option (aelf.is_event) = true; + aelf.Hash swap_id = 1; + SwapRatio new_swap_ratio = 2; + string target_token_symbol = 3; +} + +message TokenSwapped { + option (aelf.is_event) = true; + aelf.Address address = 1; + int64 amount = 2; + string symbol = 3; +} + +message SwapPairAdded { + option (aelf.is_event) = true; + aelf.Hash swap_id = 1; +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/Protobuf/callback_input.proto b/src/AElf.Client.Protobuf/Protobuf/callback_input.proto new file mode 100644 index 0000000..c389829 --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/callback_input.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +import "aelf/core.proto"; + +message CallbackInput { + aelf.Hash query_id = 1; + bytes result = 2; + repeated aelf.Address oracle_nodes = 3; +} \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/Protobuf/receipt_maker.proto b/src/AElf.Client.Protobuf/Protobuf/receipt_maker.proto new file mode 100644 index 0000000..3adefd5 --- /dev/null +++ b/src/AElf.Client.Protobuf/Protobuf/receipt_maker.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +import "aelf/core.proto"; +import "aelf/options.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; + +option csharp_namespace = "AElf.Contracts.ReceiptMakerContract"; + +service ReceiptMakerContract { + rpc GetReceiptCount(google.protobuf.Int64Value) returns (google.protobuf.Int64Value) { + option (aelf.is_view) = true; + } + rpc GetReceiptHash(GetReceiptHashInput) returns (aelf.Hash) { + option (aelf.is_view) = true; + } + rpc GetReceiptHashList(GetReceiptHashListInput) returns (GetReceiptHashListOutput) { + option (aelf.is_view) = true; + } +} + +message GetReceiptHashInput { + int64 recorder_id = 1; + int64 receipt_id = 2; +} + +message GetReceiptHashListInput { + int64 first_leaf_index = 1; + int64 last_leaf_index = 2; + int64 recorder_id = 3; +} + +message GetReceiptHashListOutput { + repeated aelf.Hash receipt_hash_list = 1; +} \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.Net.cs b/src/AElf.Client/AElfClient.Net.cs index 89b2f5b..5b4d4fb 100644 --- a/src/AElf.Client/AElfClient.Net.cs +++ b/src/AElf.Client/AElfClient.Net.cs @@ -9,72 +9,72 @@ namespace AElf.Client; public partial class AElfClient : INetAppService { /// - /// Attempt to add a node to the connected network nodes.Input parameter contains the ipAddress of the node. - /// - /// - /// - /// - /// Add successfully or not - public async Task AddPeerAsync(string ipAddress, string userName, string password) + /// Attempt to add a node to the connected network nodes.Input parameter contains the ipAddress of the node. + /// + /// + /// + /// + /// Add successfully or not + public async Task AddPeerAsync(string ipAddress, string? userName, string? password) + { + if (!EndpointHelper.TryParse(ipAddress, out var endpoint)) { - if (!EndpointHelper.TryParse(ipAddress, out var endpoint)) - { - return false; - } - - var url = GetRequestUrl(_baseUrl, "api/net/peer"); - var parameters = new Dictionary - { - {"address", endpoint?.ToString() ?? AElfClientConstants.LocalEndpoint} - }; - - return await _httpService.PostResponseAsync(url, parameters, - authenticationHeaderValue: GetAuthenticationHeaderValue()); + return false; } - /// - /// Attempt to remove a node from the connected network nodes by given the ipAddress. - /// - /// - /// - /// - /// Delete successfully or not - public async Task RemovePeerAsync(string ipAddress, string userName, string password) + var url = GetRequestUrl(_baseUrl, "api/net/peer"); + var parameters = new Dictionary { - if (!EndpointHelper.TryParse(ipAddress, out var endpoint)) - { - return false; - } + { "address", endpoint?.ToString() ?? AElfClientConstants.LocalEndpoint }, + }; - var url = GetRequestUrl(_baseUrl, $"api/net/peer?address={endpoint}"); - return await _httpService.DeleteResponseAsObjectAsync(url, - authenticationHeaderValue: GetAuthenticationHeaderValue()); - } + return await _httpService.PostResponseAsync(url, parameters, + authenticationHeaderValue: GetAuthenticationHeaderValue(userName, password)); + } - /// - /// Gets information about the peer nodes of the current node.Optional whether to include metrics. - /// - /// - /// Information about the peer nodes - public async Task?> GetPeersAsync(bool withMetrics) + /// + /// Attempt to remove a node from the connected network nodes by given the ipAddress. + /// + /// + /// + /// + /// Delete successfully or not + public async Task RemovePeerAsync(string ipAddress, string? userName, string? password) + { + if (!EndpointHelper.TryParse(ipAddress, out var endpoint)) { - var url = GetRequestUrl(_baseUrl, $"api/net/peers?withMetrics={withMetrics}"); - return await _httpService.GetResponseAsync>(url); + return false; } - /// - /// Get the node's network information. - /// - /// Network information - public async Task GetNetworkInfoAsync() - { - var url = GetRequestUrl(_baseUrl, "api/net/networkInfo"); - return await _httpService.GetResponseAsync(url); - } + var url = GetRequestUrl(_baseUrl, $"api/net/peer?address={endpoint}"); + return await _httpService.DeleteResponseAsObjectAsync(url, + authenticationHeaderValue: GetAuthenticationHeaderValue(userName, password)); + } - private AuthenticationHeaderValue GetAuthenticationHeaderValue() - { - var byteArray = Encoding.ASCII.GetBytes($"{_userName}:{_password}"); - return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); - } + /// + /// Gets information about the peer nodes of the current node.Optional whether to include metrics. + /// + /// + /// Information about the peer nodes + public async Task?> GetPeersAsync(bool withMetrics) + { + var url = GetRequestUrl(_baseUrl, $"api/net/peers?withMetrics={withMetrics}"); + return await _httpService.GetResponseAsync>(url); + } + + /// + /// Get the node's network information. + /// + /// Network information + public async Task GetNetworkInfoAsync() + { + var url = GetRequestUrl(_baseUrl, "api/net/networkInfo"); + return await _httpService.GetResponseAsync(url); + } + + private AuthenticationHeaderValue GetAuthenticationHeaderValue(string? userName, string? password) + { + var byteArray = Encoding.ASCII.GetBytes($"{userName ?? _userName}:{password ?? _password}"); + return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); + } } \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.cs b/src/AElf.Client/AElfClient.cs index b24163f..b5cd922 100644 --- a/src/AElf.Client/AElfClient.cs +++ b/src/AElf.Client/AElfClient.cs @@ -6,8 +6,8 @@ public partial class AElfClient : IDisposable { private readonly IHttpService _httpService; private readonly string _baseUrl; - private readonly string? _userName; - private readonly string? _password; + private string? _userName; + private string? _password; public AElfClient(string baseUrl, int timeOut = 60, string? userName = null, string? password = null, bool useCamelCase = false) diff --git a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs index 85039dc..3e7a115 100644 --- a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs @@ -1,5 +1,6 @@ using AElf.Client.Abp.Token; using AElf.Client.Abp.Token.SyncTokenInfo; +using AElf.Contracts.Bridge; using AElf.Contracts.NFT; using AElf.Types; using Shouldly; @@ -71,4 +72,17 @@ await _tokenService.AddMintersAsync(new AddMintersInput } }); } + + [Theory] + [InlineData("bb16f381b0f2e795a988285dec3a68affacdccd7d3ac2e74edc808c102efcd95", 228, "9413000000000000000000")] + public async Task SwapTokenTest(string swapIdHex, long receiptId, string amount) + { + var swapId = Hash.LoadFromHex(swapIdHex); + await _tokenService.SwapTokenAsync(new SwapTokenInput + { + SwapId = swapId, + OriginAmount = amount, + ReceiptId = receiptId + }); + } } \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.Abp.TestBase/appsettings.json index f24b815..c88adf1 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.json +++ b/test/AElf.Client.Abp.TestBase/appsettings.json @@ -42,11 +42,12 @@ } ] }, - "AElfToken": { - "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" + "AElfContract": { + "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH", + "BridgeContractAddress": "2RHf2fxsnEaM3wb6N1yGqPupNZbcCY98LgWbGSFWmWzgEs5Sjo" }, "AElfClientConfig": { - "ClientAlias": "TestNetSidechain", + "ClientAlias": "MainNetMainChain", "MainChainClientAlias": "TestNetMainChain", "SidechainClientAlias": "TestNetSidechain", "AccountAlias": "eanz", From aed54d72ce48430c8a9ba7652d8e63803d34a16a Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 22 Jun 2022 11:35:26 +0800 Subject: [PATCH 14/21] Fix RequestMetric.RequestTime (same with AElf repo) --- src/AElf.Client/Dto/PeerDto.cs | 4 +++- test/AElf.Client.Abp.TestBase/appsettings.json | 2 +- test/AElf.Client.Test/ClientTest.cs | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/AElf.Client/Dto/PeerDto.cs b/src/AElf.Client/Dto/PeerDto.cs index 411c2df..d7ba842 100644 --- a/src/AElf.Client/Dto/PeerDto.cs +++ b/src/AElf.Client/Dto/PeerDto.cs @@ -1,3 +1,5 @@ +using Google.Protobuf.WellKnownTypes; + namespace AElf.Client.Dto; public class PeerDto @@ -18,5 +20,5 @@ public class RequestMetric public long RoundTripTime { get; set; } public string MethodName { get; set; } public string Info { get; set; } - public string RequestTime { get; set; } + public Timestamp RequestTime { get; set; } } \ No newline at end of file diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.Abp.TestBase/appsettings.json index c88adf1..90aea72 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.json +++ b/test/AElf.Client.Abp.TestBase/appsettings.json @@ -47,7 +47,7 @@ "BridgeContractAddress": "2RHf2fxsnEaM3wb6N1yGqPupNZbcCY98LgWbGSFWmWzgEs5Sjo" }, "AElfClientConfig": { - "ClientAlias": "MainNetMainChain", + "ClientAlias": "TestNetSidechain", "MainChainClientAlias": "TestNetMainChain", "SidechainClientAlias": "TestNetSidechain", "AccountAlias": "eanz", diff --git a/test/AElf.Client.Test/ClientTest.cs b/test/AElf.Client.Test/ClientTest.cs index e91b4c7..888d971 100644 --- a/test/AElf.Client.Test/ClientTest.cs +++ b/test/AElf.Client.Test/ClientTest.cs @@ -25,7 +25,7 @@ namespace AElf.Client.Test; public class ClientTest { - private const string BaseUrl = "https://tdvv-test-node.aelf.io"; + private const string BaseUrl = "https://tdvw-test-node.aelf.io"; private string _genesisAddress; private string GenesisAddress => GetGenesisContractAddress(); @@ -160,6 +160,15 @@ public async Task GetPeers_Test() var peersInfo = JsonConvert.SerializeObject(peers, Formatting.Indented); _testOutputHelper.WriteLine(peersInfo); } + + [Fact] + public async Task GetPeersWithMetrics_Test() + { + var peers = await Client.GetPeersAsync(true); + Assert.True(peers != null); + var peersInfo = JsonConvert.SerializeObject(peers, Formatting.Indented); + _testOutputHelper.WriteLine(peersInfo); + } [Fact] public async Task GetNetworkInfo_Test() From a720290566e69c08d814f65be2eb0668a43e4a77 Mon Sep 17 00:00:00 2001 From: yiqi Date: Tue, 5 Jul 2022 10:20:17 +0800 Subject: [PATCH 15/21] Abp -> Core and other renamings. --- all.sln | 59 ++++++------------- examples/AEDPoSViewer/AEDPoSViewer.csproj | 2 +- examples/AEDPoSViewer/AEDPoSViewerModule.cs | 2 +- examples/AEDPoSViewer/AEDPoSViewerService.cs | 2 +- .../CrossChainManager.csproj | 4 +- .../CrossChainManagerModule.cs | 4 +- .../CrossChainManagerService.cs | 2 +- examples/CrossChainManager/appsettings.json | 4 +- examples/TokenManager/TokenManager.csproj | 4 +- .../TokenManager/TokenManagerHostedService.cs | 2 +- examples/TokenManager/TokenManagerModule.cs | 4 +- examples/TokenManager/TokenManagerService.cs | 6 +- examples/TokenManager/appsettings.json | 4 +- .../AElfClientAEDPoSModule.cs | 5 -- .../AElf.Client.Abp.Core.csproj | 18 ------ .../AElf.Client.Abp.Election.csproj | 10 ---- .../AElfClientNFTMarketModule.cs | 5 -- .../AElf.Client.Association.csproj} | 0 .../AElfClientAssociationModule.cs | 2 +- .../AElf.Client.Bridge.csproj} | 0 .../AElfClientBridgeModule.cs | 2 +- .../AElf.Client.Configuration.csproj} | 0 .../AElfClientConfigurationModule.cs | 2 +- .../AElf.Client.Consensus.AEDPoS.csproj} | 0 .../AElfClientAEDPoSModule.cs | 5 ++ .../AElf.Client.Core.csproj} | 3 +- .../AElfClientAbpConstants.cs | 2 +- .../AElfClientModule.cs | 4 +- .../AElfClientService.Blockchain.cs | 2 +- .../AElfClientService.Send.cs | 2 +- .../AElfClientService.View.cs | 4 +- .../ContractServiceBase.cs | 2 +- .../GlobalUsings.cs | 0 .../IAElfAccountProvider.cs | 6 +- .../IAElfClientProvider.cs | 12 ++-- .../IAElfClientService.cs | 2 +- .../Infrastructure/IKeyDirectoryProvider.cs | 2 +- .../Infrastructure/KeyDirectoryProvider.cs | 2 +- .../Options/AElfAccountOptions.cs | 2 +- .../Options/AElfClientConfigOptions.cs | 6 +- .../Options/AElfClientOptions.cs | 2 +- .../Options/AElfContractOptions.cs | 2 +- .../Profile/CommonProfile.cs | 2 +- .../Profile/MerklePathProfile.cs | 2 +- .../Profile/TransactionProfile.cs | 2 +- .../SendTransactionResult.cs | 2 +- .../AElf.Client.CrossChain.csproj} | 2 +- .../AElfClientCrossChainModule.cs | 5 +- .../AElfCrossChainConstants.cs | 2 +- .../CrossChainService.cs | 5 +- .../ICrossChainService.cs | 2 +- .../AElf.Client.Election.csproj} | 0 .../AElfClientElectionModule.cs | 2 +- .../AElf.Client.Genesis.csproj} | 0 .../AElfClientGenesisModule.cs | 2 +- .../AElf.Client.Oracle.csproj} | 0 .../AElfClientOracleModule.cs | 2 +- .../AElf.Client.Parliament.csproj} | 0 .../AElfClientParliamentModule.cs | 2 +- .../AElf.Client.Profit.csproj} | 0 .../AElfClientProfitModule.cs | 2 +- .../AElf.Client.Referendum.csproj} | 0 .../AElfClientReferendumModule.cs | 2 +- .../AElf.Client.Regiment.csproj} | 0 .../AElfClientRegimentModule.cs | 2 +- .../AElf.Client.Token.csproj} | 7 +-- .../AElfClientTokenModule.cs | 7 ++- .../AElfTokenConstants.cs | 4 +- .../CrossChainTransferQueueService.cs | 2 +- .../CrossChainTransferService.cs | 5 +- .../ICrossChainTransferQueueService.cs | 2 +- .../ICrossChainTransferService.cs | 2 +- .../ITokenService.cs | 3 +- .../README.md | 0 .../ISyncTokenInfoQueueService.cs | 2 +- .../SyncTokenInfo/ISyncTokenInfoService.cs | 2 +- .../SyncTokenInfoQueueService.cs | 2 +- .../SyncTokenInfo/SyncTokenInfoService.cs | 7 ++- .../TokenService.Send.cs | 15 ++--- .../TokenService.View.cs | 2 +- .../AElf.Client.TokenConverter.csproj} | 0 .../AElfClientTokenConverterModule.cs | 2 +- .../AElf.Client.TokenHolder.csproj} | 0 .../AElfClientTokenHolderModule.cs | 2 +- .../AElf.Client.Vote.csproj} | 0 .../AElfClientVoteModule.cs | 2 +- .../AElf.Client.Whitelist.csproj} | 2 +- .../AElfClientWhitelistModule.cs | 5 +- .../IWhitelistService.cs | 3 +- .../WhitelistService.cs | 5 +- src/AElf.Client/AElfClientBuilder.cs | 8 +-- src/AElf.Client/AElfClientConstants.cs | 9 +-- src/AElf.Client/EndpointType.cs | 4 +- .../AElf.Client.Abp.Test.csproj | 30 ---------- .../Whitelist/WhitelistServiceTests.cs | 15 ----- test/AElf.Client.Test/AElf.Client.Test.csproj | 17 +++++- .../AElfClientAbpContractServiceTestBase.cs | 2 +- .../AElfClientAbpContractServiceTestModule.cs | 4 +- .../Token/TokenServiceTests.cs | 10 ++-- .../Usings.cs | 0 .../AElf.Client.TestBase.csproj} | 0 .../AElfClientAbpTestBase.cs | 2 +- .../AElfClientAbpTestBaseModule.cs | 2 +- .../Usings.cs | 0 .../appsettings.json | 4 +- .../appsettings.secrets.json | 0 106 files changed, 179 insertions(+), 252 deletions(-) delete mode 100644 src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs delete mode 100644 src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj delete mode 100644 src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj delete mode 100644 src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs rename src/{AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj => AElf.Client.Association/AElf.Client.Association.csproj} (100%) rename src/{AElf.Client.Abp.Association => AElf.Client.Association}/AElfClientAssociationModule.cs (51%) rename src/{AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj => AElf.Client.Bridge/AElf.Client.Bridge.csproj} (100%) rename src/{AElf.Client.Abp.Bridge => AElf.Client.Bridge}/AElfClientBridgeModule.cs (51%) rename src/{AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj => AElf.Client.Configuration/AElf.Client.Configuration.csproj} (100%) rename src/{AElf.Client.Abp.Configuration => AElf.Client.Configuration}/AElfClientConfigurationModule.cs (51%) rename src/{AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj => AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj} (100%) create mode 100644 src/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs rename src/{AElf.Client.Abp/AElf.Client.Abp.csproj => AElf.Client.Core/AElf.Client.Core.csproj} (87%) rename src/{AElf.Client.Abp => AElf.Client.Core}/AElfClientAbpConstants.cs (76%) rename src/{AElf.Client.Abp => AElf.Client.Core}/AElfClientModule.cs (94%) rename src/{AElf.Client.Abp => AElf.Client.Core}/AElfClientService.Blockchain.cs (98%) rename src/{AElf.Client.Abp => AElf.Client.Core}/AElfClientService.Send.cs (98%) rename src/{AElf.Client.Abp => AElf.Client.Core}/AElfClientService.View.cs (97%) rename src/{AElf.Client.Abp => AElf.Client.Core}/ContractServiceBase.cs (98%) rename src/{AElf.Client.Abp => AElf.Client.Core}/GlobalUsings.cs (100%) rename src/{AElf.Client.Abp => AElf.Client.Core}/IAElfAccountProvider.cs (97%) rename src/{AElf.Client.Abp => AElf.Client.Core}/IAElfClientProvider.cs (89%) rename src/{AElf.Client.Abp => AElf.Client.Core}/IAElfClientService.cs (97%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Infrastructure/IKeyDirectoryProvider.cs (62%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Infrastructure/KeyDirectoryProvider.cs (93%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Options/AElfAccountOptions.cs (90%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Options/AElfClientConfigOptions.cs (55%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Options/AElfClientOptions.cs (90%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Options/AElfContractOptions.cs (79%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Profile/CommonProfile.cs (95%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Profile/MerklePathProfile.cs (92%) rename src/{AElf.Client.Abp => AElf.Client.Core}/Profile/TransactionProfile.cs (99%) rename src/{AElf.Client.Abp => AElf.Client.Core}/SendTransactionResult.cs (84%) rename src/{AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj => AElf.Client.CrossChain/AElf.Client.CrossChain.csproj} (75%) rename src/{AElf.Client.Abp.CrossChain => AElf.Client.CrossChain}/AElfClientCrossChainModule.cs (59%) rename src/{AElf.Client.Abp.CrossChain => AElf.Client.CrossChain}/AElfCrossChainConstants.cs (77%) rename src/{AElf.Client.Abp.CrossChain => AElf.Client.CrossChain}/CrossChainService.cs (94%) rename src/{AElf.Client.Abp.CrossChain => AElf.Client.CrossChain}/ICrossChainService.cs (71%) rename src/{AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj => AElf.Client.Election/AElf.Client.Election.csproj} (100%) rename src/{AElf.Client.Abp.Election => AElf.Client.Election}/AElfClientElectionModule.cs (51%) rename src/{AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj => AElf.Client.Genesis/AElf.Client.Genesis.csproj} (100%) rename src/{AElf.Client.Abp.Genesis => AElf.Client.Genesis}/AElfClientGenesisModule.cs (51%) rename src/{AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj => AElf.Client.Oracle/AElf.Client.Oracle.csproj} (100%) rename src/{AElf.Client.Abp.Oracle => AElf.Client.Oracle}/AElfClientOracleModule.cs (51%) rename src/{AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj => AElf.Client.Parliament/AElf.Client.Parliament.csproj} (100%) rename src/{AElf.Client.Abp.Parliament => AElf.Client.Parliament}/AElfClientParliamentModule.cs (51%) rename src/{AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj => AElf.Client.Profit/AElf.Client.Profit.csproj} (100%) rename src/{AElf.Client.Abp.Profit => AElf.Client.Profit}/AElfClientProfitModule.cs (51%) rename src/{AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj => AElf.Client.Referendum/AElf.Client.Referendum.csproj} (100%) rename src/{AElf.Client.Abp.Referendum => AElf.Client.Referendum}/AElfClientReferendumModule.cs (51%) rename src/{AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj => AElf.Client.Regiment/AElf.Client.Regiment.csproj} (100%) rename src/{AElf.Client.Abp.Regiment => AElf.Client.Regiment}/AElfClientRegimentModule.cs (51%) rename src/{AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj => AElf.Client.Token/AElf.Client.Token.csproj} (59%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/AElfClientTokenModule.cs (89%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/AElfTokenConstants.cs (70%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/CrossChainTransfer/CrossChainTransferQueueService.cs (94%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/CrossChainTransfer/CrossChainTransferService.cs (97%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/CrossChainTransfer/ICrossChainTransferQueueService.cs (77%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/CrossChainTransfer/ICrossChainTransferService.cs (78%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/ITokenService.cs (96%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/README.md (100%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/SyncTokenInfo/ISyncTokenInfoQueueService.cs (63%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/SyncTokenInfo/ISyncTokenInfoService.cs (64%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/SyncTokenInfo/SyncTokenInfoQueueService.cs (93%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/SyncTokenInfo/SyncTokenInfoService.cs (96%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/TokenService.Send.cs (94%) rename src/{AElf.Client.Abp.Token => AElf.Client.Token}/TokenService.View.cs (98%) rename src/{AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj => AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj} (100%) rename src/{AElf.Client.Abp.TokenConverter => AElf.Client.TokenConverter}/AElfClientTokenConverterModule.cs (51%) rename src/{AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj => AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj} (100%) rename src/{AElf.Client.Abp.TokenHolder => AElf.Client.TokenHolder}/AElfClientTokenHolderModule.cs (51%) rename src/{AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj => AElf.Client.Vote/AElf.Client.Vote.csproj} (100%) rename src/{AElf.Client.Abp.Vote => AElf.Client.Vote}/AElfClientVoteModule.cs (52%) rename src/{AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj => AElf.Client.Whitelist/AElf.Client.Whitelist.csproj} (81%) rename src/{AElf.Client.Abp.Whitelist => AElf.Client.Whitelist}/AElfClientWhitelistModule.cs (58%) rename src/{AElf.Client.Abp.Whitelist => AElf.Client.Whitelist}/IWhitelistService.cs (74%) rename src/{AElf.Client.Abp.Whitelist => AElf.Client.Whitelist}/WhitelistService.cs (93%) delete mode 100644 test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj delete mode 100644 test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs rename test/{AElf.Client.Abp.Test => AElf.Client.Test}/AElfClientAbpContractServiceTestBase.cs (83%) rename test/{AElf.Client.Abp.Test => AElf.Client.Test}/AElfClientAbpContractServiceTestModule.cs (78%) rename test/{AElf.Client.Abp.Test => AElf.Client.Test}/Token/TokenServiceTests.cs (91%) rename test/{AElf.Client.Abp.Test => AElf.Client.Test}/Usings.cs (100%) rename test/{AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj => AElf.Client.TestBase/AElf.Client.TestBase.csproj} (100%) rename test/{AElf.Client.Abp.TestBase => AElf.Client.TestBase}/AElfClientAbpTestBase.cs (95%) rename test/{AElf.Client.Abp.TestBase => AElf.Client.TestBase}/AElfClientAbpTestBaseModule.cs (84%) rename test/{AElf.Client.Abp.TestBase => AElf.Client.TestBase}/Usings.cs (100%) rename test/{AElf.Client.Abp.TestBase => AElf.Client.TestBase}/appsettings.json (94%) rename test/{AElf.Client.Abp.TestBase => AElf.Client.TestBase}/appsettings.secrets.json (100%) diff --git a/all.sln b/all.sln index f4557de..aaf03a4 100644 --- a/all.sln +++ b/all.sln @@ -18,51 +18,45 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AEDPoSViewer", "examples\AE EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Test", "test\AElf.Client.Test\AElf.Client.Test.csproj", "{4D019C99-8B1C-42B0-8630-F1E3661F414B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp", "src\AElf.Client.Abp\AElf.Client.Abp.csproj", "{BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Core", "src\AElf.Client.Core\AElf.Client.Core.csproj", "{BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Token", "src\AElf.Client.Abp.Token\AElf.Client.Abp.Token.csproj", "{4E127996-AE35-4DCC-B4C0-057CB5B22A0E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Token", "src\AElf.Client.Token\AElf.Client.Token.csproj", "{4E127996-AE35-4DCC-B4C0-057CB5B22A0E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Election", "src\AElf.Client.Abp.Election\AElf.Client.Abp.Election.csproj", "{D27E0203-23E4-4B81-A3FC-EE5034FA631E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Election", "src\AElf.Client.Election\AElf.Client.Election.csproj", "{D27E0203-23E4-4B81-A3FC-EE5034FA631E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Vote", "src\AElf.Client.Abp.Vote\AElf.Client.Abp.Vote.csproj", "{B76DF7DD-1A8A-4876-A450-5669C9B31750}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Vote", "src\AElf.Client.Vote\AElf.Client.Vote.csproj", "{B76DF7DD-1A8A-4876-A450-5669C9B31750}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Profit", "src\AElf.Client.Abp.Profit\AElf.Client.Abp.Profit.csproj", "{BD004F96-0173-489C-BA20-6C21A7F9C538}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Profit", "src\AElf.Client.Profit\AElf.Client.Profit.csproj", "{BD004F96-0173-489C-BA20-6C21A7F9C538}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Association", "src\AElf.Client.Abp.Association\AElf.Client.Abp.Association.csproj", "{7B40B739-18F8-4A40-A8EF-BA2758199092}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Association", "src\AElf.Client.Association\AElf.Client.Association.csproj", "{7B40B739-18F8-4A40-A8EF-BA2758199092}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Configuration", "src\AElf.Client.Abp.Configuration\AElf.Client.Abp.Configuration.csproj", "{E467E8FB-933C-4E2C-BC75-490B852464A8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Configuration", "src\AElf.Client.Configuration\AElf.Client.Configuration.csproj", "{E467E8FB-933C-4E2C-BC75-490B852464A8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Consensus.AEDPoS", "src\AElf.Client.Abp.Consensus.AEDPoS\AElf.Client.Abp.Consensus.AEDPoS.csproj", "{84E06902-1D71-4F8F-9071-49CAFF3B8A05}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Consensus.AEDPoS", "src\AElf.Client.Consensus.AEDPoS\AElf.Client.Consensus.AEDPoS.csproj", "{84E06902-1D71-4F8F-9071-49CAFF3B8A05}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.CrossChain", "src\AElf.Client.Abp.CrossChain\AElf.Client.Abp.CrossChain.csproj", "{6D6FE332-73A4-4F40-BE96-E720A6B83201}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.CrossChain", "src\AElf.Client.CrossChain\AElf.Client.CrossChain.csproj", "{6D6FE332-73A4-4F40-BE96-E720A6B83201}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Genesis", "src\AElf.Client.Abp.Genesis\AElf.Client.Abp.Genesis.csproj", "{12506F28-C416-4377-B23D-301CE0AA2E8C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Genesis", "src\AElf.Client.Genesis\AElf.Client.Genesis.csproj", "{12506F28-C416-4377-B23D-301CE0AA2E8C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.NFTMarket", "src\AElf.Client.Abp.NFTMarket\AElf.Client.Abp.NFTMarket.csproj", "{5653A6D9-D170-4C71-AB5F-9B770E45604A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Parliament", "src\AElf.Client.Parliament\AElf.Client.Parliament.csproj", "{8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Parliament", "src\AElf.Client.Abp.Parliament\AElf.Client.Abp.Parliament.csproj", "{8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Referendum", "src\AElf.Client.Referendum\AElf.Client.Referendum.csproj", "{899F17C1-2FB6-418E-A9BD-5613C563365E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Referendum", "src\AElf.Client.Abp.Referendum\AElf.Client.Abp.Referendum.csproj", "{899F17C1-2FB6-418E-A9BD-5613C563365E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TokenHolder", "src\AElf.Client.TokenHolder\AElf.Client.TokenHolder.csproj", "{7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TokenHolder", "src\AElf.Client.Abp.TokenHolder\AElf.Client.Abp.TokenHolder.csproj", "{7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TokenConverter", "src\AElf.Client.TokenConverter\AElf.Client.TokenConverter.csproj", "{B3EE451C-200D-4CC0-AEFA-1553892C825F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TokenConverter", "src\AElf.Client.Abp.TokenConverter\AElf.Client.Abp.TokenConverter.csproj", "{B3EE451C-200D-4CC0-AEFA-1553892C825F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Whitelist", "src\AElf.Client.Whitelist\AElf.Client.Whitelist.csproj", "{478E52D9-1BA5-4852-B1CC-79D5B8382D87}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Whitelist", "src\AElf.Client.Abp.Whitelist\AElf.Client.Abp.Whitelist.csproj", "{478E52D9-1BA5-4852-B1CC-79D5B8382D87}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Oracle", "src\AElf.Client.Oracle\AElf.Client.Oracle.csproj", "{D1C08C5C-9F59-41A9-9A7B-788377BC2B92}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Oracle", "src\AElf.Client.Abp.Oracle\AElf.Client.Abp.Oracle.csproj", "{D1C08C5C-9F59-41A9-9A7B-788377BC2B92}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Bridge", "src\AElf.Client.Bridge\AElf.Client.Bridge.csproj", "{4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Bridge", "src\AElf.Client.Abp.Bridge\AElf.Client.Abp.Bridge.csproj", "{4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Regiment", "src\AElf.Client.Abp.Regiment\AElf.Client.Abp.Regiment.csproj", "{F520E0B9-9EF7-4528-93FA-C182E8423F51}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Core", "src\AElf.Client.Abp.Core\AElf.Client.Abp.Core.csproj", "{1552B665-A065-41AE-A00E-A6E9AB974414}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Regiment", "src\AElf.Client.Regiment\AElf.Client.Regiment.csproj", "{F520E0B9-9EF7-4528-93FA-C182E8423F51}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossChainManager", "examples\CrossChainManager\CrossChainManager.csproj", "{1BC40A93-079B-48C4-B116-62C6B50C2FFC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.Test", "test\AElf.Client.Abp.Test\AElf.Client.Abp.Test.csproj", "{64ACA917-AFE2-4916-A772-A3F77B3C4FE8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Abp.TestBase", "test\AElf.Client.Abp.TestBase\AElf.Client.Abp.TestBase.csproj", "{D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TestBase", "test\AElf.Client.TestBase\AElf.Client.TestBase.csproj", "{D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -86,7 +80,6 @@ Global {84E06902-1D71-4F8F-9071-49CAFF3B8A05} = {940361AC-2167-4D30-A4F6-9A543C608196} {6D6FE332-73A4-4F40-BE96-E720A6B83201} = {940361AC-2167-4D30-A4F6-9A543C608196} {12506F28-C416-4377-B23D-301CE0AA2E8C} = {940361AC-2167-4D30-A4F6-9A543C608196} - {5653A6D9-D170-4C71-AB5F-9B770E45604A} = {940361AC-2167-4D30-A4F6-9A543C608196} {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF} = {940361AC-2167-4D30-A4F6-9A543C608196} {899F17C1-2FB6-418E-A9BD-5613C563365E} = {940361AC-2167-4D30-A4F6-9A543C608196} {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74} = {940361AC-2167-4D30-A4F6-9A543C608196} @@ -95,9 +88,7 @@ Global {D1C08C5C-9F59-41A9-9A7B-788377BC2B92} = {940361AC-2167-4D30-A4F6-9A543C608196} {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610} = {940361AC-2167-4D30-A4F6-9A543C608196} {F520E0B9-9EF7-4528-93FA-C182E8423F51} = {940361AC-2167-4D30-A4F6-9A543C608196} - {1552B665-A065-41AE-A00E-A6E9AB974414} = {940361AC-2167-4D30-A4F6-9A543C608196} {1BC40A93-079B-48C4-B116-62C6B50C2FFC} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} - {64ACA917-AFE2-4916-A772-A3F77B3C4FE8} = {7CD2B508-C765-4720-B430-94E79135797A} {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401} = {7CD2B508-C765-4720-B430-94E79135797A} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution @@ -165,10 +156,6 @@ Global {12506F28-C416-4377-B23D-301CE0AA2E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU {12506F28-C416-4377-B23D-301CE0AA2E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU {12506F28-C416-4377-B23D-301CE0AA2E8C}.Release|Any CPU.Build.0 = Release|Any CPU - {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5653A6D9-D170-4C71-AB5F-9B770E45604A}.Release|Any CPU.Build.0 = Release|Any CPU {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -201,18 +188,10 @@ Global {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Debug|Any CPU.Build.0 = Debug|Any CPU {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Release|Any CPU.ActiveCfg = Release|Any CPU {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Release|Any CPU.Build.0 = Release|Any CPU - {1552B665-A065-41AE-A00E-A6E9AB974414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1552B665-A065-41AE-A00E-A6E9AB974414}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1552B665-A065-41AE-A00E-A6E9AB974414}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1552B665-A065-41AE-A00E-A6E9AB974414}.Release|Any CPU.Build.0 = Release|Any CPU {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Release|Any CPU.Build.0 = Release|Any CPU - {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {64ACA917-AFE2-4916-A772-A3F77B3C4FE8}.Release|Any CPU.Build.0 = Release|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.Build.0 = Debug|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/examples/AEDPoSViewer/AEDPoSViewer.csproj b/examples/AEDPoSViewer/AEDPoSViewer.csproj index a356a80..56f9690 100644 --- a/examples/AEDPoSViewer/AEDPoSViewer.csproj +++ b/examples/AEDPoSViewer/AEDPoSViewer.csproj @@ -8,7 +8,7 @@ - + diff --git a/examples/AEDPoSViewer/AEDPoSViewerModule.cs b/examples/AEDPoSViewer/AEDPoSViewerModule.cs index eabd86d..48c582d 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerModule.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerModule.cs @@ -1,4 +1,4 @@ -using AElf.Client.Abp; +using AElf.Client.Core; using Volo.Abp.Modularity; namespace AEDPoSViewer; diff --git a/examples/AEDPoSViewer/AEDPoSViewerService.cs b/examples/AEDPoSViewer/AEDPoSViewerService.cs index fc0569a..b78e3e7 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerService.cs @@ -1,5 +1,5 @@ using AElf.Client; -using AElf.Client.Abp; +using AElf.Client.Core; using AElf.Contracts.Consensus.AEDPoS; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; diff --git a/examples/CrossChainManager/CrossChainManager.csproj b/examples/CrossChainManager/CrossChainManager.csproj index 25943f0..b0fdbcd 100644 --- a/examples/CrossChainManager/CrossChainManager.csproj +++ b/examples/CrossChainManager/CrossChainManager.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/examples/CrossChainManager/CrossChainManagerModule.cs b/examples/CrossChainManager/CrossChainManagerModule.cs index b13c96a..f1d1a5c 100644 --- a/examples/CrossChainManager/CrossChainManagerModule.cs +++ b/examples/CrossChainManager/CrossChainManagerModule.cs @@ -1,5 +1,5 @@ -using AElf.Client.Abp; -using AElf.Client.Abp.CrossChain; +using AElf.Client.Core; +using AElf.Client.CrossChain; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; diff --git a/examples/CrossChainManager/CrossChainManagerService.cs b/examples/CrossChainManager/CrossChainManagerService.cs index c479454..be20e27 100644 --- a/examples/CrossChainManager/CrossChainManagerService.cs +++ b/examples/CrossChainManager/CrossChainManagerService.cs @@ -1,4 +1,4 @@ -using AElf.Client.Abp.CrossChain; +using AElf.Client.CrossChain; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Volo.Abp.DependencyInjection; diff --git a/examples/CrossChainManager/appsettings.json b/examples/CrossChainManager/appsettings.json index 462b2aa..f4f09ae 100644 --- a/examples/CrossChainManager/appsettings.json +++ b/examples/CrossChainManager/appsettings.json @@ -43,9 +43,9 @@ ] }, "AElfClientConfig": { - "ClientAlias": "TestNetSidechain", + "ClientAlias": "TestNetSideChain", "MainChainClientAlias": "TestNetMainChain", - "SidechainClientAlias": "TestNetSidechain", + "SideChainClientAlias": "TestNetSideChain", "AccountAlias": "eanz", "CamelCase": false } diff --git a/examples/TokenManager/TokenManager.csproj b/examples/TokenManager/TokenManager.csproj index 6bf13c4..d8fa27a 100644 --- a/examples/TokenManager/TokenManager.csproj +++ b/examples/TokenManager/TokenManager.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs index 7766cc4..be3f260 100644 --- a/examples/TokenManager/TokenManagerHostedService.cs +++ b/examples/TokenManager/TokenManagerHostedService.cs @@ -40,7 +40,7 @@ public async Task StartAsync(CancellationToken cancellationToken) /* await tokenManagerService.CrossChainTransferAsync( Address.FromBase58("2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT"), "ELF", 100000_00000000, - EndpointType.TestNetSidechain.ToString()); + EndpointType.TestNetSideChain2.ToString()); */ await tokenManagerService.GetTokenInfoAsync("ELF"); } diff --git a/examples/TokenManager/TokenManagerModule.cs b/examples/TokenManager/TokenManagerModule.cs index a9e9837..109ea9a 100644 --- a/examples/TokenManager/TokenManagerModule.cs +++ b/examples/TokenManager/TokenManagerModule.cs @@ -1,5 +1,5 @@ -using AElf.Client.Abp; -using AElf.Client.Abp.Token; +using AElf.Client.Core; +using AElf.Client.Token; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs index 5f952bf..e468e97 100644 --- a/examples/TokenManager/TokenManagerService.cs +++ b/examples/TokenManager/TokenManagerService.cs @@ -1,7 +1,7 @@ using AElf.Client; -using AElf.Client.Abp.Token; -using AElf.Client.Abp.Token.CrossChainTransfer; -using AElf.Client.Abp.Token.SyncTokenInfo; +using AElf.Client.Token; +using AElf.Client.Token.CrossChainTransfer; +using AElf.Client.Token.SyncTokenInfo; using AElf.Contracts.MultiToken; using AElf.Types; using Microsoft.Extensions.DependencyInjection; diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json index b1d4965..004dab3 100644 --- a/examples/TokenManager/appsettings.json +++ b/examples/TokenManager/appsettings.json @@ -46,9 +46,9 @@ "NFTContractAddress": "" }, "AElfClientConfig": { - "ClientAlias": "TestNetSidechain", + "ClientAlias": "TestNetSideChain", "MainChainClientAlias": "TestNetMainChain", - "SidechainClientAlias": "TestNetSidechain", + "SideChainClientAlias": "TestNetSideChain", "AccountAlias": "eanz", "CamelCase": false } diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs b/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs deleted file mode 100644 index 51f969f..0000000 --- a/src/AElf.Client.Abp.Consensus.AEDPoS/AElfClientAEDPoSModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Abp.Consensus.AEDPoS; - -public class AElfClientAEDPoSModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj b/src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj deleted file mode 100644 index 10e6feb..0000000 --- a/src/AElf.Client.Abp.Core/AElf.Client.Abp.Core.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - diff --git a/src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj b/src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj deleted file mode 100644 index df06cf7..0000000 --- a/src/AElf.Client.Abp.Election/AElf.Client.Abp.Election.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - net6.0 - enable - enable - AElf.Client.Abp.Election - - - diff --git a/src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs b/src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs deleted file mode 100644 index d10ea29..0000000 --- a/src/AElf.Client.Abp.NFTMarket/AElfClientNFTMarketModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Abp.NFTMarket; - -public class AElfClientNFTMarketModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj b/src/AElf.Client.Association/AElf.Client.Association.csproj similarity index 100% rename from src/AElf.Client.Abp.Association/AElf.Client.Abp.Association.csproj rename to src/AElf.Client.Association/AElf.Client.Association.csproj diff --git a/src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs b/src/AElf.Client.Association/AElfClientAssociationModule.cs similarity index 51% rename from src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs rename to src/AElf.Client.Association/AElfClientAssociationModule.cs index 8a518db..ed933d7 100644 --- a/src/AElf.Client.Abp.Association/AElfClientAssociationModule.cs +++ b/src/AElf.Client.Association/AElfClientAssociationModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Association; +namespace AElf.Client.Association; public class AElfClientAssociationModule { diff --git a/src/AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj b/src/AElf.Client.Bridge/AElf.Client.Bridge.csproj similarity index 100% rename from src/AElf.Client.Abp.Bridge/AElf.Client.Abp.Bridge.csproj rename to src/AElf.Client.Bridge/AElf.Client.Bridge.csproj diff --git a/src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs b/src/AElf.Client.Bridge/AElfClientBridgeModule.cs similarity index 51% rename from src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs rename to src/AElf.Client.Bridge/AElfClientBridgeModule.cs index fa7b6c6..e8d08a9 100644 --- a/src/AElf.Client.Abp.Bridge/AElfClientBridgeModule.cs +++ b/src/AElf.Client.Bridge/AElfClientBridgeModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Bridge; +namespace AElf.Client.Bridge; public class AElfClientBridgeModule { diff --git a/src/AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj b/src/AElf.Client.Configuration/AElf.Client.Configuration.csproj similarity index 100% rename from src/AElf.Client.Abp.Configuration/AElf.Client.Abp.Configuration.csproj rename to src/AElf.Client.Configuration/AElf.Client.Configuration.csproj diff --git a/src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs b/src/AElf.Client.Configuration/AElfClientConfigurationModule.cs similarity index 51% rename from src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs rename to src/AElf.Client.Configuration/AElfClientConfigurationModule.cs index 08cf6ce..5564be6 100644 --- a/src/AElf.Client.Abp.Configuration/AElfClientConfigurationModule.cs +++ b/src/AElf.Client.Configuration/AElfClientConfigurationModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Configuration; +namespace AElf.Client.Configuration; public class AElfClientConfigurationModule { diff --git a/src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj b/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj similarity index 100% rename from src/AElf.Client.Abp.Consensus.AEDPoS/AElf.Client.Abp.Consensus.AEDPoS.csproj rename to src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj diff --git a/src/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs b/src/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs new file mode 100644 index 0000000..36c3bee --- /dev/null +++ b/src/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs @@ -0,0 +1,5 @@ +namespace AElf.Client.Consensus.AEDPoS; + +public class AElfClientAEDPoSModule +{ +} \ No newline at end of file diff --git a/src/AElf.Client.Abp/AElf.Client.Abp.csproj b/src/AElf.Client.Core/AElf.Client.Core.csproj similarity index 87% rename from src/AElf.Client.Abp/AElf.Client.Abp.csproj rename to src/AElf.Client.Core/AElf.Client.Core.csproj index 4d49632..39f3218 100644 --- a/src/AElf.Client.Abp/AElf.Client.Abp.csproj +++ b/src/AElf.Client.Core/AElf.Client.Core.csproj @@ -4,10 +4,11 @@ net6.0 enable enable - AElf.Client.Abp + AElf.Client.Core AElf C# sdk with abp module. AElf true + AElf.Client.Core diff --git a/src/AElf.Client.Abp/AElfClientAbpConstants.cs b/src/AElf.Client.Core/AElfClientAbpConstants.cs similarity index 76% rename from src/AElf.Client.Abp/AElfClientAbpConstants.cs rename to src/AElf.Client.Core/AElfClientAbpConstants.cs index b8ba12d..2db31b0 100644 --- a/src/AElf.Client.Abp/AElfClientAbpConstants.cs +++ b/src/AElf.Client.Core/AElfClientAbpConstants.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public class AElfClientAbpConstants { diff --git a/src/AElf.Client.Abp/AElfClientModule.cs b/src/AElf.Client.Core/AElfClientModule.cs similarity index 94% rename from src/AElf.Client.Abp/AElfClientModule.cs rename to src/AElf.Client.Core/AElfClientModule.cs index 6b83d19..8d895db 100644 --- a/src/AElf.Client.Abp/AElfClientModule.cs +++ b/src/AElf.Client.Core/AElfClientModule.cs @@ -1,11 +1,11 @@ -using AElf.Client.Options; +using AElf.Client.Core.Options; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; [DependsOn( typeof(AbpAutofacModule), diff --git a/src/AElf.Client.Abp/AElfClientService.Blockchain.cs b/src/AElf.Client.Core/AElfClientService.Blockchain.cs similarity index 98% rename from src/AElf.Client.Abp/AElfClientService.Blockchain.cs rename to src/AElf.Client.Core/AElfClientService.Blockchain.cs index 75154b4..7aa6d24 100644 --- a/src/AElf.Client.Abp/AElfClientService.Blockchain.cs +++ b/src/AElf.Client.Core/AElfClientService.Blockchain.cs @@ -1,7 +1,7 @@ using AElf.Client.Dto; using Microsoft.Extensions.Logging; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public partial class AElfClientService { diff --git a/src/AElf.Client.Abp/AElfClientService.Send.cs b/src/AElf.Client.Core/AElfClientService.Send.cs similarity index 98% rename from src/AElf.Client.Abp/AElfClientService.Send.cs rename to src/AElf.Client.Core/AElfClientService.Send.cs index 759c85c..7eae382 100644 --- a/src/AElf.Client.Abp/AElfClientService.Send.cs +++ b/src/AElf.Client.Core/AElfClientService.Send.cs @@ -1,7 +1,7 @@ using AElf.Client.Dto; using Google.Protobuf; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public partial class AElfClientService { diff --git a/src/AElf.Client.Abp/AElfClientService.View.cs b/src/AElf.Client.Core/AElfClientService.View.cs similarity index 97% rename from src/AElf.Client.Abp/AElfClientService.View.cs rename to src/AElf.Client.Core/AElfClientService.View.cs index c3bf71e..35f4e23 100644 --- a/src/AElf.Client.Abp/AElfClientService.View.cs +++ b/src/AElf.Client.Core/AElfClientService.View.cs @@ -1,5 +1,5 @@ using AElf.Client.Dto; -using AElf.Client.Options; +using AElf.Client.Core.Options; using Google.Protobuf; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -7,7 +7,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectMapping; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public partial class AElfClientService : IAElfClientService, ITransientDependency { diff --git a/src/AElf.Client.Abp/ContractServiceBase.cs b/src/AElf.Client.Core/ContractServiceBase.cs similarity index 98% rename from src/AElf.Client.Abp/ContractServiceBase.cs rename to src/AElf.Client.Core/ContractServiceBase.cs index 3cfaf17..036fef5 100644 --- a/src/AElf.Client.Abp/ContractServiceBase.cs +++ b/src/AElf.Client.Core/ContractServiceBase.cs @@ -1,7 +1,7 @@ using Google.Protobuf; using Microsoft.Extensions.Logging; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public class ContractServiceBase { diff --git a/src/AElf.Client.Abp/GlobalUsings.cs b/src/AElf.Client.Core/GlobalUsings.cs similarity index 100% rename from src/AElf.Client.Abp/GlobalUsings.cs rename to src/AElf.Client.Core/GlobalUsings.cs diff --git a/src/AElf.Client.Abp/IAElfAccountProvider.cs b/src/AElf.Client.Core/IAElfAccountProvider.cs similarity index 97% rename from src/AElf.Client.Abp/IAElfAccountProvider.cs rename to src/AElf.Client.Core/IAElfAccountProvider.cs index 303669f..d245116 100644 --- a/src/AElf.Client.Abp/IAElfAccountProvider.cs +++ b/src/AElf.Client.Core/IAElfAccountProvider.cs @@ -1,5 +1,5 @@ -using AElf.Client.Abp.Infrastructure; -using AElf.Client.Options; +using AElf.Client.Core.Infrastructure; +using AElf.Client.Core.Options; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -7,7 +7,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Threading; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public interface IAElfAccountProvider { diff --git a/src/AElf.Client.Abp/IAElfClientProvider.cs b/src/AElf.Client.Core/IAElfClientProvider.cs similarity index 89% rename from src/AElf.Client.Abp/IAElfClientProvider.cs rename to src/AElf.Client.Core/IAElfClientProvider.cs index 73b3f4c..a0f1794 100644 --- a/src/AElf.Client.Abp/IAElfClientProvider.cs +++ b/src/AElf.Client.Core/IAElfClientProvider.cs @@ -1,8 +1,8 @@ -using AElf.Client.Options; +using AElf.Client.Core.Options; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public interface IAElfClientProvider { @@ -21,12 +21,12 @@ public AElfClientProvider(IOptionsSnapshot aelfClientOptions, var clientBuilder = new AElfClientBuilder(); SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetMainChain).UseCamelCase(useCamelCase).Build(), "MainNet", AElfClientConstants.MainChainId, "MainChain", EndpointType.MainNetMainChain.ToString()); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetSidechain).UseCamelCase(useCamelCase).Build(), - "MainNet", AElfClientConstants.SidechainId, "Sidechain", EndpointType.MainNetSidechain.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.MainNetSideChain1).UseCamelCase(useCamelCase).Build(), + "MainNet", AElfClientConstants.SideChainId2, "SideChain", EndpointType.MainNetSideChain1.ToString()); SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetMainChain).UseCamelCase(useCamelCase).Build(), "TestNet", AElfClientConstants.MainChainId, "MainChain", EndpointType.TestNetMainChain.ToString()); - SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetSidechain).UseCamelCase(useCamelCase).Build(), - "MainNet", AElfClientConstants.SidechainId, "Sidechain", EndpointType.TestNetSidechain.ToString()); + SetClient(clientBuilder.UsePublicEndpoint(EndpointType.TestNetSideChain2).UseCamelCase(useCamelCase).Build(), + "MainNet", AElfClientConstants.SideChainId2, "SideChain", EndpointType.TestNetSideChain2.ToString()); SetClient(clientBuilder.UsePublicEndpoint(EndpointType.Local).UseCamelCase(useCamelCase).Build(), "Local", AElfClientConstants.MainChainId, "MainChain", EndpointType.Local.ToString()); diff --git a/src/AElf.Client.Abp/IAElfClientService.cs b/src/AElf.Client.Core/IAElfClientService.cs similarity index 97% rename from src/AElf.Client.Abp/IAElfClientService.cs rename to src/AElf.Client.Core/IAElfClientService.cs index d797385..85c9739 100644 --- a/src/AElf.Client.Abp/IAElfClientService.cs +++ b/src/AElf.Client.Core/IAElfClientService.cs @@ -1,7 +1,7 @@ using AElf.Client.Dto; using Google.Protobuf; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public interface IAElfClientService { diff --git a/src/AElf.Client.Abp/Infrastructure/IKeyDirectoryProvider.cs b/src/AElf.Client.Core/Infrastructure/IKeyDirectoryProvider.cs similarity index 62% rename from src/AElf.Client.Abp/Infrastructure/IKeyDirectoryProvider.cs rename to src/AElf.Client.Core/Infrastructure/IKeyDirectoryProvider.cs index a89a5ee..77ef341 100644 --- a/src/AElf.Client.Abp/Infrastructure/IKeyDirectoryProvider.cs +++ b/src/AElf.Client.Core/Infrastructure/IKeyDirectoryProvider.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Infrastructure; +namespace AElf.Client.Core.Infrastructure; public interface IKeyDirectoryProvider { diff --git a/src/AElf.Client.Abp/Infrastructure/KeyDirectoryProvider.cs b/src/AElf.Client.Core/Infrastructure/KeyDirectoryProvider.cs similarity index 93% rename from src/AElf.Client.Abp/Infrastructure/KeyDirectoryProvider.cs rename to src/AElf.Client.Core/Infrastructure/KeyDirectoryProvider.cs index 99dd09b..789672b 100644 --- a/src/AElf.Client.Abp/Infrastructure/KeyDirectoryProvider.cs +++ b/src/AElf.Client.Core/Infrastructure/KeyDirectoryProvider.cs @@ -1,6 +1,6 @@ using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Infrastructure; +namespace AElf.Client.Core.Infrastructure; public class KeyDirectoryProvider : IKeyDirectoryProvider, ISingletonDependency { diff --git a/src/AElf.Client.Abp/Options/AElfAccountOptions.cs b/src/AElf.Client.Core/Options/AElfAccountOptions.cs similarity index 90% rename from src/AElf.Client.Abp/Options/AElfAccountOptions.cs rename to src/AElf.Client.Core/Options/AElfAccountOptions.cs index 310f2f5..a49e606 100644 --- a/src/AElf.Client.Abp/Options/AElfAccountOptions.cs +++ b/src/AElf.Client.Core/Options/AElfAccountOptions.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Options; +namespace AElf.Client.Core.Options; public class AElfAccountOptions { diff --git a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs b/src/AElf.Client.Core/Options/AElfClientConfigOptions.cs similarity index 55% rename from src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs rename to src/AElf.Client.Core/Options/AElfClientConfigOptions.cs index 5461aef..816a4ef 100644 --- a/src/AElf.Client.Abp/Options/AElfClientConfigOptions.cs +++ b/src/AElf.Client.Core/Options/AElfClientConfigOptions.cs @@ -1,10 +1,10 @@ -namespace AElf.Client.Options; +namespace AElf.Client.Core.Options; public class AElfClientConfigOptions { - public string ClientAlias { get; set; } = "TestNetSidechain"; + public string ClientAlias { get; set; } = "TestNetSideChain2"; public string MainChainClientAlias { get; set; } = "TestNetMainChain"; - public string SidechainClientAlias { get; set; } = "TestNetSidechain"; + public string SideChainClientAlias { get; set; } = "TestNetSideChain2"; public string AccountAlias { get; set; } = "Default"; public bool CamelCase { get; set; } = false; } \ No newline at end of file diff --git a/src/AElf.Client.Abp/Options/AElfClientOptions.cs b/src/AElf.Client.Core/Options/AElfClientOptions.cs similarity index 90% rename from src/AElf.Client.Abp/Options/AElfClientOptions.cs rename to src/AElf.Client.Core/Options/AElfClientOptions.cs index 3d921ad..ae612dd 100644 --- a/src/AElf.Client.Abp/Options/AElfClientOptions.cs +++ b/src/AElf.Client.Core/Options/AElfClientOptions.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Options; +namespace AElf.Client.Core.Options; public class AElfClientOptions { diff --git a/src/AElf.Client.Abp/Options/AElfContractOptions.cs b/src/AElf.Client.Core/Options/AElfContractOptions.cs similarity index 79% rename from src/AElf.Client.Abp/Options/AElfContractOptions.cs rename to src/AElf.Client.Core/Options/AElfContractOptions.cs index 5ee87d7..7fb8fa0 100644 --- a/src/AElf.Client.Abp/Options/AElfContractOptions.cs +++ b/src/AElf.Client.Core/Options/AElfContractOptions.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Options; +namespace AElf.Client.Core.Options; public class AElfContractOptions { diff --git a/src/AElf.Client.Abp/Profile/CommonProfile.cs b/src/AElf.Client.Core/Profile/CommonProfile.cs similarity index 95% rename from src/AElf.Client.Abp/Profile/CommonProfile.cs rename to src/AElf.Client.Core/Profile/CommonProfile.cs index e025ada..3bacaa9 100644 --- a/src/AElf.Client.Abp/Profile/CommonProfile.cs +++ b/src/AElf.Client.Core/Profile/CommonProfile.cs @@ -1,6 +1,6 @@ using Google.Protobuf; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public class CommonProfile : AutoMapper.Profile { diff --git a/src/AElf.Client.Abp/Profile/MerklePathProfile.cs b/src/AElf.Client.Core/Profile/MerklePathProfile.cs similarity index 92% rename from src/AElf.Client.Abp/Profile/MerklePathProfile.cs rename to src/AElf.Client.Core/Profile/MerklePathProfile.cs index 5574786..8a9bf65 100644 --- a/src/AElf.Client.Abp/Profile/MerklePathProfile.cs +++ b/src/AElf.Client.Core/Profile/MerklePathProfile.cs @@ -1,7 +1,7 @@ using AElf.Client.Dto; using AutoMapper; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public class MerklePathProfile : Profile { diff --git a/src/AElf.Client.Abp/Profile/TransactionProfile.cs b/src/AElf.Client.Core/Profile/TransactionProfile.cs similarity index 99% rename from src/AElf.Client.Abp/Profile/TransactionProfile.cs rename to src/AElf.Client.Core/Profile/TransactionProfile.cs index 8bcf7c1..c23e87b 100644 --- a/src/AElf.Client.Abp/Profile/TransactionProfile.cs +++ b/src/AElf.Client.Core/Profile/TransactionProfile.cs @@ -3,7 +3,7 @@ using Google.Protobuf; using Volo.Abp.AutoMapper; -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public class TransactionProfile : Profile { diff --git a/src/AElf.Client.Abp/SendTransactionResult.cs b/src/AElf.Client.Core/SendTransactionResult.cs similarity index 84% rename from src/AElf.Client.Abp/SendTransactionResult.cs rename to src/AElf.Client.Core/SendTransactionResult.cs index 81f8104..057d94e 100644 --- a/src/AElf.Client.Abp/SendTransactionResult.cs +++ b/src/AElf.Client.Core/SendTransactionResult.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp; +namespace AElf.Client.Core; public class SendTransactionResult { diff --git a/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj b/src/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj similarity index 75% rename from src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj rename to src/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj index a49c765..0d48e63 100644 --- a/src/AElf.Client.Abp.CrossChain/AElf.Client.Abp.CrossChain.csproj +++ b/src/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs b/src/AElf.Client.CrossChain/AElfClientCrossChainModule.cs similarity index 59% rename from src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs rename to src/AElf.Client.CrossChain/AElfClientCrossChainModule.cs index 78c0fb1..f53ed5f 100644 --- a/src/AElf.Client.Abp.CrossChain/AElfClientCrossChainModule.cs +++ b/src/AElf.Client.CrossChain/AElfClientCrossChainModule.cs @@ -1,6 +1,7 @@ -using Volo.Abp.Modularity; +using AElf.Client.Core; +using Volo.Abp.Modularity; -namespace AElf.Client.Abp.CrossChain; +namespace AElf.Client.CrossChain; [DependsOn( typeof(AElfClientModule), diff --git a/src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs b/src/AElf.Client.CrossChain/AElfCrossChainConstants.cs similarity index 77% rename from src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs rename to src/AElf.Client.CrossChain/AElfCrossChainConstants.cs index e28a9c4..3bc30cd 100644 --- a/src/AElf.Client.Abp.CrossChain/AElfCrossChainConstants.cs +++ b/src/AElf.Client.CrossChain/AElfCrossChainConstants.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.CrossChain; +namespace AElf.Client.CrossChain; public class AElfCrossChainConstants { diff --git a/src/AElf.Client.Abp.CrossChain/CrossChainService.cs b/src/AElf.Client.CrossChain/CrossChainService.cs similarity index 94% rename from src/AElf.Client.Abp.CrossChain/CrossChainService.cs rename to src/AElf.Client.CrossChain/CrossChainService.cs index e83e99c..433e240 100644 --- a/src/AElf.Client.Abp.CrossChain/CrossChainService.cs +++ b/src/AElf.Client.CrossChain/CrossChainService.cs @@ -1,10 +1,11 @@ -using AElf.Client.Options; +using AElf.Client.Core; +using AElf.Client.Core.Options; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.CrossChain; +namespace AElf.Client.CrossChain; public class CrossChainService : ContractServiceBase, ICrossChainService, ITransientDependency { diff --git a/src/AElf.Client.Abp.CrossChain/ICrossChainService.cs b/src/AElf.Client.CrossChain/ICrossChainService.cs similarity index 71% rename from src/AElf.Client.Abp.CrossChain/ICrossChainService.cs rename to src/AElf.Client.CrossChain/ICrossChainService.cs index 0dc7864..8537c8d 100644 --- a/src/AElf.Client.Abp.CrossChain/ICrossChainService.cs +++ b/src/AElf.Client.CrossChain/ICrossChainService.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.CrossChain; +namespace AElf.Client.CrossChain; public interface ICrossChainService { diff --git a/src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj b/src/AElf.Client.Election/AElf.Client.Election.csproj similarity index 100% rename from src/AElf.Client.Abp.Genesis/AElf.Client.Abp.Genesis.csproj rename to src/AElf.Client.Election/AElf.Client.Election.csproj diff --git a/src/AElf.Client.Abp.Election/AElfClientElectionModule.cs b/src/AElf.Client.Election/AElfClientElectionModule.cs similarity index 51% rename from src/AElf.Client.Abp.Election/AElfClientElectionModule.cs rename to src/AElf.Client.Election/AElfClientElectionModule.cs index 5ac1487..3b15cff 100644 --- a/src/AElf.Client.Abp.Election/AElfClientElectionModule.cs +++ b/src/AElf.Client.Election/AElfClientElectionModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Election; +namespace AElf.Client.Election; public class AElfClientElectionModule { diff --git a/src/AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj b/src/AElf.Client.Genesis/AElf.Client.Genesis.csproj similarity index 100% rename from src/AElf.Client.Abp.NFTMarket/AElf.Client.Abp.NFTMarket.csproj rename to src/AElf.Client.Genesis/AElf.Client.Genesis.csproj diff --git a/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs b/src/AElf.Client.Genesis/AElfClientGenesisModule.cs similarity index 51% rename from src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs rename to src/AElf.Client.Genesis/AElfClientGenesisModule.cs index 6aa310f..86b2776 100644 --- a/src/AElf.Client.Abp.Genesis/AElfClientGenesisModule.cs +++ b/src/AElf.Client.Genesis/AElfClientGenesisModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Genesis; +namespace AElf.Client.Genesis; public class AElfClientGenesisModule { diff --git a/src/AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj b/src/AElf.Client.Oracle/AElf.Client.Oracle.csproj similarity index 100% rename from src/AElf.Client.Abp.Oracle/AElf.Client.Abp.Oracle.csproj rename to src/AElf.Client.Oracle/AElf.Client.Oracle.csproj diff --git a/src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs b/src/AElf.Client.Oracle/AElfClientOracleModule.cs similarity index 51% rename from src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs rename to src/AElf.Client.Oracle/AElfClientOracleModule.cs index 8a9aaec..09eafbd 100644 --- a/src/AElf.Client.Abp.Oracle/AElfClientOracleModule.cs +++ b/src/AElf.Client.Oracle/AElfClientOracleModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Oracle; +namespace AElf.Client.Oracle; public class AElfClientOracleModule { diff --git a/src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj b/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj similarity index 100% rename from src/AElf.Client.Abp.Parliament/AElf.Client.Abp.Parliament.csproj rename to src/AElf.Client.Parliament/AElf.Client.Parliament.csproj diff --git a/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs b/src/AElf.Client.Parliament/AElfClientParliamentModule.cs similarity index 51% rename from src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs rename to src/AElf.Client.Parliament/AElfClientParliamentModule.cs index f1ec434..6484be2 100644 --- a/src/AElf.Client.Abp.Parliament/AElfClientParliamentModule.cs +++ b/src/AElf.Client.Parliament/AElfClientParliamentModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Parliament; +namespace AElf.Client.Parliament; public class AElfClientParliamentModule { diff --git a/src/AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj b/src/AElf.Client.Profit/AElf.Client.Profit.csproj similarity index 100% rename from src/AElf.Client.Abp.Profit/AElf.Client.Abp.Profit.csproj rename to src/AElf.Client.Profit/AElf.Client.Profit.csproj diff --git a/src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs b/src/AElf.Client.Profit/AElfClientProfitModule.cs similarity index 51% rename from src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs rename to src/AElf.Client.Profit/AElfClientProfitModule.cs index 2c59b61..31899b5 100644 --- a/src/AElf.Client.Abp.Profit/AElfClientProfitModule.cs +++ b/src/AElf.Client.Profit/AElfClientProfitModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Profit; +namespace AElf.Client.Profit; public class AElfClientProfitModule { diff --git a/src/AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj b/src/AElf.Client.Referendum/AElf.Client.Referendum.csproj similarity index 100% rename from src/AElf.Client.Abp.Referendum/AElf.Client.Abp.Referendum.csproj rename to src/AElf.Client.Referendum/AElf.Client.Referendum.csproj diff --git a/src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs b/src/AElf.Client.Referendum/AElfClientReferendumModule.cs similarity index 51% rename from src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs rename to src/AElf.Client.Referendum/AElfClientReferendumModule.cs index b809d28..15ac370 100644 --- a/src/AElf.Client.Abp.Referendum/AElfClientReferendumModule.cs +++ b/src/AElf.Client.Referendum/AElfClientReferendumModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Referendum; +namespace AElf.Client.Referendum; public class AElfClientReferendumModule { diff --git a/src/AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj b/src/AElf.Client.Regiment/AElf.Client.Regiment.csproj similarity index 100% rename from src/AElf.Client.Abp.Regiment/AElf.Client.Abp.Regiment.csproj rename to src/AElf.Client.Regiment/AElf.Client.Regiment.csproj diff --git a/src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs b/src/AElf.Client.Regiment/AElfClientRegimentModule.cs similarity index 51% rename from src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs rename to src/AElf.Client.Regiment/AElfClientRegimentModule.cs index 2b1307e..18683e0 100644 --- a/src/AElf.Client.Abp.Regiment/AElfClientRegimentModule.cs +++ b/src/AElf.Client.Regiment/AElfClientRegimentModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Regiment; +namespace AElf.Client.Regiment; public class AElfClientRegimentModule { diff --git a/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj b/src/AElf.Client.Token/AElf.Client.Token.csproj similarity index 59% rename from src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj rename to src/AElf.Client.Token/AElf.Client.Token.csproj index a366b41..4c7b7c5 100644 --- a/src/AElf.Client.Abp.Token/AElf.Client.Abp.Token.csproj +++ b/src/AElf.Client.Token/AElf.Client.Token.csproj @@ -4,16 +4,15 @@ net6.0 enable enable - AElf.Client.Abp.Token - AElf.Client.Abp.Token + AElf.Client.Token AElf token manager abp module. AElf true - - + + diff --git a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs b/src/AElf.Client.Token/AElfClientTokenModule.cs similarity index 89% rename from src/AElf.Client.Abp.Token/AElfClientTokenModule.cs rename to src/AElf.Client.Token/AElfClientTokenModule.cs index 04f73db..33131ce 100644 --- a/src/AElf.Client.Abp.Token/AElfClientTokenModule.cs +++ b/src/AElf.Client.Token/AElfClientTokenModule.cs @@ -1,11 +1,12 @@ -using AElf.Client.Abp.CrossChain; -using AElf.Client.Options; +using AElf.Client.Core; +using AElf.Client.Core.Options; +using AElf.Client.CrossChain; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Token; [DependsOn( typeof(AElfClientModule), diff --git a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs b/src/AElf.Client.Token/AElfTokenConstants.cs similarity index 70% rename from src/AElf.Client.Abp.Token/AElfTokenConstants.cs rename to src/AElf.Client.Token/AElfTokenConstants.cs index 64facc7..4b6f692 100644 --- a/src/AElf.Client.Abp.Token/AElfTokenConstants.cs +++ b/src/AElf.Client.Token/AElfTokenConstants.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Token; public class AElfTokenConstants { @@ -7,5 +7,5 @@ public class AElfTokenConstants public const string CrossChainTransferQueueName = "CrossChainTransfer"; public const int DefaultMaxDegreeOfParallelism = int.MaxValue; public const int TenSeconds = 10_000; - public const string TestNetSidechainMultiTokenContractAddress = "7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX"; + public const string TestNetSideChain1MultiTokenContractAddress = "7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX"; } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs b/src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs similarity index 94% rename from src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs rename to src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs index 26d6c3a..ebf6679 100644 --- a/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferQueueService.cs +++ b/src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs @@ -1,7 +1,7 @@ using AElf.Types; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Token.CrossChainTransfer; +namespace AElf.Client.Token.CrossChainTransfer; public class CrossChainTransferQueueService : ICrossChainTransferQueueService, ITransientDependency { diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs b/src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs similarity index 97% rename from src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs rename to src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs index 6c6aa0b..4fedc66 100644 --- a/src/AElf.Client.Abp.Token/CrossChainTransfer/CrossChainTransferService.cs +++ b/src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs @@ -1,4 +1,5 @@ -using AElf.Client.Options; +using AElf.Client.Core; +using AElf.Client.Core.Options; using AElf.Contracts.MultiToken; using AElf.Types; using Google.Protobuf; @@ -6,7 +7,7 @@ using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Token.CrossChainTransfer; +namespace AElf.Client.Token.CrossChainTransfer; public class CrossChainTransferService : ICrossChainTransferService, ITransientDependency { diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs b/src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs similarity index 77% rename from src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs rename to src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs index d53f01a..794a13e 100644 --- a/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs +++ b/src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs @@ -1,6 +1,6 @@ using AElf.Types; -namespace AElf.Client.Abp.Token.CrossChainTransfer; +namespace AElf.Client.Token.CrossChainTransfer; public interface ICrossChainTransferQueueService { diff --git a/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs b/src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs similarity index 78% rename from src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs rename to src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs index b523886..bcfdb65 100644 --- a/src/AElf.Client.Abp.Token/CrossChainTransfer/ICrossChainTransferService.cs +++ b/src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs @@ -1,6 +1,6 @@ using AElf.Types; -namespace AElf.Client.Abp.Token.CrossChainTransfer; +namespace AElf.Client.Token.CrossChainTransfer; public interface ICrossChainTransferService { diff --git a/src/AElf.Client.Abp.Token/ITokenService.cs b/src/AElf.Client.Token/ITokenService.cs similarity index 96% rename from src/AElf.Client.Abp.Token/ITokenService.cs rename to src/AElf.Client.Token/ITokenService.cs index 668e9f5..87b3c3b 100644 --- a/src/AElf.Client.Abp.Token/ITokenService.cs +++ b/src/AElf.Client.Token/ITokenService.cs @@ -1,10 +1,11 @@ +using AElf.Client.Core; using AElf.Contracts.Bridge; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; using AElf.Types; using TransferInput = AElf.Contracts.MultiToken.TransferInput; -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Token; public interface ITokenService { diff --git a/src/AElf.Client.Abp.Token/README.md b/src/AElf.Client.Token/README.md similarity index 100% rename from src/AElf.Client.Abp.Token/README.md rename to src/AElf.Client.Token/README.md diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs b/src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs similarity index 63% rename from src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs rename to src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs index 1558f27..6f28907 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs +++ b/src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Token.SyncTokenInfo; +namespace AElf.Client.Token.SyncTokenInfo; public interface ISyncTokenInfoQueueService { diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoService.cs b/src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs similarity index 64% rename from src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoService.cs rename to src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs index 279c5ae..8ebb3ff 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfo/ISyncTokenInfoService.cs +++ b/src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Token.SyncTokenInfo; +namespace AElf.Client.Token.SyncTokenInfo; public interface ISyncTokenInfoService { diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs b/src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs similarity index 93% rename from src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs rename to src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs index 8b5a177..c6d506e 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs +++ b/src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs @@ -1,6 +1,6 @@ using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Token.SyncTokenInfo; +namespace AElf.Client.Token.SyncTokenInfo; public class SyncTokenInfoQueueService : ISyncTokenInfoQueueService, ITransientDependency { diff --git a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs b/src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs similarity index 96% rename from src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs rename to src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs index 0b15ddc..930c8e5 100644 --- a/src/AElf.Client.Abp.Token/SyncTokenInfo/SyncTokenInfoService.cs +++ b/src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs @@ -1,5 +1,6 @@ -using AElf.Client.Abp.CrossChain; -using AElf.Client.Options; +using AElf.Client.Core; +using AElf.Client.Core.Options; +using AElf.Client.CrossChain; using AElf.Contracts.MultiToken; using AElf.Types; using Google.Protobuf; @@ -8,7 +9,7 @@ using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Token.SyncTokenInfo; +namespace AElf.Client.Token.SyncTokenInfo; public class SyncTokenInfoService : ISyncTokenInfoService, ITransientDependency { diff --git a/src/AElf.Client.Abp.Token/TokenService.Send.cs b/src/AElf.Client.Token/TokenService.Send.cs similarity index 94% rename from src/AElf.Client.Abp.Token/TokenService.Send.cs rename to src/AElf.Client.Token/TokenService.Send.cs index de47732..84a3675 100644 --- a/src/AElf.Client.Abp.Token/TokenService.Send.cs +++ b/src/AElf.Client.Token/TokenService.Send.cs @@ -1,4 +1,5 @@ -using AElf.Client.Options; +using AElf.Client.Core; +using AElf.Client.Core.Options; using AElf.Contracts.Bridge; using AElf.Contracts.MultiToken; using AElf.Contracts.NFT; @@ -8,7 +9,7 @@ using CreateInput = AElf.Contracts.MultiToken.CreateInput; using TransferInput = AElf.Contracts.MultiToken.TransferInput; -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Token; public partial class TokenService : ContractServiceBase, ITokenService, ITransientDependency { @@ -74,7 +75,7 @@ public async Task ValidateTokenInfoExistsAsync( public async Task CrossChainCreateTokenAsync( CrossChainCreateTokenInput crossChainCreateTokenInput) { - var clientAlias = PreferGetUseSidechainClientAlias(); + var clientAlias = PreferGetUseSideChainClientAlias(); var tx = await PerformSendTransactionAsync("CrossChainCreateToken", crossChainCreateTokenInput, clientAlias); return new SendTransactionResult { @@ -110,7 +111,7 @@ public async Task CrossChainReceiveTokenAsync( public async Task CrossChainCreateNFTProtocolAsync( CrossChainCreateInput crossChainCreateInput) { - var clientAlias = PreferGetUseSidechainClientAlias(); + var clientAlias = PreferGetUseSideChainClientAlias(); ContractAddress = Address.FromBase58(_contractOptions.NFTContractAddress); var tx = await PerformSendTransactionAsync("CrossChainCreate", crossChainCreateInput, clientAlias); @@ -167,10 +168,10 @@ private string PreferGetUseMainChainClientAlias() : _clientConfigOptions.ClientAlias; } - private string PreferGetUseSidechainClientAlias() + private string PreferGetUseSideChainClientAlias() { - return !string.IsNullOrEmpty(_clientConfigOptions.SidechainClientAlias) - ? _clientConfigOptions.SidechainClientAlias + return !string.IsNullOrEmpty(_clientConfigOptions.SideChainClientAlias) + ? _clientConfigOptions.SideChainClientAlias : _clientConfigOptions.ClientAlias; } } \ No newline at end of file diff --git a/src/AElf.Client.Abp.Token/TokenService.View.cs b/src/AElf.Client.Token/TokenService.View.cs similarity index 98% rename from src/AElf.Client.Abp.Token/TokenService.View.cs rename to src/AElf.Client.Token/TokenService.View.cs index 7a2bb8d..f3633fb 100644 --- a/src/AElf.Client.Abp.Token/TokenService.View.cs +++ b/src/AElf.Client.Token/TokenService.View.cs @@ -3,7 +3,7 @@ using Google.Protobuf; using Microsoft.Extensions.Logging; -namespace AElf.Client.Abp.Token; +namespace AElf.Client.Token; public partial class TokenService { diff --git a/src/AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj b/src/AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj similarity index 100% rename from src/AElf.Client.Abp.TokenConverter/AElf.Client.Abp.TokenConverter.csproj rename to src/AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj diff --git a/src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs b/src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs similarity index 51% rename from src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs rename to src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs index 70cc362..641effb 100644 --- a/src/AElf.Client.Abp.TokenConverter/AElfClientTokenConverterModule.cs +++ b/src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.TokenConverter; +namespace AElf.Client.TokenConverter; public class AElfClientTokenConverterModule { diff --git a/src/AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj b/src/AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj similarity index 100% rename from src/AElf.Client.Abp.TokenHolder/AElf.Client.Abp.TokenHolder.csproj rename to src/AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj diff --git a/src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs b/src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs similarity index 51% rename from src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs rename to src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs index b6e9bd1..07a915b 100644 --- a/src/AElf.Client.Abp.TokenHolder/AElfClientTokenHolderModule.cs +++ b/src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.TokenHolder; +namespace AElf.Client.TokenHolder; public class AElfClientTokenHolderModule { diff --git a/src/AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj b/src/AElf.Client.Vote/AElf.Client.Vote.csproj similarity index 100% rename from src/AElf.Client.Abp.Vote/AElf.Client.Abp.Vote.csproj rename to src/AElf.Client.Vote/AElf.Client.Vote.csproj diff --git a/src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs b/src/AElf.Client.Vote/AElfClientVoteModule.cs similarity index 52% rename from src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs rename to src/AElf.Client.Vote/AElfClientVoteModule.cs index 4f48dff..bb3ccbb 100644 --- a/src/AElf.Client.Abp.Vote/AElfClientVoteModule.cs +++ b/src/AElf.Client.Vote/AElfClientVoteModule.cs @@ -1,4 +1,4 @@ -namespace AElf.Client.Abp.Vote; +namespace AElf.Client.Vote; public class AElfClientVoteModule { diff --git a/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj b/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj similarity index 81% rename from src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj rename to src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj index a864077..2bc654f 100644 --- a/src/AElf.Client.Abp.Whitelist/AElf.Client.Abp.Whitelist.csproj +++ b/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs b/src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs similarity index 58% rename from src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs rename to src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs index 84a2c3d..d49816c 100644 --- a/src/AElf.Client.Abp.Whitelist/AElfClientWhitelistModule.cs +++ b/src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs @@ -1,6 +1,7 @@ -using Volo.Abp.Modularity; +using AElf.Client.Core; +using Volo.Abp.Modularity; -namespace AElf.Client.Abp.Whitelist; +namespace AElf.Client.Whitelist; [DependsOn( typeof(AElfClientModule), diff --git a/src/AElf.Client.Abp.Whitelist/IWhitelistService.cs b/src/AElf.Client.Whitelist/IWhitelistService.cs similarity index 74% rename from src/AElf.Client.Abp.Whitelist/IWhitelistService.cs rename to src/AElf.Client.Whitelist/IWhitelistService.cs index 0c85907..f06a6c2 100644 --- a/src/AElf.Client.Abp.Whitelist/IWhitelistService.cs +++ b/src/AElf.Client.Whitelist/IWhitelistService.cs @@ -1,6 +1,7 @@ +using AElf.Client.Core; using AElf.Contracts.Whitelist; -namespace AElf.Client.Abp.Whitelist; +namespace AElf.Client.Whitelist; public interface IWhitelistService { diff --git a/src/AElf.Client.Abp.Whitelist/WhitelistService.cs b/src/AElf.Client.Whitelist/WhitelistService.cs similarity index 93% rename from src/AElf.Client.Abp.Whitelist/WhitelistService.cs rename to src/AElf.Client.Whitelist/WhitelistService.cs index 7032ba4..75e9ca9 100644 --- a/src/AElf.Client.Abp.Whitelist/WhitelistService.cs +++ b/src/AElf.Client.Whitelist/WhitelistService.cs @@ -1,10 +1,11 @@ -using AElf.Client.Options; +using AElf.Client.Core; +using AElf.Client.Core.Options; using AElf.Contracts.Whitelist; using AElf.Types; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -namespace AElf.Client.Abp.Whitelist; +namespace AElf.Client.Whitelist; public class WhitelistService : ContractServiceBase, IWhitelistService, ITransientDependency { diff --git a/src/AElf.Client/AElfClientBuilder.cs b/src/AElf.Client/AElfClientBuilder.cs index e0ae620..91444fd 100644 --- a/src/AElf.Client/AElfClientBuilder.cs +++ b/src/AElf.Client/AElfClientBuilder.cs @@ -29,14 +29,14 @@ public AElfClientBuilder UsePublicEndpoint(EndpointType endpointType) case EndpointType.MainNetMainChain: NodeEndpoint = AElfClientConstants.MainNetMainChain; break; - case EndpointType.MainNetSidechain: - NodeEndpoint = AElfClientConstants.MainNetSidechain; + case EndpointType.MainNetSideChain1: + NodeEndpoint = AElfClientConstants.MainNetSideChain1; break; case EndpointType.TestNetMainChain: NodeEndpoint = AElfClientConstants.TestNetMainChain; break; - case EndpointType.TestNetSidechain: - NodeEndpoint = AElfClientConstants.TestNetSidechain; + case EndpointType.TestNetSideChain2: + NodeEndpoint = AElfClientConstants.TestNetSideChain2; break; case EndpointType.Local: default: diff --git a/src/AElf.Client/AElfClientConstants.cs b/src/AElf.Client/AElfClientConstants.cs index 5e37626..b988813 100644 --- a/src/AElf.Client/AElfClientConstants.cs +++ b/src/AElf.Client/AElfClientConstants.cs @@ -5,9 +5,10 @@ public class AElfClientConstants public const string DefaultPrivateKey = "09da44778f8db2e602fb484334f37df19e221c84c4582ce5b7770ccfbc3ddbef"; public const string LocalEndpoint = "http://127.0.0.1:1726"; public const string MainNetMainChain = "https://aelf-public-node.aelf.io"; - public const string MainNetSidechain = "https://tdvv-public-node.aelf.io"; - public const string TestNetMainChain = "http://54.199.254.157:8000"; - public const string TestNetSidechain = "https://tdvw-test-node.aelf.io"; + public const string MainNetSideChain1 = "https://tdvv-public-node.aelf.io"; + public const string TestNetMainChain = "https://aelf-test-node.aelf.io"; + public const string TestNetSideChain1 = "https://tdvv-test-node.aelf.io"; + public const string TestNetSideChain2 = "https://tdvw-test-node.aelf.io"; public const int MainChainId = 9992731; - public const int SidechainId = 1866392; + public const int SideChainId2 = 1866392; } \ No newline at end of file diff --git a/src/AElf.Client/EndpointType.cs b/src/AElf.Client/EndpointType.cs index 0b132fa..43011e0 100644 --- a/src/AElf.Client/EndpointType.cs +++ b/src/AElf.Client/EndpointType.cs @@ -3,8 +3,8 @@ namespace AElf.Client; public enum EndpointType { MainNetMainChain, - MainNetSidechain, + MainNetSideChain1, TestNetMainChain, - TestNetSidechain, + TestNetSideChain2, Local } \ No newline at end of file diff --git a/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj b/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj deleted file mode 100644 index 9ceb643..0000000 --- a/test/AElf.Client.Abp.Test/AElf.Client.Abp.Test.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - net6.0 - enable - enable - - false - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - diff --git a/test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs b/test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs deleted file mode 100644 index 9a7ba17..0000000 --- a/test/AElf.Client.Abp.Test/Whitelist/WhitelistServiceTests.cs +++ /dev/null @@ -1,15 +0,0 @@ -using AElf.Contracts.Whitelist; - -namespace AElf.Client.Abp.Test.Whitelist; - -[Trait("Category", "WhitelistContractService")] -public class WhitelistServiceTests : AElfClientAbpContractServiceTestBase -{ - [Theory] - [InlineData(true)] - public async Task CreateWhitelistTest(bool isClonable) - { - var extraInfoList = new ExtraInfoList(); - - } -} \ No newline at end of file diff --git a/test/AElf.Client.Test/AElf.Client.Test.csproj b/test/AElf.Client.Test/AElf.Client.Test.csproj index f6a8729..c89d123 100644 --- a/test/AElf.Client.Test/AElf.Client.Test.csproj +++ b/test/AElf.Client.Test/AElf.Client.Test.csproj @@ -3,18 +3,31 @@ net6.0 false + enable + + false + - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + - + + + diff --git a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs b/test/AElf.Client.Test/AElfClientAbpContractServiceTestBase.cs similarity index 83% rename from test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs rename to test/AElf.Client.Test/AElfClientAbpContractServiceTestBase.cs index ba7123f..c3b95c1 100644 --- a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestBase.cs +++ b/test/AElf.Client.Test/AElfClientAbpContractServiceTestBase.cs @@ -1,4 +1,4 @@ -using AElf.Client.Abp.TestBase; +using AElf.Client.TestBase; namespace AElf.Client.Abp.Test; diff --git a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs b/test/AElf.Client.Test/AElfClientAbpContractServiceTestModule.cs similarity index 78% rename from test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs rename to test/AElf.Client.Test/AElfClientAbpContractServiceTestModule.cs index 02791f1..df0caad 100644 --- a/test/AElf.Client.Abp.Test/AElfClientAbpContractServiceTestModule.cs +++ b/test/AElf.Client.Test/AElfClientAbpContractServiceTestModule.cs @@ -1,5 +1,5 @@ -using AElf.Client.Abp.TestBase; -using AElf.Client.Abp.Token; +using AElf.Client.TestBase; +using AElf.Client.Token; using Volo.Abp.Modularity; namespace AElf.Client.Abp.Test; diff --git a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Test/Token/TokenServiceTests.cs similarity index 91% rename from test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs rename to test/AElf.Client.Test/Token/TokenServiceTests.cs index 3e7a115..bd9f5cb 100644 --- a/test/AElf.Client.Abp.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Test/Token/TokenServiceTests.cs @@ -1,12 +1,14 @@ -using AElf.Client.Abp.Token; -using AElf.Client.Abp.Token.SyncTokenInfo; +using System.Threading.Tasks; +using AElf.Client.Abp.Test; +using AElf.Client.Token; +using AElf.Client.Token.SyncTokenInfo; using AElf.Contracts.Bridge; using AElf.Contracts.NFT; using AElf.Types; using Shouldly; using TransferInput = AElf.Contracts.MultiToken.TransferInput; -namespace AElf.Client.Abp.Test.Token; +namespace AElf.Client.Test.Token; [Trait("Category", "TokenContractService")] public sealed class TokenServiceTests : AElfClientAbpContractServiceTestBase @@ -29,7 +31,7 @@ public async Task GetTokenInfoTest(string symbol) } [Theory] - [InlineData("2nSXrp4iM3A1gB5WKXjkwJQwy56jzcw1ESNpVnWywnyjXFixGc", "ELF", 10_00000000)] + [InlineData("YNcE6ahghC1hGcbL9cf964Bzfw6kXkC86gYSFwSHe6i2vm8YH", "ELF", 2000_00000000)] public async Task TransferTest(string address, string symbol, long amount) { var result = await _tokenService.TransferAsync(new TransferInput diff --git a/test/AElf.Client.Abp.Test/Usings.cs b/test/AElf.Client.Test/Usings.cs similarity index 100% rename from test/AElf.Client.Abp.Test/Usings.cs rename to test/AElf.Client.Test/Usings.cs diff --git a/test/AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj b/test/AElf.Client.TestBase/AElf.Client.TestBase.csproj similarity index 100% rename from test/AElf.Client.Abp.TestBase/AElf.Client.Abp.TestBase.csproj rename to test/AElf.Client.TestBase/AElf.Client.TestBase.csproj diff --git a/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs b/test/AElf.Client.TestBase/AElfClientAbpTestBase.cs similarity index 95% rename from test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs rename to test/AElf.Client.TestBase/AElfClientAbpTestBase.cs index 215b499..6640b9d 100644 --- a/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBase.cs +++ b/test/AElf.Client.TestBase/AElfClientAbpTestBase.cs @@ -4,7 +4,7 @@ using Volo.Abp.Modularity; using Volo.Abp.Testing; -namespace AElf.Client.Abp.TestBase; +namespace AElf.Client.TestBase; public abstract class AElfClientAbpTestBase : AbpIntegratedTest where TStartupModule : IAbpModule diff --git a/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs b/test/AElf.Client.TestBase/AElfClientAbpTestBaseModule.cs similarity index 84% rename from test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs rename to test/AElf.Client.TestBase/AElfClientAbpTestBaseModule.cs index 524b9f4..9f9adb7 100644 --- a/test/AElf.Client.Abp.TestBase/AElfClientAbpTestBaseModule.cs +++ b/test/AElf.Client.TestBase/AElfClientAbpTestBaseModule.cs @@ -2,7 +2,7 @@ using Volo.Abp.Autofac; using Volo.Abp.Modularity; -namespace AElf.Client.Abp.TestBase; +namespace AElf.Client.TestBase; [DependsOn( typeof(AbpAutofacModule), diff --git a/test/AElf.Client.Abp.TestBase/Usings.cs b/test/AElf.Client.TestBase/Usings.cs similarity index 100% rename from test/AElf.Client.Abp.TestBase/Usings.cs rename to test/AElf.Client.TestBase/Usings.cs diff --git a/test/AElf.Client.Abp.TestBase/appsettings.json b/test/AElf.Client.TestBase/appsettings.json similarity index 94% rename from test/AElf.Client.Abp.TestBase/appsettings.json rename to test/AElf.Client.TestBase/appsettings.json index 90aea72..cb1fdb7 100644 --- a/test/AElf.Client.Abp.TestBase/appsettings.json +++ b/test/AElf.Client.TestBase/appsettings.json @@ -47,9 +47,9 @@ "BridgeContractAddress": "2RHf2fxsnEaM3wb6N1yGqPupNZbcCY98LgWbGSFWmWzgEs5Sjo" }, "AElfClientConfig": { - "ClientAlias": "TestNetSidechain", + "ClientAlias": "TestNetSideChain2", "MainChainClientAlias": "TestNetMainChain", - "SidechainClientAlias": "TestNetSidechain", + "SideChainClientAlias": "TestNetSideChain2", "AccountAlias": "eanz", "CamelCase": false } diff --git a/test/AElf.Client.Abp.TestBase/appsettings.secrets.json b/test/AElf.Client.TestBase/appsettings.secrets.json similarity index 100% rename from test/AElf.Client.Abp.TestBase/appsettings.secrets.json rename to test/AElf.Client.TestBase/appsettings.secrets.json From a697e5406d970e2c22878bfe61275b5fe6a8aa87 Mon Sep 17 00:00:00 2001 From: yiqi Date: Mon, 11 Jul 2022 21:40:25 +0800 Subject: [PATCH 16/21] Improve AEDPoSViewer --- examples/AEDPoSViewer/AEDPoSViewer.csproj | 1 + examples/AEDPoSViewer/AEDPoSViewerService.cs | 69 ++++++- .../AEDPoSViewer/Data/BlockProducerMap.cs | 47 +++++ examples/AEDPoSViewer/appsettings.json | 2 +- .../AElfContractOption.cs | 9 - .../AElfGenesisConstants.cs | 6 - .../DeployContract/DeployContractService.cs | 168 ------------------ .../DeployContract/IDeployContractService.cs | 8 - .../GenesisService.Send.cs | 72 -------- .../GenesisService.View.cs | 28 --- .../IGenesisService.cs | 19 -- .../DeployContractService.cs | 2 +- .../GenesisService.View.cs | 15 +- src/AElf.Client.Genesis/IGenesisService.cs | 1 + src/AElf.Client/AElfClient.cs | 1 + test/AElf.Client.Test/BasicTests.cs | 15 ++ .../Genesis/GenesisServiceTests.cs | 11 ++ .../Token/TokenServiceTests.cs | 2 +- test/AElf.Client.TestBase/appsettings.json | 2 +- 19 files changed, 159 insertions(+), 319 deletions(-) create mode 100644 examples/AEDPoSViewer/Data/BlockProducerMap.cs delete mode 100644 src/AElf.Client.Abp.Genesis/AElfContractOption.cs delete mode 100644 src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs delete mode 100644 src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs delete mode 100644 src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs delete mode 100644 src/AElf.Client.Abp.Genesis/GenesisService.Send.cs delete mode 100644 src/AElf.Client.Abp.Genesis/GenesisService.View.cs delete mode 100644 src/AElf.Client.Abp.Genesis/IGenesisService.cs create mode 100644 test/AElf.Client.Test/BasicTests.cs diff --git a/examples/AEDPoSViewer/AEDPoSViewer.csproj b/examples/AEDPoSViewer/AEDPoSViewer.csproj index 56f9690..005dac9 100644 --- a/examples/AEDPoSViewer/AEDPoSViewer.csproj +++ b/examples/AEDPoSViewer/AEDPoSViewer.csproj @@ -18,6 +18,7 @@ + diff --git a/examples/AEDPoSViewer/AEDPoSViewerService.cs b/examples/AEDPoSViewer/AEDPoSViewerService.cs index b78e3e7..a76fd1b 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerService.cs @@ -1,11 +1,16 @@ -using AElf.Client; +using AEDPoSViewer.Data; +using AElf; using AElf.Client.Core; +using AElf.Client.Core.Options; using AElf.Contracts.Consensus.AEDPoS; +using AElf.Types; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Spectre.Console; using Volo.Abp.DependencyInjection; namespace AEDPoSViewer; @@ -24,16 +29,74 @@ public AEDPoSViewerService(IServiceScopeFactory serviceScopeFactory) } public async Task RunAsync() + { + var currentRound = await GetCurrentRoundAsync(); + for (var i = currentRound.RoundNumber - 4; i < currentRound.RoundNumber; i++) + { + DisplayRound(await GetRoundAsync(i)); + } + + DisplayRound(currentRound); + } + + private async Task GetRoundAsync(long roundNumber) + { + using var scope = ServiceScopeFactory.CreateScope(); + + var clientConfig = scope.ServiceProvider.GetRequiredService>(); + + var clientService = scope.ServiceProvider.GetRequiredService(); + + var result = await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, + "GetRoundInformation", new Int64Value { Value = roundNumber }, clientConfig.Value.ClientAlias); + + var round = new Round(); + round.MergeFrom(result); + return round; + } + + private async Task GetCurrentRoundAsync() { using var scope = ServiceScopeFactory.CreateScope(); + var clientConfig = scope.ServiceProvider.GetRequiredService>(); + var clientService = scope.ServiceProvider.GetRequiredService(); var result = await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, - "GetCurrentRoundInformation", new Empty(), EndpointType.MainNetMainChain.ToString()); + "GetCurrentRoundInformation", new Empty(), clientConfig.Value.ClientAlias); var round = new Round(); round.MergeFrom(result); - Logger.LogInformation("Current round: {Round}", round); + return round; + } + + private void DisplayRound(Round round) + { + //AnsiConsole.MarkupLine($"[blue]Term:[/]\t{round.TermNumber}"); + AnsiConsole.MarkupLine($"[blue]Round:[/]\t{round.RoundNumber}"); + //AnsiConsole.MarkupLine($"[blue]Days:[/]\t{new TimeSpan(0, 0, 0, (int)round.BlockchainAge).TotalDays}"); + + var table = new Table(); + table.AddColumn(new TableColumn(new Markup("[blue]Pubkey[/]"))); + table.AddColumn(new TableColumn("[blue]Address[/]")); + table.AddColumn(new TableColumn("[blue]Order[/]")); + table.AddColumn(new TableColumn("[blue]Produced[/]")); + table.AddColumn(new TableColumn("[blue]Missed Slots[/]")); + foreach (var info in round.RealTimeMinersInformation.OrderBy(i => i.Value.Order)) + { + var pubkey = info.Key; + var minerInRound = info.Value; + var address = Address.FromPublicKey(ByteArrayHelper.HexStringToByteArray(pubkey)).ToBase58(); + BlockProducer.Map.TryGetValue(pubkey, out var displayPubkey); + table.AddRow( + displayPubkey ?? pubkey[..10], + address, + minerInRound.Order.ToString(), + minerInRound.ActualMiningTimes.Count.ToString(), + minerInRound.MissedTimeSlots.ToString()); + } + + AnsiConsole.Write(table); } } \ No newline at end of file diff --git a/examples/AEDPoSViewer/Data/BlockProducerMap.cs b/examples/AEDPoSViewer/Data/BlockProducerMap.cs new file mode 100644 index 0000000..dcd134e --- /dev/null +++ b/examples/AEDPoSViewer/Data/BlockProducerMap.cs @@ -0,0 +1,47 @@ +namespace AEDPoSViewer.Data; + +public static class BlockProducer +{ + public static Dictionary Map; + + static BlockProducer() + { + Map = new Dictionary + { + ["048a8e7562f14207a5e9cc41163a8b947cf826bd1628fa79b4e5345e014bd3cb139617ccbb1fed60a4cdd691a238f9d30f30bf50452d5a4d9b050de73d16ccd606"] = + "FBG", + ["04f34af28e68d7c9bcfc7a9797a4d894ee9a9d3d142e275cd254b6495ed7ec95f95411c9819950c23c36fd00a2c610947487bd6e0b3e3ed8d2c90f089fa4f0c02a"] = + "RockX", + ["04d92f55aa3ea457c24836b263aca894b7aa890eb17176b8d46b17d35d5a417e491a024c8974c1bfc7b586c15f329e5d7e707f888841ba984f32dec7631efd891a"] = + "CoinHuntingCommunity", + ["04cfe24816b93a4936d564c63fd7cdcc3e77c8f26037dec96b8ab5f209b161c6567df2a317d1bb5b5494eac41d8c457ac6b8242dff9af0147beabe0ecb28ea2b79"] = + "LumosSocial", + ["0454c2e605e790e8c6e295604eeb6e169af97e25862882f44cbff19502096e29460b425e7cb50da1215b5931057fa84dd812a66a15ead46a66a9972d3e3c3fe38b"] = + "bountyblok", + ["0476d07226df54bc3f0cbbf6ab86f5c9d2324860e9e3c36db2886555d7832eed89214f73dfe8c43e7efdd7157dfbb148966944fbcb1ad0bf812b6d3350858e9104"] = + "ChainExplorers", + ["04a45c95d121c659d9f90ce7c43236f0204b87e5d180a700d6a040f2ad60a4b7cb7f22aed7e2ed7205376edcabfd2d1efb011e46e45ec94eed23cad48b794ce89e"] = + "marbleGameFI", + ["040bcbc49d65a89e49dc7152b2720f5769e6132a2c2d8742d0b7d6efb7bc1a977355f5dbd05f565e3c8848cbce8c8a0250a8a2296dc74b3d4fa0335637de5b1ec7"] = + "Genesis5", + ["04c7132a91d3b3924d1afcf99b255dde5fc0fbb437e8cb3b0d3858e9bbbf7f30e2e39e3819ebb9f034963b6a7ed3e3c12e8528cfce6210f39cf12803f89877a890"] = + "OKX", + ["042f7cab8272e1f4e90e59e91bbe2c211f1a0e15a5b670aff517a02f625d678607a96723b6ce3232fcf6ad0fc988e3e198cdedebcc10cd4d86b4dddfd8a99edcf0"] = + "aelfin", + ["04f7760c46da886f7e06e8e665cbab7d63cfe825c680dce990fcb2c3b7a01c7236e0ae40aacb32bbc4fffc57ae45bc1fe5344461efeed2b4660aef3ec3f9e35b15"] = + "HuobiPool", + ["0458ad2ec4d8944bff7f3ab7b56a90ffca784b0632bdf8c4a952da153b24b3fbbda5432f5ef293ab7ced791969f5fe02b0b5e6bc5af7ce074a9dc386c8dab0e6db"] = + "MetaDefy", + ["04e6b61a5904cfa1e242051bd71a6adba572eaf325213f41a0ae4d0139fe63627d130e6e525c3d23732ae64f3bfc8959ca4174f6aef8ea7901b4c436f5cfc81371"] = + "Genesis2", + ["04ace35149bf24792b0a4c9ea327ef44061e4a6dffa598a24be054b8068d173e0c59f4a070417b7f544057c447f27678d6aa6b531b14ee996af9728ff2fabe7f42"] = + "Genesis3", + ["04dfc5398e6c0485cb4ee98f6202f81fd49c971fa21ef9f62e309a4b983cffae9149c13cf9a8d00c10153f45855943e1ec5ca399b7143cf336cc901c457e905236"] = + "Genesis1", + ["0485bc2868f15dc6ff07ec85e3ee6f5900bb3bf3c6c50c3f40d377a203c476fdade815ab5bba1ade2eefb20de26085ab1ab84317ba07b093aa622a536f32d35682"] = + "CoinMultiDex", + ["04c1b4a75fd9ba37e0a84b9916e517e9c591c5b9efacabf1feb1a3d34f38920a250454dc9dce0f811956d210804c904959be96a75a9d9b1410aa25f7d9e1b6f69c"] = + "Genesis4", + }; + } +} \ No newline at end of file diff --git a/examples/AEDPoSViewer/appsettings.json b/examples/AEDPoSViewer/appsettings.json index e7e1db1..e7beef8 100644 --- a/examples/AEDPoSViewer/appsettings.json +++ b/examples/AEDPoSViewer/appsettings.json @@ -38,7 +38,7 @@ ] }, "AElfClientConfig": { - "ClientAlias": "TestNetMainChain", + "ClientAlias": "MainNetSideChain1", "AccountAlias": "Ean", "CamelCase": false } diff --git a/src/AElf.Client.Abp.Genesis/AElfContractOption.cs b/src/AElf.Client.Abp.Genesis/AElfContractOption.cs deleted file mode 100644 index 0a9de55..0000000 --- a/src/AElf.Client.Abp.Genesis/AElfContractOption.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace AElf.Client.Abp.Genesis; - -public class AElfContractOption -{ - public string NFTContractAddress { get; set; } - - public string GenesisContractAddress { get; set; } - public string ContractDirectory { get; set; } -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs b/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs deleted file mode 100644 index c8f7cea..0000000 --- a/src/AElf.Client.Abp.Genesis/AElfGenesisConstants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Client.Abp.Genesis; - -public class AElfGenesisConstants -{ - public const int TenSeconds = 10_000; -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs b/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs deleted file mode 100644 index 3903d4e..0000000 --- a/src/AElf.Client.Abp.Genesis/DeployContract/DeployContractService.cs +++ /dev/null @@ -1,168 +0,0 @@ -using AElf.Client.Abp.Consensus.AEDPoS; -using AElf.Client.Abp.Infrastructure; -using AElf.Client.Abp.Parliament; -using AElf.Standards.ACS0; -using AElf.Standards.ACS3; -using AElf.Types; -using Google.Protobuf; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; - -namespace AElf.Client.Abp.Genesis.DeployContract; - -public class DeployContractService : IDeployContractService, ITransientDependency -{ - private readonly IGenesisService _genesisService; - private readonly IParliamentService _parliamentService; - private readonly IConsensusService _consensusService; - - private readonly IKeyDirectoryProvider _keyDirectoryProvider; - private readonly AElfContractOption _contractOption; - - - private ILogger Logger { get; set; } - - public DeployContractService( - IGenesisService genesisService, - IConsensusService consensusService, - IParliamentService parliamentService, - IKeyDirectoryProvider keyDirectoryProvider, - IOptionsSnapshot contractOption) - { - _parliamentService = parliamentService; - _genesisService = genesisService; - _consensusService = consensusService; - _keyDirectoryProvider = keyDirectoryProvider; - _contractOption = contractOption.Value; - - Logger = NullLogger.Instance; - } - - public async Task DeployContract(string contractFileName) - { - Logger.LogInformation($"Deploy contract: {contractFileName}"); - var input = await ContractDeploymentInput(contractFileName); - var proposalNewContact = await _genesisService.ProposeNewContract(input); - Logger.LogInformation("ProposalNewContact: {Result}", proposalNewContact.TransactionResult); - if (proposalNewContact.TransactionResult.Status != TransactionResultStatus.Mined) return null; - - var proposalNewLogs = proposalNewContact.TransactionResult.Logs; - var proposalId = ProposalCreated.Parser - .ParseFrom(proposalNewLogs.First(l => l.Name.Contains(nameof(ProposalCreated))).NonIndexed) - .ProposalId; - var proposalHash = ContractProposed.Parser - .ParseFrom(proposalNewLogs.First(l => l.Name.Contains(nameof(ContractProposed))).NonIndexed) - .ProposedContractInputHash; - - var toBeRelease = await ApproveThroughMiners(proposalId); - if (!toBeRelease) return null; - var releaseApprovedInput = new ReleaseContractInput - { - ProposalId = proposalId, - ProposedContractInputHash = proposalHash - }; - var releaseApprovedContract = await _genesisService.ReleaseApprovedContract(releaseApprovedInput); - Logger.LogInformation("ReleaseApprovedContract: {Result}", releaseApprovedContract.TransactionResult); - if (releaseApprovedContract.TransactionResult.Status != TransactionResultStatus.Mined) return null; - - var releaseApprovedLogs = releaseApprovedContract.TransactionResult.Logs; - var deployProposalId = ProposalCreated.Parser - .ParseFrom(releaseApprovedLogs.First(l => l.Name.Contains(nameof(ProposalCreated))).NonIndexed) - .ProposalId; - - var releaseCodeCheckedInput = new ReleaseContractInput - { - ProposalId = deployProposalId, - ProposedContractInputHash = proposalHash - }; - - if (await CheckProposal(deployProposalId)) - { - var releaseCodeCheckedResult = await _genesisService.ReleaseCodeCheckedContract(releaseCodeCheckedInput); - Logger.LogInformation("ReleaseCodeCheckedResult: {Result}", releaseCodeCheckedResult.TransactionResult); - if (releaseCodeCheckedResult.TransactionResult.Status != TransactionResultStatus.Mined) return null; - var deployAddress = CodeUpdated.Parser.ParseFrom(releaseCodeCheckedResult.TransactionResult.Logs - .First(l => l.Name.Contains(nameof(CodeUpdated))).Indexed - .First()).Address; - Logger.LogInformation($"Contract deploy passed authority, contract address: {deployAddress}"); - return deployAddress; - } - - Logger.LogError("Contract code didn't pass the code check"); - return null; - } - - private async Task ContractDeploymentInput(string name) - { - var contractPath = GetFileFullPath(name, _contractOption.ContractDirectory); - var code = await File.ReadAllBytesAsync(contractPath); - var checkCode = await CheckCode(code); - - if (checkCode) - { - var input = new ContractDeploymentInput - { - Category = 0, - Code = ByteString.CopyFrom(code) - }; - return input; - } - - Logger.LogError("The code is already deployed."); - return new ContractDeploymentInput(); - } - - private async Task ApproveThroughMiners(Hash proposalId) - { - var miners = await _consensusService.GetCurrentMinerList(); - foreach (var minersPubkey in miners.Pubkeys) - { - var miner = Address.FromPublicKey(minersPubkey.ToByteArray()); - var approveResult = await _parliamentService.ApproveAsync(proposalId, null, miner.ToBase58()); - Logger.LogInformation("Approve: {Result}", approveResult.TransactionResult); - } - var toBeRelease = (await _parliamentService.CheckProposal(proposalId)).ToBeReleased; - return toBeRelease; - } - - private async Task CheckProposal(Hash proposalId) - { - var toBeReleased = false; - var sleepTimes = 0; - while (!toBeReleased && sleepTimes < 20) - { - await Task.Delay(AElfGenesisConstants.TenSeconds); - toBeReleased = (await _parliamentService.CheckProposal(proposalId)).ToBeReleased; - Console.Write("\rCheck proposal status"); - sleepTimes++; - } - - return toBeReleased; - } - - private string GetFileFullPath(string contractName, string contractFileDirectory) - { - var dirPath = GetDirectoryPath(contractFileDirectory); - var filePath = Path.Combine(dirPath, $"{contractName}.dll"); - var filePathWithExtension = File.Exists(filePath) - ? filePath - : Path.Combine(dirPath, $"{contractName}.dll.patched"); - return filePathWithExtension; - } - - private string GetDirectoryPath(string? configuredKeyDirectory) - { - return string.IsNullOrWhiteSpace(configuredKeyDirectory) - ? Path.Combine(_keyDirectoryProvider.GetAppDataPath(), "contracts") - : configuredKeyDirectory; - } - - private async Task CheckCode(byte[] code) - { - var hash = HashHelper.ComputeFrom(code); - var registration = await _genesisService.GetSmartContractRegistrationByCodeHash(hash); - return registration.Equals(new SmartContractRegistration()); - } -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs b/src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs deleted file mode 100644 index 35a41fd..0000000 --- a/src/AElf.Client.Abp.Genesis/DeployContract/IDeployContractService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using AElf.Types; - -namespace AElf.Client.Abp.Genesis.DeployContract; - -public interface IDeployContractService -{ - Task DeployContract(string contractFileName); -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/GenesisService.Send.cs b/src/AElf.Client.Abp.Genesis/GenesisService.Send.cs deleted file mode 100644 index 1c883ab..0000000 --- a/src/AElf.Client.Abp.Genesis/GenesisService.Send.cs +++ /dev/null @@ -1,72 +0,0 @@ -using AElf.Client.Options; -using AElf.Standards.ACS0; -using AElf.Types; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; - -namespace AElf.Client.Abp.Genesis; - -public partial class GenesisService : ContractServiceBase, IGenesisService, ITransientDependency -{ - private readonly IAElfClientService _clientService; - private readonly AElfClientConfigOptions _clientConfigOptions; - private readonly string _contractAddress; - - public GenesisService(IAElfClientService clientService, - IOptionsSnapshot clientConfigOptions, - IOptionsSnapshot contractOptions) : base(clientService, - Address.FromBase58(contractOptions.Value.GenesisContractAddress)) - { - _clientService = clientService; - _clientConfigOptions = clientConfigOptions.Value; - _contractAddress = contractOptions.Value.GenesisContractAddress; - } - - public async Task ProposeNewContract(ContractDeploymentInput contractDeploymentInput) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var tx = await _clientService.SendAsync(_contractAddress, "ProposeNewContract", contractDeploymentInput, - useClientAlias); - return new SendTransactionResult - { - Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) - }; - } - - public async Task ProposeUpdateContract(ContractUpdateInput contractUpdateInput) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var tx = await _clientService.SendAsync(_contractAddress, "ProposeUpdateContract", contractUpdateInput, - useClientAlias); - return new SendTransactionResult - { - Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) - }; - } - - public async Task ReleaseApprovedContract(ReleaseContractInput releaseContractInput) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var tx = await _clientService.SendAsync(_contractAddress, "ReleaseApprovedContract", releaseContractInput, - useClientAlias); - return new SendTransactionResult - { - Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) - }; - } - - public async Task ReleaseCodeCheckedContract(ReleaseContractInput releaseContractInput) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var tx = await _clientService.SendAsync(_contractAddress, "ReleaseCodeCheckedContract", releaseContractInput, - useClientAlias); - return new SendTransactionResult - { - Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) - }; - } -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/GenesisService.View.cs b/src/AElf.Client.Abp.Genesis/GenesisService.View.cs deleted file mode 100644 index 6ee081e..0000000 --- a/src/AElf.Client.Abp.Genesis/GenesisService.View.cs +++ /dev/null @@ -1,28 +0,0 @@ -using AElf.Types; -using Google.Protobuf; -using Google.Protobuf.WellKnownTypes; - -namespace AElf.Client.Abp.Genesis; - -public partial class GenesisService -{ - public async Task GetContractDeploymentController() - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewAsync(_contractAddress, "GetContractDeploymentController", - new Empty(), useClientAlias); - var authorityInfo = new AuthorityInfo(); - authorityInfo.MergeFrom(result); - return authorityInfo; - } - - public async Task GetSmartContractRegistrationByCodeHash(Hash codeHash) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewAsync(_contractAddress, "GetSmartContractRegistrationByCodeHash", - codeHash , useClientAlias); - var smartContractRegistration = new SmartContractRegistration(); - smartContractRegistration.MergeFrom(result); - return smartContractRegistration; - } -} \ No newline at end of file diff --git a/src/AElf.Client.Abp.Genesis/IGenesisService.cs b/src/AElf.Client.Abp.Genesis/IGenesisService.cs deleted file mode 100644 index d6aa3cd..0000000 --- a/src/AElf.Client.Abp.Genesis/IGenesisService.cs +++ /dev/null @@ -1,19 +0,0 @@ -using AElf.Standards.ACS0; -using AElf.Types; - -namespace AElf.Client.Abp.Genesis; - -public interface IGenesisService -{ - Task ProposeNewContract(ContractDeploymentInput contractDeploymentInput); - - Task ProposeUpdateContract(ContractUpdateInput contractUpdateInput); - - Task ReleaseApprovedContract(ReleaseContractInput releaseContractInput); - - Task ReleaseCodeCheckedContract(ReleaseContractInput releaseContractInput); - - - Task GetContractDeploymentController(); - Task GetSmartContractRegistrationByCodeHash(Hash codeHash); -} \ No newline at end of file diff --git a/src/AElf.Client.Genesis/DeployContractService.cs b/src/AElf.Client.Genesis/DeployContractService.cs index 2c32580..f3e252a 100644 --- a/src/AElf.Client.Genesis/DeployContractService.cs +++ b/src/AElf.Client.Genesis/DeployContractService.cs @@ -165,4 +165,4 @@ private async Task CheckCode(byte[] code) var registration = await _genesisService.GetSmartContractRegistrationByCodeHash(hash); return registration.Equals(new SmartContractRegistration()); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/AElf.Client.Genesis/GenesisService.View.cs b/src/AElf.Client.Genesis/GenesisService.View.cs index e028189..e8691ac 100644 --- a/src/AElf.Client.Genesis/GenesisService.View.cs +++ b/src/AElf.Client.Genesis/GenesisService.View.cs @@ -1,3 +1,4 @@ +using AElf.Standards.ACS0; using AElf.Types; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -10,7 +11,7 @@ public async Task GetContractDeploymentController() { var useClientAlias = _clientConfigOptions.ClientAlias; var result = await _clientService.ViewAsync(_contractAddress, "GetContractDeploymentController", - new Empty(), useClientAlias); + new Empty(), useClientAlias); var authorityInfo = new AuthorityInfo(); authorityInfo.MergeFrom(result); return authorityInfo; @@ -20,9 +21,19 @@ public async Task GetSmartContractRegistrationByCodeH { var useClientAlias = _clientConfigOptions.ClientAlias; var result = await _clientService.ViewAsync(_contractAddress, "GetSmartContractRegistrationByCodeHash", - codeHash , useClientAlias); + codeHash, useClientAlias); var smartContractRegistration = new SmartContractRegistration(); smartContractRegistration.MergeFrom(result); return smartContractRegistration; } + + public async Task GetContractInfo(Address contractAddress) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewAsync(_contractAddress, "GetContractInfo", + contractAddress, useClientAlias); + var contractInfo = new ContractInfo(); + contractInfo.MergeFrom(result); + return contractInfo; + } } \ No newline at end of file diff --git a/src/AElf.Client.Genesis/IGenesisService.cs b/src/AElf.Client.Genesis/IGenesisService.cs index eb9fc51..178c6e2 100644 --- a/src/AElf.Client.Genesis/IGenesisService.cs +++ b/src/AElf.Client.Genesis/IGenesisService.cs @@ -16,5 +16,6 @@ public interface IGenesisService Task GetContractDeploymentController(); + Task GetContractInfo(Address contractAddress); Task GetSmartContractRegistrationByCodeHash(Hash codeHash); } \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.cs b/src/AElf.Client/AElfClient.cs index b5cd922..f5cd32d 100644 --- a/src/AElf.Client/AElfClient.cs +++ b/src/AElf.Client/AElfClient.cs @@ -5,6 +5,7 @@ namespace AElf.Client; public partial class AElfClient : IDisposable { private readonly IHttpService _httpService; + // aelf node endpoint. private readonly string _baseUrl; private string? _userName; private string? _password; diff --git a/test/AElf.Client.Test/BasicTests.cs b/test/AElf.Client.Test/BasicTests.cs new file mode 100644 index 0000000..a3e3dec --- /dev/null +++ b/test/AElf.Client.Test/BasicTests.cs @@ -0,0 +1,15 @@ +using AElf.Types; +using Shouldly; + +namespace AElf.Client.Test; + +public class BasicTests +{ + [Theory] + [InlineData("04c1b4a75fd9ba37e0a84b9916e517e9c591c5b9efacabf1feb1a3d34f38920a250454dc9dce0f811956d210804c904959be96a75a9d9b1410aa25f7d9e1b6f69c")] + public void PubkeyToAddressTest(string pubkey) + { + var address = Address.FromPublicKey(ByteArrayHelper.HexStringToByteArray(pubkey)); + address.ShouldNotBeNull(); + } +} \ No newline at end of file diff --git a/test/AElf.Client.Test/Genesis/GenesisServiceTests.cs b/test/AElf.Client.Test/Genesis/GenesisServiceTests.cs index b138335..d92843b 100644 --- a/test/AElf.Client.Test/Genesis/GenesisServiceTests.cs +++ b/test/AElf.Client.Test/Genesis/GenesisServiceTests.cs @@ -1,6 +1,8 @@ +using System.Runtime.InteropServices; using System.Threading.Tasks; using AElf.Client.Genesis; using AElf.Client.Test; +using AElf.Types; using Shouldly; namespace AElf.Client.Abp.Test.Genesis; @@ -25,4 +27,13 @@ public async Task DeployContract(string contractName) var address = await _deployService.DeployContract(contractName); address.ShouldNotBeNull(); } + + [Theory] + [InlineData("UoHeeCXZ6fV481oD3NXASSexWVtsPLgv2Wthm3BGrPAgqdS5d")] + public async Task GetContractInfo(string contractAddress) + { + var address = Address.FromBase58(contractAddress); + var contractInfo = await _genesisService.GetContractInfo(address); + contractInfo.Author.ToBase58().ShouldBe("2UKQnHcQvhBT6X6ULtfnuh3b9PVRvVMEroHHkcK4YfcoH1Z1x2"); + } } \ No newline at end of file diff --git a/test/AElf.Client.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Test/Token/TokenServiceTests.cs index 83e0005..371968e 100644 --- a/test/AElf.Client.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Test/Token/TokenServiceTests.cs @@ -32,7 +32,7 @@ public async Task GetTokenInfoTest(string symbol) } [Theory] - [InlineData("2nSXrp4iM3A1gB5WKXjkwJQwy56jzcw1ESNpVnWywnyjXFixGc", "ELF", 1_00000000)] + [InlineData("HyGoexPnPnJFgqTUPaBg5TrvvbgvRdu6sPZt19WjRdXZJk2jN", "ELF", 1_00000000)] public async Task TransferTest(string address, string symbol, long amount) { var result = await _tokenService.TransferAsync(new TransferInput diff --git a/test/AElf.Client.TestBase/appsettings.json b/test/AElf.Client.TestBase/appsettings.json index d1c8eeb..c75cdc4 100644 --- a/test/AElf.Client.TestBase/appsettings.json +++ b/test/AElf.Client.TestBase/appsettings.json @@ -45,7 +45,7 @@ "AElfContract": { "ContractDirectory": "", "BridgeContractAddress": "2RHf2fxsnEaM3wb6N1yGqPupNZbcCY98LgWbGSFWmWzgEs5Sjo", - "GenesisContractAddress": "pykr77ft9UUKJZLVq15wCH8PinBSjVRQ12sD1Ayq92mKFsJ1i", + "GenesisContractAddress": "2UKQnHcQvhBT6X6ULtfnuh3b9PVRvVMEroHHkcK4YfcoH1Z1x2", "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" }, "AElfClientConfig": { From 4680c449df1e08fb810f14721299a233b493b379 Mon Sep 17 00:00:00 2001 From: yiqi Date: Tue, 9 Aug 2022 18:17:34 +0800 Subject: [PATCH 17/21] feat: Improve aedpos viewer. --- examples/AEDPoSViewer/AEDPoSViewerService.cs | 6 ++++-- examples/AEDPoSViewer/appsettings.json | 2 +- src/AElf.Client.Token/TokenService.View.cs | 2 +- src/AElf.Client/AElfClientConstants.cs | 3 ++- test/AElf.Client.Test/Token/TokenServiceTests.cs | 8 ++++++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/AEDPoSViewer/AEDPoSViewerService.cs b/examples/AEDPoSViewer/AEDPoSViewerService.cs index a76fd1b..c2c6520 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerService.cs @@ -89,11 +89,13 @@ private void DisplayRound(Round round) var minerInRound = info.Value; var address = Address.FromPublicKey(ByteArrayHelper.HexStringToByteArray(pubkey)).ToBase58(); BlockProducer.Map.TryGetValue(pubkey, out var displayPubkey); + var actualMiningTimes = minerInRound.ActualMiningTimes.Count; + var isAlarm = actualMiningTimes == 0; table.AddRow( - displayPubkey ?? pubkey[..10], + (isAlarm ? "[red]" : "") + (displayPubkey ?? pubkey[..10]) + (isAlarm ? "[/]" : ""), address, minerInRound.Order.ToString(), - minerInRound.ActualMiningTimes.Count.ToString(), + (isAlarm ? "[red]" : "") + actualMiningTimes + (isAlarm ? "[/]" : ""), minerInRound.MissedTimeSlots.ToString()); } diff --git a/examples/AEDPoSViewer/appsettings.json b/examples/AEDPoSViewer/appsettings.json index e7beef8..f0b02d7 100644 --- a/examples/AEDPoSViewer/appsettings.json +++ b/examples/AEDPoSViewer/appsettings.json @@ -38,7 +38,7 @@ ] }, "AElfClientConfig": { - "ClientAlias": "MainNetSideChain1", + "ClientAlias": "MainNetMainChain", "AccountAlias": "Ean", "CamelCase": false } diff --git a/src/AElf.Client.Token/TokenService.View.cs b/src/AElf.Client.Token/TokenService.View.cs index f3633fb..2e73ec5 100644 --- a/src/AElf.Client.Token/TokenService.View.cs +++ b/src/AElf.Client.Token/TokenService.View.cs @@ -9,7 +9,7 @@ public partial class TokenService { public async Task GetTokenInfoAsync(string symbol) { - var useClientAlias = PreferGetUseMainChainClientAlias(); + var useClientAlias = _clientConfigOptions.ClientAlias; var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetTokenInfo", new GetTokenInfoInput { diff --git a/src/AElf.Client/AElfClientConstants.cs b/src/AElf.Client/AElfClientConstants.cs index b988813..b55f7e8 100644 --- a/src/AElf.Client/AElfClientConstants.cs +++ b/src/AElf.Client/AElfClientConstants.cs @@ -10,5 +10,6 @@ public class AElfClientConstants public const string TestNetSideChain1 = "https://tdvv-test-node.aelf.io"; public const string TestNetSideChain2 = "https://tdvw-test-node.aelf.io"; public const int MainChainId = 9992731; - public const int SideChainId2 = 1866392; + public const int SideChainId1 = 1866392; + public const int SideChainId2 = 1931928; } \ No newline at end of file diff --git a/test/AElf.Client.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Test/Token/TokenServiceTests.cs index 371968e..980e195 100644 --- a/test/AElf.Client.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Test/Token/TokenServiceTests.cs @@ -7,6 +7,7 @@ using AElf.Types; using Google.Protobuf; using Shouldly; +using Xunit.Abstractions; using TransferInput = AElf.Contracts.MultiToken.TransferInput; namespace AElf.Client.Test.Token; @@ -14,21 +15,24 @@ namespace AElf.Client.Test.Token; [Trait("Category", "TokenContractService")] public sealed class TokenServiceTests : AElfClientAbpContractServiceTestBase { + private readonly ITestOutputHelper _testOutputHelper; private readonly ITokenService _tokenService; private readonly ISyncTokenInfoQueueService _syncTokenInfoQueueService; - public TokenServiceTests() + public TokenServiceTests(ITestOutputHelper testOutputHelper) { + _testOutputHelper = testOutputHelper; _tokenService = GetRequiredService(); _syncTokenInfoQueueService = GetRequiredService(); } [Theory] - [InlineData("ELF")] + [InlineData("USDT")] public async Task GetTokenInfoTest(string symbol) { var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); tokenInfo.Symbol.ShouldBe(symbol); + _testOutputHelper.WriteLine(tokenInfo.ToString()); } [Theory] From 6c3c6b63b434530dbb1b1593e23746675c6ca15b Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 31 Aug 2022 15:57:40 +0800 Subject: [PATCH 18/21] chore: Add AElf.Client.sln which only contains basic client functions. --- all.sln | 14 ++++----- .../AElf.Client.Consensus.AEDPoS.csproj | 2 +- src/AElf.Client.Core/AElf.Client.Core.csproj | 2 +- .../AElf.Client.Parliament.csproj | 2 +- src/AElf.Client.Token/ITokenService.cs | 1 + src/AElf.Client.Token/TokenService.View.cs | 11 +++++++ .../AElf.Client.Whitelist.csproj | 2 +- src/AElf.Client/AElf.Client.csproj | 4 +-- src/AElf.Client/Services/IChainAppService.cs | 1 - .../AElf.Client.Core.Test.csproj | 31 +++++++++++++++++++ .../AElfClientAbpContractServiceTestBase.cs | 0 .../AElfClientAbpContractServiceTestModule.cs | 0 .../Genesis/GenesisServiceTests.cs | 0 .../Token/TokenServiceTests.cs | 7 +++++ test/AElf.Client.Core.Test/Usings.cs | 1 + test/AElf.Client.Test/AElf.Client.Test.csproj | 3 -- test/AElf.Client.TestBase/appsettings.json | 2 +- 17 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj rename test/{AElf.Client.Test => AElf.Client.Core.Test}/AElfClientAbpContractServiceTestBase.cs (100%) rename test/{AElf.Client.Test => AElf.Client.Core.Test}/AElfClientAbpContractServiceTestModule.cs (100%) rename test/{AElf.Client.Test => AElf.Client.Core.Test}/Genesis/GenesisServiceTests.cs (100%) rename test/{AElf.Client.Test => AElf.Client.Core.Test}/Token/TokenServiceTests.cs (93%) create mode 100644 test/AElf.Client.Core.Test/Usings.cs diff --git a/all.sln b/all.sln index aaf03a4..f1b816b 100644 --- a/all.sln +++ b/all.sln @@ -46,8 +46,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TokenHolder", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TokenConverter", "src\AElf.Client.TokenConverter\AElf.Client.TokenConverter.csproj", "{B3EE451C-200D-4CC0-AEFA-1553892C825F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Whitelist", "src\AElf.Client.Whitelist\AElf.Client.Whitelist.csproj", "{478E52D9-1BA5-4852-B1CC-79D5B8382D87}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Oracle", "src\AElf.Client.Oracle\AElf.Client.Oracle.csproj", "{D1C08C5C-9F59-41A9-9A7B-788377BC2B92}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Bridge", "src\AElf.Client.Bridge\AElf.Client.Bridge.csproj", "{4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}" @@ -58,6 +56,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossChainManager", "exampl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TestBase", "test\AElf.Client.TestBase\AElf.Client.TestBase.csproj", "{D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Core.Test", "test\AElf.Client.Core.Test\AElf.Client.Core.Test.csproj", "{407B184F-466B-4C56-9EFC-99F84B7A251D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -84,12 +84,12 @@ Global {899F17C1-2FB6-418E-A9BD-5613C563365E} = {940361AC-2167-4D30-A4F6-9A543C608196} {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74} = {940361AC-2167-4D30-A4F6-9A543C608196} {B3EE451C-200D-4CC0-AEFA-1553892C825F} = {940361AC-2167-4D30-A4F6-9A543C608196} - {478E52D9-1BA5-4852-B1CC-79D5B8382D87} = {940361AC-2167-4D30-A4F6-9A543C608196} {D1C08C5C-9F59-41A9-9A7B-788377BC2B92} = {940361AC-2167-4D30-A4F6-9A543C608196} {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610} = {940361AC-2167-4D30-A4F6-9A543C608196} {F520E0B9-9EF7-4528-93FA-C182E8423F51} = {940361AC-2167-4D30-A4F6-9A543C608196} {1BC40A93-079B-48C4-B116-62C6B50C2FFC} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401} = {7CD2B508-C765-4720-B430-94E79135797A} + {407B184F-466B-4C56-9EFC-99F84B7A251D} = {7CD2B508-C765-4720-B430-94E79135797A} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -172,10 +172,6 @@ Global {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Release|Any CPU.Build.0 = Release|Any CPU - {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Debug|Any CPU.Build.0 = Debug|Any CPU - {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Release|Any CPU.ActiveCfg = Release|Any CPU - {478E52D9-1BA5-4852-B1CC-79D5B8382D87}.Release|Any CPU.Build.0 = Release|Any CPU {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Debug|Any CPU.Build.0 = Debug|Any CPU {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -196,5 +192,9 @@ Global {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.Build.0 = Debug|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.ActiveCfg = Release|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.Build.0 = Release|Any CPU + {407B184F-466B-4C56-9EFC-99F84B7A251D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {407B184F-466B-4C56-9EFC-99F84B7A251D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {407B184F-466B-4C56-9EFC-99F84B7A251D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {407B184F-466B-4C56-9EFC-99F84B7A251D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj b/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj index 2bc654f..c73bdf0 100644 --- a/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj +++ b/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Client.Core/AElf.Client.Core.csproj b/src/AElf.Client.Core/AElf.Client.Core.csproj index 39f3218..f048d05 100644 --- a/src/AElf.Client.Core/AElf.Client.Core.csproj +++ b/src/AElf.Client.Core/AElf.Client.Core.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj b/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj index 9404ce9..68353eb 100644 --- a/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj +++ b/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Client.Token/ITokenService.cs b/src/AElf.Client.Token/ITokenService.cs index 87b3c3b..f971e55 100644 --- a/src/AElf.Client.Token/ITokenService.cs +++ b/src/AElf.Client.Token/ITokenService.cs @@ -29,4 +29,5 @@ Task CrossChainReceiveTokenAsync(CrossChainReceiveTokenIn Task GetTokenInfoAsync(string symbol); Task GetTokenBalanceAsync(string symbol, Address owner); Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender); + Task GetCalculateFeeCoefficientsForSenderAsync(); } \ No newline at end of file diff --git a/src/AElf.Client.Token/TokenService.View.cs b/src/AElf.Client.Token/TokenService.View.cs index 2e73ec5..b37cb6a 100644 --- a/src/AElf.Client.Token/TokenService.View.cs +++ b/src/AElf.Client.Token/TokenService.View.cs @@ -1,6 +1,7 @@ using AElf.Contracts.MultiToken; using AElf.Types; using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Logging; namespace AElf.Client.Token; @@ -49,4 +50,14 @@ public async Task GetTokenAllowanceAsync(string symbol, Addr allowance.MergeFrom(result); return allowance; } + + public async Task GetCalculateFeeCoefficientsForSenderAsync() + { + var useClientAlias = _clientConfigOptions.ClientAlias; + var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, + "GetCalculateFeeCoefficientsForSender", new Empty(), useClientAlias); + var coefficients = new CalculateFeeCoefficients(); + coefficients.MergeFrom(result); + return coefficients; + } } \ No newline at end of file diff --git a/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj b/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj index 2bc654f..c73bdf0 100644 --- a/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj +++ b/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Client/AElf.Client.csproj b/src/AElf.Client/AElf.Client.csproj index bac79bd..0531363 100644 --- a/src/AElf.Client/AElf.Client.csproj +++ b/src/AElf.Client/AElf.Client.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/src/AElf.Client/Services/IChainAppService.cs b/src/AElf.Client/Services/IChainAppService.cs index 48d9b61..1685b1d 100644 --- a/src/AElf.Client/Services/IChainAppService.cs +++ b/src/AElf.Client/Services/IChainAppService.cs @@ -1,5 +1,4 @@ using AElf.Client.Dto; -using AElf.Kernel; namespace AElf.Client; diff --git a/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj b/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj new file mode 100644 index 0000000..63eb767 --- /dev/null +++ b/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj @@ -0,0 +1,31 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + diff --git a/test/AElf.Client.Test/AElfClientAbpContractServiceTestBase.cs b/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestBase.cs similarity index 100% rename from test/AElf.Client.Test/AElfClientAbpContractServiceTestBase.cs rename to test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestBase.cs diff --git a/test/AElf.Client.Test/AElfClientAbpContractServiceTestModule.cs b/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestModule.cs similarity index 100% rename from test/AElf.Client.Test/AElfClientAbpContractServiceTestModule.cs rename to test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestModule.cs diff --git a/test/AElf.Client.Test/Genesis/GenesisServiceTests.cs b/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs similarity index 100% rename from test/AElf.Client.Test/Genesis/GenesisServiceTests.cs rename to test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs diff --git a/test/AElf.Client.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs similarity index 93% rename from test/AElf.Client.Test/Token/TokenServiceTests.cs rename to test/AElf.Client.Core.Test/Token/TokenServiceTests.cs index 980e195..efd9652 100644 --- a/test/AElf.Client.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs @@ -103,4 +103,11 @@ await _tokenService.SwapTokenAsync(new SwapTokenInput ReceiptId = receiptId }); } + + [Fact] + public async Task GetCalculateFeeCoefficientsForSenderTest() + { + var coefficients = await _tokenService.GetCalculateFeeCoefficientsForSenderAsync(); + coefficients.FeeTokenType.ShouldBe(4); + } } \ No newline at end of file diff --git a/test/AElf.Client.Core.Test/Usings.cs b/test/AElf.Client.Core.Test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/test/AElf.Client.Core.Test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/test/AElf.Client.Test/AElf.Client.Test.csproj b/test/AElf.Client.Test/AElf.Client.Test.csproj index 6929635..647ea1f 100644 --- a/test/AElf.Client.Test/AElf.Client.Test.csproj +++ b/test/AElf.Client.Test/AElf.Client.Test.csproj @@ -26,9 +26,6 @@ - - - diff --git a/test/AElf.Client.TestBase/appsettings.json b/test/AElf.Client.TestBase/appsettings.json index c75cdc4..71acfb0 100644 --- a/test/AElf.Client.TestBase/appsettings.json +++ b/test/AElf.Client.TestBase/appsettings.json @@ -49,7 +49,7 @@ "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" }, "AElfClientConfig": { - "ClientAlias": "TestNetSideChain2", + "ClientAlias": "TestNetMainChain", "MainChainClientAlias": "TestNetMainChain", "SideChainClientAlias": "TestNetSideChain2", "AccountAlias": "eanz", From 8f5afc3e351d1babf8ca5b19f95d0ab1680758ba Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 31 Aug 2022 16:19:36 +0800 Subject: [PATCH 19/21] chore: Ignore AElf.Client.Core test cases on ci testing. --- AElf.Client.sln | 37 +++++++++++++++++++ src/AElf.Client/AElf.Client.csproj | 1 + src/AElf.Client/TransactionBuilder.cs | 11 +++--- .../Genesis/GenesisServiceTests.cs | 5 ++- .../Token/TokenServiceTests.cs | 15 ++++---- test/AElf.Client.TestBase/IgnoreOnCIFact.cs | 14 +++++++ test/AElf.Client.TestBase/IgnoreOnCITheory.cs | 14 +++++++ 7 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 AElf.Client.sln create mode 100644 test/AElf.Client.TestBase/IgnoreOnCIFact.cs create mode 100644 test/AElf.Client.TestBase/IgnoreOnCITheory.cs diff --git a/AElf.Client.sln b/AElf.Client.sln new file mode 100644 index 0000000..ce42ea6 --- /dev/null +++ b/AElf.Client.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{940361AC-2167-4D30-A4F6-9A543C608196}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7CD2B508-C765-4720-B430-94E79135797A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client", "src\AElf.Client\AElf.Client.csproj", "{1AE7844D-B4D9-4F5A-9D25-7E551B61138E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Test", "test\AElf.Client.Test\AElf.Client.Test.csproj", "{4D019C99-8B1C-42B0-8630-F1E3661F414B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Protobuf", "src\AElf.Client.Protobuf\AElf.Client.Protobuf.csproj", "{01B13EE5-9892-4D2A-8E77-C0A4A9575753}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1AE7844D-B4D9-4F5A-9D25-7E551B61138E} = {940361AC-2167-4D30-A4F6-9A543C608196} + {4D019C99-8B1C-42B0-8630-F1E3661F414B} = {7CD2B508-C765-4720-B430-94E79135797A} + {01B13EE5-9892-4D2A-8E77-C0A4A9575753} = {940361AC-2167-4D30-A4F6-9A543C608196} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Release|Any CPU.Build.0 = Release|Any CPU + {4D019C99-8B1C-42B0-8630-F1E3661F414B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D019C99-8B1C-42B0-8630-F1E3661F414B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D019C99-8B1C-42B0-8630-F1E3661F414B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D019C99-8B1C-42B0-8630-F1E3661F414B}.Release|Any CPU.Build.0 = Release|Any CPU + {01B13EE5-9892-4D2A-8E77-C0A4A9575753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {01B13EE5-9892-4D2A-8E77-C0A4A9575753}.Debug|Any CPU.Build.0 = Debug|Any CPU + {01B13EE5-9892-4D2A-8E77-C0A4A9575753}.Release|Any CPU.ActiveCfg = Release|Any CPU + {01B13EE5-9892-4D2A-8E77-C0A4A9575753}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/AElf.Client/AElf.Client.csproj b/src/AElf.Client/AElf.Client.csproj index 0531363..e6ccb5c 100644 --- a/src/AElf.Client/AElf.Client.csproj +++ b/src/AElf.Client/AElf.Client.csproj @@ -18,6 +18,7 @@ + diff --git a/src/AElf.Client/TransactionBuilder.cs b/src/AElf.Client/TransactionBuilder.cs index beb357f..2b352b6 100644 --- a/src/AElf.Client/TransactionBuilder.cs +++ b/src/AElf.Client/TransactionBuilder.cs @@ -1,5 +1,6 @@ using AElf.Cryptography; using Google.Protobuf; +using Volo.Abp.Threading; namespace AElf.Client; @@ -8,9 +9,9 @@ public class TransactionBuilder private readonly AElfClient _aelfClient; private byte[] PrivateKey { get; set; } - private string ContractAddress { get; set; } - private string MethodName { get; set; } - private IMessage Parameter { get; set; } + private string? ContractAddress { get; set; } + private string? MethodName { get; set; } + private IMessage? Parameter { get; set; } public TransactionBuilder(AElfClient aelfClient) { @@ -26,8 +27,8 @@ public TransactionBuilder UsePrivateKey(byte[] privateKey) public TransactionBuilder UseSystemContract(string systemContractName) { - ContractAddress = _aelfClient.GetContractAddressByNameAsync(HashHelper.ComputeFrom(systemContractName)).Result - .ToBase58(); + ContractAddress = AsyncHelper.RunSync(async () => + (await _aelfClient.GetContractAddressByNameAsync(HashHelper.ComputeFrom(systemContractName))).ToBase58()); return this; } diff --git a/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs b/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs index d92843b..4f9be51 100644 --- a/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs +++ b/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using AElf.Client.Genesis; using AElf.Client.Test; +using AElf.Client.TestBase; using AElf.Types; using Shouldly; @@ -20,7 +21,7 @@ public GenesisServiceTests() _deployService = GetRequiredService(); } - [Theory] + [IgnoreOnCITheory] [InlineData("AElf.Contracts.NFT")] public async Task DeployContract(string contractName) { @@ -28,7 +29,7 @@ public async Task DeployContract(string contractName) address.ShouldNotBeNull(); } - [Theory] + [IgnoreOnCITheory] [InlineData("UoHeeCXZ6fV481oD3NXASSexWVtsPLgv2Wthm3BGrPAgqdS5d")] public async Task GetContractInfo(string contractAddress) { diff --git a/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs index efd9652..28293f2 100644 --- a/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs +++ b/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using AElf.Client.TestBase; using AElf.Client.Token; using AElf.Client.Token.SyncTokenInfo; using AElf.Contracts.Bridge; @@ -26,7 +27,7 @@ public TokenServiceTests(ITestOutputHelper testOutputHelper) _syncTokenInfoQueueService = GetRequiredService(); } - [Theory] + [IgnoreOnCITheory] [InlineData("USDT")] public async Task GetTokenInfoTest(string symbol) { @@ -35,7 +36,7 @@ public async Task GetTokenInfoTest(string symbol) _testOutputHelper.WriteLine(tokenInfo.ToString()); } - [Theory] + [IgnoreOnCITheory] [InlineData("HyGoexPnPnJFgqTUPaBg5TrvvbgvRdu6sPZt19WjRdXZJk2jN", "ELF", 1_00000000)] public async Task TransferTest(string address, string symbol, long amount) { @@ -59,14 +60,14 @@ public async Task TransferTest(string address, string symbol, long amount) transferred.Amount.ShouldBe(amount); } - [Theory] + [IgnoreOnCITheory] [InlineData("BA994198147")] public async Task SyncTokenInfoTest(string symbol) { _syncTokenInfoQueueService.Enqueue(symbol); } - [Theory] + [IgnoreOnCITheory] [InlineData("CO429872652")] public async Task CrossChainCreateNFTProtocolTest(string symbol) { @@ -76,7 +77,7 @@ await _tokenService.CrossChainCreateNFTProtocolAsync(new CrossChainCreateInput }); } - [Theory] + [IgnoreOnCITheory] [InlineData("BA417054001", "JQkVTWz5HXxEmNXzTtsAVHC7EUTeiFktzoFUu9TyA6MWngkem")] public async Task AddMintersTest(string symbol, string addressBase58) { @@ -91,7 +92,7 @@ await _tokenService.AddMintersAsync(new AddMintersInput }); } - [Theory] + [IgnoreOnCITheory] [InlineData("bb16f381b0f2e795a988285dec3a68affacdccd7d3ac2e74edc808c102efcd95", 228, "9413000000000000000000")] public async Task SwapTokenTest(string swapIdHex, long receiptId, string amount) { @@ -104,7 +105,7 @@ await _tokenService.SwapTokenAsync(new SwapTokenInput }); } - [Fact] + [IgnoreOnCIFact] public async Task GetCalculateFeeCoefficientsForSenderTest() { var coefficients = await _tokenService.GetCalculateFeeCoefficientsForSenderAsync(); diff --git a/test/AElf.Client.TestBase/IgnoreOnCIFact.cs b/test/AElf.Client.TestBase/IgnoreOnCIFact.cs new file mode 100644 index 0000000..08a9df4 --- /dev/null +++ b/test/AElf.Client.TestBase/IgnoreOnCIFact.cs @@ -0,0 +1,14 @@ +namespace AElf.Client.TestBase; + +public sealed class IgnoreOnCIFact : FactAttribute +{ + public IgnoreOnCIFact() + { + if (IsOnCI()) Skip = "Ignore on CI running to save execution time."; + } + + private static bool IsOnCI() + { + return Environment.GetEnvironmentVariable("CI_TEST") != null; + } +} \ No newline at end of file diff --git a/test/AElf.Client.TestBase/IgnoreOnCITheory.cs b/test/AElf.Client.TestBase/IgnoreOnCITheory.cs new file mode 100644 index 0000000..4378f6f --- /dev/null +++ b/test/AElf.Client.TestBase/IgnoreOnCITheory.cs @@ -0,0 +1,14 @@ +namespace AElf.Client.TestBase; + +public sealed class IgnoreOnCITheory : TheoryAttribute +{ + public IgnoreOnCITheory() + { + if (IsOnCI()) Skip = "Ignore on CI running to save execution time."; + } + + private static bool IsOnCI() + { + return Environment.GetEnvironmentVariable("CI_TEST") != null; + } +} \ No newline at end of file From 9882c29d2bf5ad40ab955512ffb294460d815cdd Mon Sep 17 00:00:00 2001 From: yiqi Date: Wed, 7 Sep 2022 11:25:06 +0800 Subject: [PATCH 20/21] feat: Tune AElfContract config section. --- src/AElf.Client.Core/AElfClientModule.cs | 1 + src/AElf.Client.Core/Options/AElfContractOptions.cs | 3 +-- src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj | 3 +++ src/AElf.Client.Token/TokenService.Send.cs | 6 +++--- .../AElf.Client.Core.Test/AElf.Client.Core.Test.csproj | 1 + test/AElf.Client.TestBase/appsettings.json | 10 ++++++---- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/AElf.Client.Core/AElfClientModule.cs b/src/AElf.Client.Core/AElfClientModule.cs index f038d33..c8e4a16 100644 --- a/src/AElf.Client.Core/AElfClientModule.cs +++ b/src/AElf.Client.Core/AElfClientModule.cs @@ -18,6 +18,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) var configuration = context.Services.GetConfiguration(); Configure(options => { configuration.GetSection("AElfClient").Bind(options); }); Configure(options => { configuration.GetSection("AElfAccount").Bind(options); }); + Configure(options => { configuration.GetSection("AElfContract").Bind(options); }); Configure(options => { configuration.GetSection("AElfClientConfig").Bind(options); }); Configure(options => { configuration.GetSection("AElfMinerAccount").Bind(options); }); diff --git a/src/AElf.Client.Core/Options/AElfContractOptions.cs b/src/AElf.Client.Core/Options/AElfContractOptions.cs index 7e00bac..25f3e7a 100644 --- a/src/AElf.Client.Core/Options/AElfContractOptions.cs +++ b/src/AElf.Client.Core/Options/AElfContractOptions.cs @@ -2,7 +2,6 @@ namespace AElf.Client.Core.Options; public class AElfContractOptions { - public string NFTContractAddress { get; set; } - public string BridgeContractAddress { get; set; } + public Dictionary ContractAddressList { get; set; } public string ContractDirectory { get; set; } } \ No newline at end of file diff --git a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj index 61bd36c..c9b869f 100644 --- a/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj +++ b/src/AElf.Client.Protobuf/AElf.Client.Protobuf.csproj @@ -74,6 +74,9 @@ MSBuild:Compile + + MSBuild:Compile + diff --git a/src/AElf.Client.Token/TokenService.Send.cs b/src/AElf.Client.Token/TokenService.Send.cs index 84a3675..15cfcfc 100644 --- a/src/AElf.Client.Token/TokenService.Send.cs +++ b/src/AElf.Client.Token/TokenService.Send.cs @@ -112,7 +112,7 @@ public async Task CrossChainCreateNFTProtocolAsync( CrossChainCreateInput crossChainCreateInput) { var clientAlias = PreferGetUseSideChainClientAlias(); - ContractAddress = Address.FromBase58(_contractOptions.NFTContractAddress); + ContractAddress = Address.FromBase58(_contractOptions.ContractAddressList["NFTContract"]); var tx = await PerformSendTransactionAsync("CrossChainCreate", crossChainCreateInput, clientAlias); return new SendTransactionResult @@ -137,7 +137,7 @@ public async Task TransferAsync(TransferInput transferInp public async Task AddMintersAsync(AddMintersInput addMintersInput) { var clientAlias = _clientConfigOptions.ClientAlias; - ContractAddress = Address.FromBase58(_contractOptions.NFTContractAddress); + ContractAddress = Address.FromBase58(_contractOptions.ContractAddressList["NFTContract"]); var tx = await PerformSendTransactionAsync("AddMinters", addMintersInput, clientAlias); return new SendTransactionResult @@ -150,7 +150,7 @@ public async Task AddMintersAsync(AddMintersInput addMint public async Task SwapTokenAsync(SwapTokenInput swapTokenInput) { var clientAlias = _clientConfigOptions.ClientAlias; - ContractAddress = Address.FromBase58(_contractOptions.BridgeContractAddress); + ContractAddress = Address.FromBase58(_contractOptions.ContractAddressList["BridgeContract"]); var tx = await PerformSendTransactionAsync("SwapToken", swapTokenInput, clientAlias); var txResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias); diff --git a/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj b/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj index 63eb767..d2224fa 100644 --- a/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj +++ b/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj @@ -22,6 +22,7 @@ + diff --git a/test/AElf.Client.TestBase/appsettings.json b/test/AElf.Client.TestBase/appsettings.json index 71acfb0..ef4f6f1 100644 --- a/test/AElf.Client.TestBase/appsettings.json +++ b/test/AElf.Client.TestBase/appsettings.json @@ -44,12 +44,14 @@ }, "AElfContract": { "ContractDirectory": "", - "BridgeContractAddress": "2RHf2fxsnEaM3wb6N1yGqPupNZbcCY98LgWbGSFWmWzgEs5Sjo", - "GenesisContractAddress": "2UKQnHcQvhBT6X6ULtfnuh3b9PVRvVMEroHHkcK4YfcoH1Z1x2", - "NFTContractAddress": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" + "ContractAddressList": { + "BridgeContract": "2RHf2fxsnEaM3wb6N1yGqPupNZbcCY98LgWbGSFWmWzgEs5Sjo", + "GenesisContract": "2UKQnHcQvhBT6X6ULtfnuh3b9PVRvVMEroHHkcK4YfcoH1Z1x2", + "NFTContract": "2ZpYFeE4yWjrcKLBoj1iwbfYnbo9hK7exvfGTdqcq77QSxpzNH" + } }, "AElfClientConfig": { - "ClientAlias": "TestNetMainChain", + "ClientAlias": "MainNetSideChain1", "MainChainClientAlias": "TestNetMainChain", "SideChainClientAlias": "TestNetSideChain2", "AccountAlias": "eanz", From ae27263144403ee9280f64e26050bf1613f62d34 Mon Sep 17 00:00:00 2001 From: yiqi Date: Thu, 8 Sep 2022 12:07:47 +0800 Subject: [PATCH 21/21] feat: Optimize AElfClientService & Move contract services to examples. --- all.sln | 167 ++++-------------- examples/AEDPoSViewer/AEDPoSViewerService.cs | 19 +- .../AElf.Client.Consensus.AEDPoS.csproj | 2 +- .../AElfClientAEDPoSModule.cs | 0 .../AElfConsensusConstants.cs | 0 .../ConsensusService.Send.cs | 0 .../ConsensusService.View.cs | 7 +- .../IConsensusService.cs | 0 .../AElf.Client.CrossChain.csproj | 2 +- .../AElfClientCrossChainModule.cs | 0 .../AElfCrossChainConstants.cs | 0 .../CrossChainService.cs | 8 +- .../ICrossChainService.cs | 0 .../AElf.Client.Genesis.csproj | 2 +- .../AElfClientGenesisModule.cs | 8 +- .../DeployContractService.cs | 32 ++-- .../GenesisService.Send.cs | 37 ++-- .../GenesisService.View.cs | 29 +++ .../IDeployContractService.cs | 2 +- .../AElf.Client.Genesis/IGenesisService.cs | 0 .../AElf.Client.Parliament.csproj | 2 +- .../AElfClientParliamentModule.cs | 0 .../AElfParliamentConstants.cs | 0 .../IParliamentService.cs | 2 +- .../Options/AElfMinerAccountOptions.cs | 0 .../ParliamentService.Send.cs | 12 +- .../ParliamentService.View.cs | 23 +++ .../AElf.Client.Token.csproj | 2 +- .../AElfClientTokenModule.cs | 0 .../AElf.Client.Token/AElfTokenConstants.cs | 0 .../CrossChainTransferQueueService.cs | 0 .../CrossChainTransferService.cs | 0 .../ICrossChainTransferQueueService.cs | 0 .../ICrossChainTransferService.cs | 0 .../AElf.Client.Token/ITokenService.cs | 0 {src => examples}/AElf.Client.Token/README.md | 0 .../ISyncTokenInfoQueueService.cs | 0 .../SyncTokenInfo/ISyncTokenInfoService.cs | 0 .../SyncTokenInfoQueueService.cs | 0 .../SyncTokenInfo/SyncTokenInfoService.cs | 0 .../AElf.Client.Token/TokenService.Send.cs | 0 .../AElf.Client.Token/TokenService.View.cs | 27 +-- .../CrossChainManager.csproj | 32 ---- .../CrossChainManagerHostedService.cs | 45 ----- .../CrossChainManagerModule.cs | 19 -- .../CrossChainManagerService.cs | 27 --- examples/CrossChainManager/Program.cs | 40 ----- examples/CrossChainManager/appsettings.json | 52 ------ examples/ElectionViewer/ElectionViewer.csproj | 10 -- examples/ElectionViewer/Program.cs | 3 - examples/TokenManager/Program.cs | 40 ----- examples/TokenManager/TokenManager.csproj | 31 ---- .../TokenManager/TokenManagerConstants.cs | 7 - .../TokenManager/TokenManagerHostedService.cs | 52 ------ examples/TokenManager/TokenManagerModule.cs | 20 --- examples/TokenManager/TokenManagerService.cs | 69 -------- examples/TokenManager/TokenMangerOptions.cs | 6 - examples/TokenManager/appsettings.json | 55 ------ .../AElf.Client.Association.csproj | 9 - .../AElfClientAssociationModule.cs | 5 - .../AElf.Client.Bridge.csproj | 9 - .../AElfClientBridgeModule.cs | 5 - .../AElf.Client.Configuration.csproj | 9 - .../AElfClientConfigurationModule.cs | 5 - .../AElfClientAbpConstants.cs | 6 - .../AElfClientCoreConstants.cs | 7 + src/AElf.Client.Core/AElfClientModule.cs | 1 - .../AElfClientService.Blockchain.cs | 14 +- .../AElfClientService.Send.cs | 43 ++--- .../AElfClientService.View.cs | 37 +++- src/AElf.Client.Core/ContractServiceBase.cs | 26 +-- src/AElf.Client.Core/IAElfAccountProvider.cs | 53 +++--- src/AElf.Client.Core/IAElfClientService.cs | 59 ++++++- .../Options/AElfAccountOptions.cs | 1 + .../AElf.Client.Election.csproj | 20 --- .../AElfClientElectionModule.cs | 5 - src/AElf.Client.Genesis/AElfContractOption.cs | 9 - .../GenesisService.View.cs | 39 ---- .../AElf.Client.Oracle.csproj | 9 - .../AElfClientOracleModule.cs | 5 - src/AElf.Client.Parliament/Parliament.View.cs | 29 --- .../AElf.Client.Profit.csproj | 9 - .../AElfClientProfitModule.cs | 5 - .../AElf.Client.Referendum.csproj | 9 - .../AElfClientReferendumModule.cs | 5 - .../AElf.Client.Regiment.csproj | 9 - .../AElfClientRegimentModule.cs | 5 - .../AElf.Client.TokenConverter.csproj | 9 - .../AElfClientTokenConverterModule.cs | 5 - .../AElf.Client.TokenHolder.csproj | 9 - .../AElfClientTokenHolderModule.cs | 5 - src/AElf.Client.Vote/AElf.Client.Vote.csproj | 9 - src/AElf.Client.Vote/AElfClientVoteModule.cs | 5 - .../AElf.Client.Whitelist.csproj | 17 -- .../AElfClientWhitelistModule.cs | 13 -- .../IWhitelistService.cs | 9 - src/AElf.Client.Whitelist/WhitelistService.cs | 33 ---- src/AElf.Client/AElfClient.Chain.cs | 2 +- .../AElf.Client.Core.Test.csproj | 32 ---- .../AElfClientAbpContractServiceTestBase.cs | 9 - .../AElfClientAbpContractServiceTestModule.cs | 16 -- .../Genesis/GenesisServiceTests.cs | 40 ----- .../Token/TokenServiceTests.cs | 114 ------------ test/AElf.Client.Core.Test/Usings.cs | 1 - test/AElf.Client.TestBase/appsettings.json | 2 +- 105 files changed, 319 insertions(+), 1349 deletions(-) rename {src => examples}/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj (80%) rename {src => examples}/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs (100%) rename {src => examples}/AElf.Client.Consensus.AEDPoS/AElfConsensusConstants.cs (100%) rename {src => examples}/AElf.Client.Consensus.AEDPoS/ConsensusService.Send.cs (100%) rename {src => examples}/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs (52%) rename {src => examples}/AElf.Client.Consensus.AEDPoS/IConsensusService.cs (100%) rename {src => examples}/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj (74%) rename {src => examples}/AElf.Client.CrossChain/AElfClientCrossChainModule.cs (100%) rename {src => examples}/AElf.Client.CrossChain/AElfCrossChainConstants.cs (100%) rename {src => examples}/AElf.Client.CrossChain/CrossChainService.cs (77%) rename {src => examples}/AElf.Client.CrossChain/ICrossChainService.cs (100%) rename {src => examples}/AElf.Client.Genesis/AElf.Client.Genesis.csproj (88%) rename {src => examples}/AElf.Client.Genesis/AElfClientGenesisModule.cs (73%) rename {src => examples}/AElf.Client.Genesis/DeployContractService.cs (86%) rename {src => examples}/AElf.Client.Genesis/GenesisService.Send.cs (73%) create mode 100644 examples/AElf.Client.Genesis/GenesisService.View.cs rename {src => examples}/AElf.Client.Genesis/IDeployContractService.cs (59%) rename {src => examples}/AElf.Client.Genesis/IGenesisService.cs (100%) rename {src => examples}/AElf.Client.Parliament/AElf.Client.Parliament.csproj (82%) rename {src => examples}/AElf.Client.Parliament/AElfClientParliamentModule.cs (100%) rename {src => examples}/AElf.Client.Parliament/AElfParliamentConstants.cs (100%) rename {src => examples}/AElf.Client.Parliament/IParliamentService.cs (89%) rename {src/AElf.Client.Core => examples/AElf.Client.Parliament}/Options/AElfMinerAccountOptions.cs (100%) rename {src => examples}/AElf.Client.Parliament/ParliamentService.Send.cs (70%) create mode 100644 examples/AElf.Client.Parliament/ParliamentService.View.cs rename {src => examples}/AElf.Client.Token/AElf.Client.Token.csproj (86%) rename {src => examples}/AElf.Client.Token/AElfClientTokenModule.cs (100%) rename {src => examples}/AElf.Client.Token/AElfTokenConstants.cs (100%) rename {src => examples}/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs (100%) rename {src => examples}/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs (100%) rename {src => examples}/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs (100%) rename {src => examples}/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs (100%) rename {src => examples}/AElf.Client.Token/ITokenService.cs (100%) rename {src => examples}/AElf.Client.Token/README.md (100%) rename {src => examples}/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs (100%) rename {src => examples}/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs (100%) rename {src => examples}/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs (100%) rename {src => examples}/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs (100%) rename {src => examples}/AElf.Client.Token/TokenService.Send.cs (100%) rename {src => examples}/AElf.Client.Token/TokenService.View.cs (54%) delete mode 100644 examples/CrossChainManager/CrossChainManager.csproj delete mode 100644 examples/CrossChainManager/CrossChainManagerHostedService.cs delete mode 100644 examples/CrossChainManager/CrossChainManagerModule.cs delete mode 100644 examples/CrossChainManager/CrossChainManagerService.cs delete mode 100644 examples/CrossChainManager/Program.cs delete mode 100644 examples/CrossChainManager/appsettings.json delete mode 100644 examples/ElectionViewer/ElectionViewer.csproj delete mode 100644 examples/ElectionViewer/Program.cs delete mode 100644 examples/TokenManager/Program.cs delete mode 100644 examples/TokenManager/TokenManager.csproj delete mode 100644 examples/TokenManager/TokenManagerConstants.cs delete mode 100644 examples/TokenManager/TokenManagerHostedService.cs delete mode 100644 examples/TokenManager/TokenManagerModule.cs delete mode 100644 examples/TokenManager/TokenManagerService.cs delete mode 100644 examples/TokenManager/TokenMangerOptions.cs delete mode 100644 examples/TokenManager/appsettings.json delete mode 100644 src/AElf.Client.Association/AElf.Client.Association.csproj delete mode 100644 src/AElf.Client.Association/AElfClientAssociationModule.cs delete mode 100644 src/AElf.Client.Bridge/AElf.Client.Bridge.csproj delete mode 100644 src/AElf.Client.Bridge/AElfClientBridgeModule.cs delete mode 100644 src/AElf.Client.Configuration/AElf.Client.Configuration.csproj delete mode 100644 src/AElf.Client.Configuration/AElfClientConfigurationModule.cs delete mode 100644 src/AElf.Client.Core/AElfClientAbpConstants.cs create mode 100644 src/AElf.Client.Core/AElfClientCoreConstants.cs delete mode 100644 src/AElf.Client.Election/AElf.Client.Election.csproj delete mode 100644 src/AElf.Client.Election/AElfClientElectionModule.cs delete mode 100644 src/AElf.Client.Genesis/AElfContractOption.cs delete mode 100644 src/AElf.Client.Genesis/GenesisService.View.cs delete mode 100644 src/AElf.Client.Oracle/AElf.Client.Oracle.csproj delete mode 100644 src/AElf.Client.Oracle/AElfClientOracleModule.cs delete mode 100644 src/AElf.Client.Parliament/Parliament.View.cs delete mode 100644 src/AElf.Client.Profit/AElf.Client.Profit.csproj delete mode 100644 src/AElf.Client.Profit/AElfClientProfitModule.cs delete mode 100644 src/AElf.Client.Referendum/AElf.Client.Referendum.csproj delete mode 100644 src/AElf.Client.Referendum/AElfClientReferendumModule.cs delete mode 100644 src/AElf.Client.Regiment/AElf.Client.Regiment.csproj delete mode 100644 src/AElf.Client.Regiment/AElfClientRegimentModule.cs delete mode 100644 src/AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj delete mode 100644 src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs delete mode 100644 src/AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj delete mode 100644 src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs delete mode 100644 src/AElf.Client.Vote/AElf.Client.Vote.csproj delete mode 100644 src/AElf.Client.Vote/AElfClientVoteModule.cs delete mode 100644 src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj delete mode 100644 src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs delete mode 100644 src/AElf.Client.Whitelist/IWhitelistService.cs delete mode 100644 src/AElf.Client.Whitelist/WhitelistService.cs delete mode 100644 test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj delete mode 100644 test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestBase.cs delete mode 100644 test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestModule.cs delete mode 100644 test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs delete mode 100644 test/AElf.Client.Core.Test/Token/TokenServiceTests.cs delete mode 100644 test/AElf.Client.Core.Test/Usings.cs diff --git a/all.sln b/all.sln index f1b816b..9de7f43 100644 --- a/all.sln +++ b/all.sln @@ -10,53 +10,23 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client", "src\AElf.Cli EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Protobuf", "src\AElf.Client.Protobuf\AElf.Client.Protobuf.csproj", "{E7DF7523-2FB5-45B3-9EAA-9B759FDDC2EB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TokenManager", "examples\TokenManager\TokenManager.csproj", "{CA0B4594-2549-4DB1-9079-EA5FD739C6B6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectionViewer", "examples\ElectionViewer\ElectionViewer.csproj", "{E678AABE-AF7B-45F4-B931-CF0D77C5AECA}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AEDPoSViewer", "examples\AEDPoSViewer\AEDPoSViewer.csproj", "{BE0E29FA-A9C6-4E03-9E0C-297CCF7C5729}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Test", "test\AElf.Client.Test\AElf.Client.Test.csproj", "{4D019C99-8B1C-42B0-8630-F1E3661F414B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Core", "src\AElf.Client.Core\AElf.Client.Core.csproj", "{BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Token", "src\AElf.Client.Token\AElf.Client.Token.csproj", "{4E127996-AE35-4DCC-B4C0-057CB5B22A0E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Election", "src\AElf.Client.Election\AElf.Client.Election.csproj", "{D27E0203-23E4-4B81-A3FC-EE5034FA631E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Vote", "src\AElf.Client.Vote\AElf.Client.Vote.csproj", "{B76DF7DD-1A8A-4876-A450-5669C9B31750}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Profit", "src\AElf.Client.Profit\AElf.Client.Profit.csproj", "{BD004F96-0173-489C-BA20-6C21A7F9C538}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Association", "src\AElf.Client.Association\AElf.Client.Association.csproj", "{7B40B739-18F8-4A40-A8EF-BA2758199092}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Configuration", "src\AElf.Client.Configuration\AElf.Client.Configuration.csproj", "{E467E8FB-933C-4E2C-BC75-490B852464A8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Consensus.AEDPoS", "src\AElf.Client.Consensus.AEDPoS\AElf.Client.Consensus.AEDPoS.csproj", "{84E06902-1D71-4F8F-9071-49CAFF3B8A05}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.CrossChain", "src\AElf.Client.CrossChain\AElf.Client.CrossChain.csproj", "{6D6FE332-73A4-4F40-BE96-E720A6B83201}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Genesis", "src\AElf.Client.Genesis\AElf.Client.Genesis.csproj", "{12506F28-C416-4377-B23D-301CE0AA2E8C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Parliament", "src\AElf.Client.Parliament\AElf.Client.Parliament.csproj", "{8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Referendum", "src\AElf.Client.Referendum\AElf.Client.Referendum.csproj", "{899F17C1-2FB6-418E-A9BD-5613C563365E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TokenHolder", "src\AElf.Client.TokenHolder\AElf.Client.TokenHolder.csproj", "{7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TokenConverter", "src\AElf.Client.TokenConverter\AElf.Client.TokenConverter.csproj", "{B3EE451C-200D-4CC0-AEFA-1553892C825F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Oracle", "src\AElf.Client.Oracle\AElf.Client.Oracle.csproj", "{D1C08C5C-9F59-41A9-9A7B-788377BC2B92}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TestBase", "test\AElf.Client.TestBase\AElf.Client.TestBase.csproj", "{D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Bridge", "src\AElf.Client.Bridge\AElf.Client.Bridge.csproj", "{4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Genesis", "examples\AElf.Client.Genesis\AElf.Client.Genesis.csproj", "{A6F6AF4C-A783-4EC3-A03F-F1576020BC49}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Regiment", "src\AElf.Client.Regiment\AElf.Client.Regiment.csproj", "{F520E0B9-9EF7-4528-93FA-C182E8423F51}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Consensus.AEDPoS", "examples\AElf.Client.Consensus.AEDPoS\AElf.Client.Consensus.AEDPoS.csproj", "{46531278-7E47-4D6F-AD45-A6870E624105}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossChainManager", "examples\CrossChainManager\CrossChainManager.csproj", "{1BC40A93-079B-48C4-B116-62C6B50C2FFC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Parliament", "examples\AElf.Client.Parliament\AElf.Client.Parliament.csproj", "{12B17C25-1A00-4BB7-9911-9AC06988C261}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.TestBase", "test\AElf.Client.TestBase\AElf.Client.TestBase.csproj", "{D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Token", "examples\AElf.Client.Token\AElf.Client.Token.csproj", "{0FD6224B-4C4B-49C3-BC25-5C0B1FDBB077}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.Core.Test", "test\AElf.Client.Core.Test\AElf.Client.Core.Test.csproj", "{407B184F-466B-4C56-9EFC-99F84B7A251D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Client.CrossChain", "examples\AElf.Client.CrossChain\AElf.Client.CrossChain.csproj", "{0657BEEB-97B1-4250-9252-6685A99B5D10}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -66,30 +36,15 @@ Global GlobalSection(NestedProjects) = preSolution {1AE7844D-B4D9-4F5A-9D25-7E551B61138E} = {940361AC-2167-4D30-A4F6-9A543C608196} {E7DF7523-2FB5-45B3-9EAA-9B759FDDC2EB} = {940361AC-2167-4D30-A4F6-9A543C608196} - {CA0B4594-2549-4DB1-9079-EA5FD739C6B6} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} - {E678AABE-AF7B-45F4-B931-CF0D77C5AECA} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} {BE0E29FA-A9C6-4E03-9E0C-297CCF7C5729} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} {4D019C99-8B1C-42B0-8630-F1E3661F414B} = {7CD2B508-C765-4720-B430-94E79135797A} {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F} = {940361AC-2167-4D30-A4F6-9A543C608196} - {4E127996-AE35-4DCC-B4C0-057CB5B22A0E} = {940361AC-2167-4D30-A4F6-9A543C608196} - {D27E0203-23E4-4B81-A3FC-EE5034FA631E} = {940361AC-2167-4D30-A4F6-9A543C608196} - {B76DF7DD-1A8A-4876-A450-5669C9B31750} = {940361AC-2167-4D30-A4F6-9A543C608196} - {BD004F96-0173-489C-BA20-6C21A7F9C538} = {940361AC-2167-4D30-A4F6-9A543C608196} - {7B40B739-18F8-4A40-A8EF-BA2758199092} = {940361AC-2167-4D30-A4F6-9A543C608196} - {E467E8FB-933C-4E2C-BC75-490B852464A8} = {940361AC-2167-4D30-A4F6-9A543C608196} - {84E06902-1D71-4F8F-9071-49CAFF3B8A05} = {940361AC-2167-4D30-A4F6-9A543C608196} - {6D6FE332-73A4-4F40-BE96-E720A6B83201} = {940361AC-2167-4D30-A4F6-9A543C608196} - {12506F28-C416-4377-B23D-301CE0AA2E8C} = {940361AC-2167-4D30-A4F6-9A543C608196} - {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF} = {940361AC-2167-4D30-A4F6-9A543C608196} - {899F17C1-2FB6-418E-A9BD-5613C563365E} = {940361AC-2167-4D30-A4F6-9A543C608196} - {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74} = {940361AC-2167-4D30-A4F6-9A543C608196} - {B3EE451C-200D-4CC0-AEFA-1553892C825F} = {940361AC-2167-4D30-A4F6-9A543C608196} - {D1C08C5C-9F59-41A9-9A7B-788377BC2B92} = {940361AC-2167-4D30-A4F6-9A543C608196} - {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610} = {940361AC-2167-4D30-A4F6-9A543C608196} - {F520E0B9-9EF7-4528-93FA-C182E8423F51} = {940361AC-2167-4D30-A4F6-9A543C608196} - {1BC40A93-079B-48C4-B116-62C6B50C2FFC} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401} = {7CD2B508-C765-4720-B430-94E79135797A} - {407B184F-466B-4C56-9EFC-99F84B7A251D} = {7CD2B508-C765-4720-B430-94E79135797A} + {A6F6AF4C-A783-4EC3-A03F-F1576020BC49} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} + {46531278-7E47-4D6F-AD45-A6870E624105} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} + {12B17C25-1A00-4BB7-9911-9AC06988C261} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} + {0FD6224B-4C4B-49C3-BC25-5C0B1FDBB077} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} + {0657BEEB-97B1-4250-9252-6685A99B5D10} = {5D1BDC45-D6F1-4359-868B-CB85CEC4ABD8} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1AE7844D-B4D9-4F5A-9D25-7E551B61138E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -100,14 +55,6 @@ Global {E7DF7523-2FB5-45B3-9EAA-9B759FDDC2EB}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7DF7523-2FB5-45B3-9EAA-9B759FDDC2EB}.Release|Any CPU.ActiveCfg = Release|Any CPU {E7DF7523-2FB5-45B3-9EAA-9B759FDDC2EB}.Release|Any CPU.Build.0 = Release|Any CPU - {CA0B4594-2549-4DB1-9079-EA5FD739C6B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CA0B4594-2549-4DB1-9079-EA5FD739C6B6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CA0B4594-2549-4DB1-9079-EA5FD739C6B6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CA0B4594-2549-4DB1-9079-EA5FD739C6B6}.Release|Any CPU.Build.0 = Release|Any CPU - {E678AABE-AF7B-45F4-B931-CF0D77C5AECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E678AABE-AF7B-45F4-B931-CF0D77C5AECA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E678AABE-AF7B-45F4-B931-CF0D77C5AECA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E678AABE-AF7B-45F4-B931-CF0D77C5AECA}.Release|Any CPU.Build.0 = Release|Any CPU {BE0E29FA-A9C6-4E03-9E0C-297CCF7C5729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BE0E29FA-A9C6-4E03-9E0C-297CCF7C5729}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE0E29FA-A9C6-4E03-9E0C-297CCF7C5729}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -120,81 +67,29 @@ Global {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}.Debug|Any CPU.Build.0 = Debug|Any CPU {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}.Release|Any CPU.ActiveCfg = Release|Any CPU {BBE11EF4-5CD6-4918-8E6C-74BF61C1A87F}.Release|Any CPU.Build.0 = Release|Any CPU - {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4E127996-AE35-4DCC-B4C0-057CB5B22A0E}.Release|Any CPU.Build.0 = Release|Any CPU - {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D27E0203-23E4-4B81-A3FC-EE5034FA631E}.Release|Any CPU.Build.0 = Release|Any CPU - {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B76DF7DD-1A8A-4876-A450-5669C9B31750}.Release|Any CPU.Build.0 = Release|Any CPU - {BD004F96-0173-489C-BA20-6C21A7F9C538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BD004F96-0173-489C-BA20-6C21A7F9C538}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BD004F96-0173-489C-BA20-6C21A7F9C538}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BD004F96-0173-489C-BA20-6C21A7F9C538}.Release|Any CPU.Build.0 = Release|Any CPU - {7B40B739-18F8-4A40-A8EF-BA2758199092}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7B40B739-18F8-4A40-A8EF-BA2758199092}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7B40B739-18F8-4A40-A8EF-BA2758199092}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7B40B739-18F8-4A40-A8EF-BA2758199092}.Release|Any CPU.Build.0 = Release|Any CPU - {E467E8FB-933C-4E2C-BC75-490B852464A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E467E8FB-933C-4E2C-BC75-490B852464A8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E467E8FB-933C-4E2C-BC75-490B852464A8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E467E8FB-933C-4E2C-BC75-490B852464A8}.Release|Any CPU.Build.0 = Release|Any CPU - {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Debug|Any CPU.Build.0 = Debug|Any CPU - {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Release|Any CPU.ActiveCfg = Release|Any CPU - {84E06902-1D71-4F8F-9071-49CAFF3B8A05}.Release|Any CPU.Build.0 = Release|Any CPU - {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6D6FE332-73A4-4F40-BE96-E720A6B83201}.Release|Any CPU.Build.0 = Release|Any CPU - {12506F28-C416-4377-B23D-301CE0AA2E8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {12506F28-C416-4377-B23D-301CE0AA2E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {12506F28-C416-4377-B23D-301CE0AA2E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {12506F28-C416-4377-B23D-301CE0AA2E8C}.Release|Any CPU.Build.0 = Release|Any CPU - {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8FE45FDB-47DC-48A8-ADA6-411A30FEF7BF}.Release|Any CPU.Build.0 = Release|Any CPU - {899F17C1-2FB6-418E-A9BD-5613C563365E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {899F17C1-2FB6-418E-A9BD-5613C563365E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {899F17C1-2FB6-418E-A9BD-5613C563365E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {899F17C1-2FB6-418E-A9BD-5613C563365E}.Release|Any CPU.Build.0 = Release|Any CPU - {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7E6BBE19-D51D-4393-9BE9-1C4E5139CB74}.Release|Any CPU.Build.0 = Release|Any CPU - {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B3EE451C-200D-4CC0-AEFA-1553892C825F}.Release|Any CPU.Build.0 = Release|Any CPU - {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D1C08C5C-9F59-41A9-9A7B-788377BC2B92}.Release|Any CPU.Build.0 = Release|Any CPU - {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F9DFAC2-3F9D-4A89-94D8-5469DAD84610}.Release|Any CPU.Build.0 = Release|Any CPU - {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F520E0B9-9EF7-4528-93FA-C182E8423F51}.Release|Any CPU.Build.0 = Release|Any CPU - {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1BC40A93-079B-48C4-B116-62C6B50C2FFC}.Release|Any CPU.Build.0 = Release|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Debug|Any CPU.Build.0 = Debug|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.ActiveCfg = Release|Any CPU {D542FBDB-DFE1-46C2-8C4E-9A5643F3C401}.Release|Any CPU.Build.0 = Release|Any CPU - {407B184F-466B-4C56-9EFC-99F84B7A251D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {407B184F-466B-4C56-9EFC-99F84B7A251D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {407B184F-466B-4C56-9EFC-99F84B7A251D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {407B184F-466B-4C56-9EFC-99F84B7A251D}.Release|Any CPU.Build.0 = Release|Any CPU + {A6F6AF4C-A783-4EC3-A03F-F1576020BC49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6F6AF4C-A783-4EC3-A03F-F1576020BC49}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6F6AF4C-A783-4EC3-A03F-F1576020BC49}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6F6AF4C-A783-4EC3-A03F-F1576020BC49}.Release|Any CPU.Build.0 = Release|Any CPU + {46531278-7E47-4D6F-AD45-A6870E624105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46531278-7E47-4D6F-AD45-A6870E624105}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46531278-7E47-4D6F-AD45-A6870E624105}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46531278-7E47-4D6F-AD45-A6870E624105}.Release|Any CPU.Build.0 = Release|Any CPU + {12B17C25-1A00-4BB7-9911-9AC06988C261}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12B17C25-1A00-4BB7-9911-9AC06988C261}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12B17C25-1A00-4BB7-9911-9AC06988C261}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12B17C25-1A00-4BB7-9911-9AC06988C261}.Release|Any CPU.Build.0 = Release|Any CPU + {0FD6224B-4C4B-49C3-BC25-5C0B1FDBB077}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0FD6224B-4C4B-49C3-BC25-5C0B1FDBB077}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0FD6224B-4C4B-49C3-BC25-5C0B1FDBB077}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0FD6224B-4C4B-49C3-BC25-5C0B1FDBB077}.Release|Any CPU.Build.0 = Release|Any CPU + {0657BEEB-97B1-4250-9252-6685A99B5D10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0657BEEB-97B1-4250-9252-6685A99B5D10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0657BEEB-97B1-4250-9252-6685A99B5D10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0657BEEB-97B1-4250-9252-6685A99B5D10}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/examples/AEDPoSViewer/AEDPoSViewerService.cs b/examples/AEDPoSViewer/AEDPoSViewerService.cs index c2c6520..68e2deb 100644 --- a/examples/AEDPoSViewer/AEDPoSViewerService.cs +++ b/examples/AEDPoSViewer/AEDPoSViewerService.cs @@ -4,11 +4,8 @@ using AElf.Client.Core.Options; using AElf.Contracts.Consensus.AEDPoS; using AElf.Types; -using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Spectre.Console; using Volo.Abp.DependencyInjection; @@ -19,13 +16,9 @@ public class AEDPoSViewerService : ITransientDependency { private IServiceScopeFactory ServiceScopeFactory { get; } - public ILogger Logger { get; set; } - public AEDPoSViewerService(IServiceScopeFactory serviceScopeFactory) { ServiceScopeFactory = serviceScopeFactory; - - Logger = NullLogger.Instance; } public async Task RunAsync() @@ -47,12 +40,8 @@ private async Task GetRoundAsync(long roundNumber) var clientService = scope.ServiceProvider.GetRequiredService(); - var result = await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, + return await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, "GetRoundInformation", new Int64Value { Value = roundNumber }, clientConfig.Value.ClientAlias); - - var round = new Round(); - round.MergeFrom(result); - return round; } private async Task GetCurrentRoundAsync() @@ -63,12 +52,8 @@ private async Task GetCurrentRoundAsync() var clientService = scope.ServiceProvider.GetRequiredService(); - var result = await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, + return await clientService.ViewSystemAsync(AEDPoSViewerConstants.ConsensusSmartContractName, "GetCurrentRoundInformation", new Empty(), clientConfig.Value.ClientAlias); - - var round = new Round(); - round.MergeFrom(result); - return round; } private void DisplayRound(Round round) diff --git a/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj b/examples/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj similarity index 80% rename from src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj rename to examples/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj index c73bdf0..b1de127 100644 --- a/src/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj +++ b/examples/AElf.Client.Consensus.AEDPoS/AElf.Client.Consensus.AEDPoS.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs b/examples/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs similarity index 100% rename from src/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs rename to examples/AElf.Client.Consensus.AEDPoS/AElfClientAEDPoSModule.cs diff --git a/src/AElf.Client.Consensus.AEDPoS/AElfConsensusConstants.cs b/examples/AElf.Client.Consensus.AEDPoS/AElfConsensusConstants.cs similarity index 100% rename from src/AElf.Client.Consensus.AEDPoS/AElfConsensusConstants.cs rename to examples/AElf.Client.Consensus.AEDPoS/AElfConsensusConstants.cs diff --git a/src/AElf.Client.Consensus.AEDPoS/ConsensusService.Send.cs b/examples/AElf.Client.Consensus.AEDPoS/ConsensusService.Send.cs similarity index 100% rename from src/AElf.Client.Consensus.AEDPoS/ConsensusService.Send.cs rename to examples/AElf.Client.Consensus.AEDPoS/ConsensusService.Send.cs diff --git a/src/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs b/examples/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs similarity index 52% rename from src/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs rename to examples/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs index e2bc089..8e8cf61 100644 --- a/src/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs +++ b/examples/AElf.Client.Consensus.AEDPoS/ConsensusService.View.cs @@ -9,10 +9,7 @@ public partial class ConsensusService public async Task GetCurrentMinerList() { var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfConsensusConstants.ConsensusSmartContractName, "GetCurrentMinerList", - new Empty(), useClientAlias); - var minerList = new MinerList(); - minerList.MergeFrom(result); - return minerList; + return await _clientService.ViewSystemAsync(AElfConsensusConstants.ConsensusSmartContractName, + "GetCurrentMinerList", new Empty(), useClientAlias); } } \ No newline at end of file diff --git a/src/AElf.Client.Consensus.AEDPoS/IConsensusService.cs b/examples/AElf.Client.Consensus.AEDPoS/IConsensusService.cs similarity index 100% rename from src/AElf.Client.Consensus.AEDPoS/IConsensusService.cs rename to examples/AElf.Client.Consensus.AEDPoS/IConsensusService.cs diff --git a/src/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj b/examples/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj similarity index 74% rename from src/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj rename to examples/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj index 0d48e63..fa15dcd 100644 --- a/src/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj +++ b/examples/AElf.Client.CrossChain/AElf.Client.CrossChain.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Client.CrossChain/AElfClientCrossChainModule.cs b/examples/AElf.Client.CrossChain/AElfClientCrossChainModule.cs similarity index 100% rename from src/AElf.Client.CrossChain/AElfClientCrossChainModule.cs rename to examples/AElf.Client.CrossChain/AElfClientCrossChainModule.cs diff --git a/src/AElf.Client.CrossChain/AElfCrossChainConstants.cs b/examples/AElf.Client.CrossChain/AElfCrossChainConstants.cs similarity index 100% rename from src/AElf.Client.CrossChain/AElfCrossChainConstants.cs rename to examples/AElf.Client.CrossChain/AElfCrossChainConstants.cs diff --git a/src/AElf.Client.CrossChain/CrossChainService.cs b/examples/AElf.Client.CrossChain/CrossChainService.cs similarity index 77% rename from src/AElf.Client.CrossChain/CrossChainService.cs rename to examples/AElf.Client.CrossChain/CrossChainService.cs index 433e240..f0a4f72 100644 --- a/src/AElf.Client.CrossChain/CrossChainService.cs +++ b/examples/AElf.Client.CrossChain/CrossChainService.cs @@ -23,17 +23,15 @@ public CrossChainService(IAElfClientService clientService, public async Task GetSyncedHeightByChainId(int chainId) { var useClientAlias = _clientConfigOptions.ClientAlias; - var result = chainId == AElfClientConstants.MainChainId - ? await _clientService.ViewSystemAsync(AElfCrossChainConstants.CrossChainSmartContractName, + var height = chainId == AElfClientConstants.MainChainId + ? await _clientService.ViewSystemAsync(AElfCrossChainConstants.CrossChainSmartContractName, "GetParentChainHeight", new Empty(), useClientAlias) - : await _clientService.ViewSystemAsync(AElfCrossChainConstants.CrossChainSmartContractName, + : await _clientService.ViewSystemAsync(AElfCrossChainConstants.CrossChainSmartContractName, "GetSideChainHeight", new Int32Value { Value = chainId }, useClientAlias); - var height = new Int64Value(); - height.MergeFrom(result); return height.Value; } } \ No newline at end of file diff --git a/src/AElf.Client.CrossChain/ICrossChainService.cs b/examples/AElf.Client.CrossChain/ICrossChainService.cs similarity index 100% rename from src/AElf.Client.CrossChain/ICrossChainService.cs rename to examples/AElf.Client.CrossChain/ICrossChainService.cs diff --git a/src/AElf.Client.Genesis/AElf.Client.Genesis.csproj b/examples/AElf.Client.Genesis/AElf.Client.Genesis.csproj similarity index 88% rename from src/AElf.Client.Genesis/AElf.Client.Genesis.csproj rename to examples/AElf.Client.Genesis/AElf.Client.Genesis.csproj index faca4a2..9d89cf5 100644 --- a/src/AElf.Client.Genesis/AElf.Client.Genesis.csproj +++ b/examples/AElf.Client.Genesis/AElf.Client.Genesis.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/AElf.Client.Genesis/AElfClientGenesisModule.cs b/examples/AElf.Client.Genesis/AElfClientGenesisModule.cs similarity index 73% rename from src/AElf.Client.Genesis/AElfClientGenesisModule.cs rename to examples/AElf.Client.Genesis/AElfClientGenesisModule.cs index e41cfe1..8b33541 100644 --- a/src/AElf.Client.Genesis/AElfClientGenesisModule.cs +++ b/examples/AElf.Client.Genesis/AElfClientGenesisModule.cs @@ -1,8 +1,9 @@ using AElf.Client.Consensus.AEDPoS; using AElf.Client.Core; +using AElf.Client.Core.Options; using AElf.Client.Parliament; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; using Volo.Abp.Modularity; namespace AElf.Client.Genesis; @@ -16,9 +17,6 @@ public class AElfClientGenesisModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - Configure(configuration.GetSection("AElfContract")); - } - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { + Configure(options => { configuration.GetSection("AElfMinerAccount").Bind(options); }); } } \ No newline at end of file diff --git a/src/AElf.Client.Genesis/DeployContractService.cs b/examples/AElf.Client.Genesis/DeployContractService.cs similarity index 86% rename from src/AElf.Client.Genesis/DeployContractService.cs rename to examples/AElf.Client.Genesis/DeployContractService.cs index f3e252a..c4523f8 100644 --- a/src/AElf.Client.Genesis/DeployContractService.cs +++ b/examples/AElf.Client.Genesis/DeployContractService.cs @@ -1,5 +1,6 @@ using AElf.Client.Consensus.AEDPoS; using AElf.Client.Core.Infrastructure; +using AElf.Client.Core.Options; using AElf.Client.Parliament; using AElf.Standards.ACS0; using AElf.Standards.ACS3; @@ -19,8 +20,7 @@ public class DeployContractService : IDeployContractService, ITransientDependenc private readonly IConsensusService _consensusService; private readonly IKeyDirectoryProvider _keyDirectoryProvider; - private readonly AElfContractOption _contractOption; - + private readonly AElfContractOptions _contractOptions; private ILogger Logger { get; set; } @@ -29,21 +29,21 @@ public DeployContractService( IConsensusService consensusService, IParliamentService parliamentService, IKeyDirectoryProvider keyDirectoryProvider, - IOptionsSnapshot contractOption) + IOptionsSnapshot contractOption) { _parliamentService = parliamentService; _genesisService = genesisService; _consensusService = consensusService; _keyDirectoryProvider = keyDirectoryProvider; - _contractOption = contractOption.Value; + _contractOptions = contractOption.Value; Logger = NullLogger.Instance; } - public async Task DeployContract(string contractFileName) + public async Task DeployContractAsync(string contractFileName) { - Logger.LogInformation($"Deploy contract: {contractFileName}"); - var input = await ContractDeploymentInput(contractFileName); + Logger.LogInformation("Deploying contract: {ContractFileName}", contractFileName); + var input = await GetContractDeploymentInputAsync(contractFileName); var proposalNewContact = await _genesisService.ProposeNewContract(input); Logger.LogInformation("ProposalNewContact: {Result}", proposalNewContact.TransactionResult); if (proposalNewContact.TransactionResult.Status != TransactionResultStatus.Mined) return null; @@ -56,7 +56,7 @@ public DeployContractService( .ParseFrom(proposalNewLogs.First(l => l.Name.Contains(nameof(ContractProposed))).NonIndexed) .ProposedContractInputHash; - var toBeRelease = await ApproveThroughMiners(proposalId); + var toBeRelease = await ApproveThroughMinersAsync(proposalId); if (!toBeRelease) return null; var releaseApprovedInput = new ReleaseContractInput { @@ -78,7 +78,7 @@ public DeployContractService( ProposedContractInputHash = proposalHash }; - if (await CheckProposal(deployProposalId)) + if (await CheckProposalAsync(deployProposalId)) { var releaseCodeCheckedResult = await _genesisService.ReleaseCodeCheckedContract(releaseCodeCheckedInput); Logger.LogInformation("ReleaseCodeCheckedResult: {Result}", releaseCodeCheckedResult.TransactionResult); @@ -94,11 +94,11 @@ public DeployContractService( return null; } - private async Task ContractDeploymentInput(string name) + private async Task GetContractDeploymentInputAsync(string name) { - var contractPath = GetFileFullPath(name, _contractOption.ContractDirectory); + var contractPath = GetFileFullPath(name, _contractOptions.ContractDirectory); var code = await File.ReadAllBytesAsync(contractPath); - var checkCode = await CheckCode(code); + var checkCode = await CheckCodeAsync(code); if (checkCode) { @@ -114,20 +114,20 @@ private async Task ContractDeploymentInput(string name) return new ContractDeploymentInput(); } - private async Task ApproveThroughMiners(Hash proposalId) + private async Task ApproveThroughMinersAsync(Hash proposalId) { var miners = await _consensusService.GetCurrentMinerList(); foreach (var minersPubkey in miners.Pubkeys) { var miner = Address.FromPublicKey(minersPubkey.ToByteArray()); - var approveResult = await _parliamentService.ApproveAsync(proposalId, null, miner.ToBase58()); + var approveResult = await _parliamentService.ApproveAsync(proposalId, miner.ToBase58()); Logger.LogInformation("Approve: {Result}", approveResult.TransactionResult); } var toBeRelease = (await _parliamentService.CheckProposal(proposalId)).ToBeReleased; return toBeRelease; } - private async Task CheckProposal(Hash proposalId) + private async Task CheckProposalAsync(Hash proposalId) { var toBeReleased = false; var sleepTimes = 0; @@ -159,7 +159,7 @@ private string GetDirectoryPath(string? configuredKeyDirectory) : configuredKeyDirectory; } - private async Task CheckCode(byte[] code) + private async Task CheckCodeAsync(byte[] code) { var hash = HashHelper.ComputeFrom(code); var registration = await _genesisService.GetSmartContractRegistrationByCodeHash(hash); diff --git a/src/AElf.Client.Genesis/GenesisService.Send.cs b/examples/AElf.Client.Genesis/GenesisService.Send.cs similarity index 73% rename from src/AElf.Client.Genesis/GenesisService.Send.cs rename to examples/AElf.Client.Genesis/GenesisService.Send.cs index 2c339a9..da4bdd7 100644 --- a/src/AElf.Client.Genesis/GenesisService.Send.cs +++ b/examples/AElf.Client.Genesis/GenesisService.Send.cs @@ -1,10 +1,9 @@ using AElf.Client.Core; using AElf.Client.Core.Options; -using AElf.Client.Genesis; using AElf.Standards.ACS0; -using AElf.Types; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; +using Volo.Abp.Threading; namespace AElf.Client.Genesis; @@ -15,60 +14,60 @@ public partial class GenesisService : ContractServiceBase, IGenesisService, ITra private readonly string _contractAddress; public GenesisService(IAElfClientService clientService, - IOptionsSnapshot clientConfigOptions, - IOptionsSnapshot contractOptions) : base(clientService, - Address.FromBase58(contractOptions.Value.GenesisContractAddress)) + IOptionsSnapshot clientConfigOptions) : base(clientService, + AElfClientCoreConstants.GenesisSmartContractName) { _clientService = clientService; _clientConfigOptions = clientConfigOptions.Value; - _contractAddress = contractOptions.Value.GenesisContractAddress; + _contractAddress = AsyncHelper.RunSync(async () => + (await _clientService.GetGenesisContractAddressAsync(_clientConfigOptions.ClientAlias)).ToBase58()); } public async Task ProposeNewContract(ContractDeploymentInput contractDeploymentInput) { - var useClientAlias = _clientConfigOptions.ClientAlias; + var clientAlias = _clientConfigOptions.ClientAlias; var tx = await _clientService.SendAsync(_contractAddress, "ProposeNewContract", contractDeploymentInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task ProposeUpdateContract(ContractUpdateInput contractUpdateInput) { - var useClientAlias = _clientConfigOptions.ClientAlias; + var clientAlias = _clientConfigOptions.ClientAlias; var tx = await _clientService.SendAsync(_contractAddress, "ProposeUpdateContract", contractUpdateInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task ReleaseApprovedContract(ReleaseContractInput releaseContractInput) { - var useClientAlias = _clientConfigOptions.ClientAlias; + var clientAlias = _clientConfigOptions.ClientAlias; var tx = await _clientService.SendAsync(_contractAddress, "ReleaseApprovedContract", releaseContractInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } public async Task ReleaseCodeCheckedContract(ReleaseContractInput releaseContractInput) { - var useClientAlias = _clientConfigOptions.ClientAlias; + var clientAlias = _clientConfigOptions.ClientAlias; var tx = await _clientService.SendAsync(_contractAddress, "ReleaseCodeCheckedContract", releaseContractInput, - useClientAlias); + clientAlias); return new SendTransactionResult { Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) + TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), clientAlias) }; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/examples/AElf.Client.Genesis/GenesisService.View.cs b/examples/AElf.Client.Genesis/GenesisService.View.cs new file mode 100644 index 0000000..461c331 --- /dev/null +++ b/examples/AElf.Client.Genesis/GenesisService.View.cs @@ -0,0 +1,29 @@ +using AElf.Standards.ACS0; +using AElf.Types; +using Google.Protobuf.WellKnownTypes; + +namespace AElf.Client.Genesis; + +public partial class GenesisService +{ + public async Task GetContractDeploymentController() + { + var useClientAlias = _clientConfigOptions.ClientAlias; + return await _clientService.ViewAsync(_contractAddress, "GetContractDeploymentController", + new Empty(), useClientAlias); + } + + public async Task GetSmartContractRegistrationByCodeHash(Hash codeHash) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + return await _clientService.ViewAsync(_contractAddress, + "GetSmartContractRegistrationByCodeHash", codeHash, useClientAlias); + } + + public async Task GetContractInfo(Address contractAddress) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + return await _clientService.ViewAsync(_contractAddress, "GetContractInfo", + contractAddress, useClientAlias); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Genesis/IDeployContractService.cs b/examples/AElf.Client.Genesis/IDeployContractService.cs similarity index 59% rename from src/AElf.Client.Genesis/IDeployContractService.cs rename to examples/AElf.Client.Genesis/IDeployContractService.cs index 317164c..1a5526c 100644 --- a/src/AElf.Client.Genesis/IDeployContractService.cs +++ b/examples/AElf.Client.Genesis/IDeployContractService.cs @@ -4,5 +4,5 @@ namespace AElf.Client.Genesis; public interface IDeployContractService { - Task DeployContract(string contractFileName); + Task DeployContractAsync(string contractFileName); } \ No newline at end of file diff --git a/src/AElf.Client.Genesis/IGenesisService.cs b/examples/AElf.Client.Genesis/IGenesisService.cs similarity index 100% rename from src/AElf.Client.Genesis/IGenesisService.cs rename to examples/AElf.Client.Genesis/IGenesisService.cs diff --git a/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj b/examples/AElf.Client.Parliament/AElf.Client.Parliament.csproj similarity index 82% rename from src/AElf.Client.Parliament/AElf.Client.Parliament.csproj rename to examples/AElf.Client.Parliament/AElf.Client.Parliament.csproj index 68353eb..08725e2 100644 --- a/src/AElf.Client.Parliament/AElf.Client.Parliament.csproj +++ b/examples/AElf.Client.Parliament/AElf.Client.Parliament.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/AElf.Client.Parliament/AElfClientParliamentModule.cs b/examples/AElf.Client.Parliament/AElfClientParliamentModule.cs similarity index 100% rename from src/AElf.Client.Parliament/AElfClientParliamentModule.cs rename to examples/AElf.Client.Parliament/AElfClientParliamentModule.cs diff --git a/src/AElf.Client.Parliament/AElfParliamentConstants.cs b/examples/AElf.Client.Parliament/AElfParliamentConstants.cs similarity index 100% rename from src/AElf.Client.Parliament/AElfParliamentConstants.cs rename to examples/AElf.Client.Parliament/AElfParliamentConstants.cs diff --git a/src/AElf.Client.Parliament/IParliamentService.cs b/examples/AElf.Client.Parliament/IParliamentService.cs similarity index 89% rename from src/AElf.Client.Parliament/IParliamentService.cs rename to examples/AElf.Client.Parliament/IParliamentService.cs index 3a54b87..6676ecc 100644 --- a/src/AElf.Client.Parliament/IParliamentService.cs +++ b/examples/AElf.Client.Parliament/IParliamentService.cs @@ -7,7 +7,7 @@ namespace AElf.Client.Parliament; public interface IParliamentService { - Task ApproveAsync(Hash proposalId, string? accountAlias, string accountAddress); + Task ApproveAsync(Hash proposalId, string accountAddress); Task CheckProposal(Hash proposalId); diff --git a/src/AElf.Client.Core/Options/AElfMinerAccountOptions.cs b/examples/AElf.Client.Parliament/Options/AElfMinerAccountOptions.cs similarity index 100% rename from src/AElf.Client.Core/Options/AElfMinerAccountOptions.cs rename to examples/AElf.Client.Parliament/Options/AElfMinerAccountOptions.cs diff --git a/src/AElf.Client.Parliament/ParliamentService.Send.cs b/examples/AElf.Client.Parliament/ParliamentService.Send.cs similarity index 70% rename from src/AElf.Client.Parliament/ParliamentService.Send.cs rename to examples/AElf.Client.Parliament/ParliamentService.Send.cs index 9afd384..0bfc3ac 100644 --- a/src/AElf.Client.Parliament/ParliamentService.Send.cs +++ b/examples/AElf.Client.Parliament/ParliamentService.Send.cs @@ -1,6 +1,5 @@ using AElf.Client.Core; using AElf.Client.Core.Options; -using AElf.Standards.ACS3; using AElf.Types; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -11,19 +10,24 @@ public partial class ParliamentService : ContractServiceBase, IParliamentService { private readonly IAElfClientService _clientService; private readonly AElfClientConfigOptions _clientConfigOptions; + private readonly IAElfAccountProvider _aelfAccountProvider; - public ParliamentService(IAElfClientService clientService, IOptionsSnapshot clientConfigOptions) + public ParliamentService(IAElfClientService clientService, IAElfAccountProvider aelfAccountProvider, + IOptionsSnapshot clientConfigOptions) : base(clientService, AElfParliamentConstants.ParliamentSmartContractName) { _clientService = clientService; + _aelfAccountProvider = aelfAccountProvider; _clientConfigOptions = clientConfigOptions.Value; } - public async Task ApproveAsync(Hash proposalId, string? accountAlias, string address) + public async Task ApproveAsync(Hash proposalId, string accountAddress) { var useClientAlias = _clientConfigOptions.ClientAlias; + _aelfAccountProvider.AddAccountByDefaultPassword(accountAddress); + var accountAlias = _aelfAccountProvider.GetAliasByAddress(accountAddress); var tx = await _clientService.SendSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, "Approve", - proposalId, useClientAlias, accountAlias, address); + proposalId, useClientAlias, accountAlias); return new SendTransactionResult { Transaction = tx, diff --git a/examples/AElf.Client.Parliament/ParliamentService.View.cs b/examples/AElf.Client.Parliament/ParliamentService.View.cs new file mode 100644 index 0000000..54d0cf9 --- /dev/null +++ b/examples/AElf.Client.Parliament/ParliamentService.View.cs @@ -0,0 +1,23 @@ +using AElf.Contracts.Parliament; +using AElf.Standards.ACS3; +using AElf.Types; +using Google.Protobuf; + +namespace AElf.Client.Parliament; + +public partial class ParliamentService +{ + public async Task CheckProposal(Hash proposalId) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + return await _clientService.ViewSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, + "GetProposal", proposalId, useClientAlias); + } + + public async Task GetOrganization(Address organizationAddress) + { + var useClientAlias = _clientConfigOptions.ClientAlias; + return await _clientService.ViewSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, + "GetOrganization", organizationAddress, useClientAlias); + } +} \ No newline at end of file diff --git a/src/AElf.Client.Token/AElf.Client.Token.csproj b/examples/AElf.Client.Token/AElf.Client.Token.csproj similarity index 86% rename from src/AElf.Client.Token/AElf.Client.Token.csproj rename to examples/AElf.Client.Token/AElf.Client.Token.csproj index 4c7b7c5..13d8a42 100644 --- a/src/AElf.Client.Token/AElf.Client.Token.csproj +++ b/examples/AElf.Client.Token/AElf.Client.Token.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/AElf.Client.Token/AElfClientTokenModule.cs b/examples/AElf.Client.Token/AElfClientTokenModule.cs similarity index 100% rename from src/AElf.Client.Token/AElfClientTokenModule.cs rename to examples/AElf.Client.Token/AElfClientTokenModule.cs diff --git a/src/AElf.Client.Token/AElfTokenConstants.cs b/examples/AElf.Client.Token/AElfTokenConstants.cs similarity index 100% rename from src/AElf.Client.Token/AElfTokenConstants.cs rename to examples/AElf.Client.Token/AElfTokenConstants.cs diff --git a/src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs b/examples/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs similarity index 100% rename from src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs rename to examples/AElf.Client.Token/CrossChainTransfer/CrossChainTransferQueueService.cs diff --git a/src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs b/examples/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs similarity index 100% rename from src/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs rename to examples/AElf.Client.Token/CrossChainTransfer/CrossChainTransferService.cs diff --git a/src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs b/examples/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs similarity index 100% rename from src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs rename to examples/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferQueueService.cs diff --git a/src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs b/examples/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs similarity index 100% rename from src/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs rename to examples/AElf.Client.Token/CrossChainTransfer/ICrossChainTransferService.cs diff --git a/src/AElf.Client.Token/ITokenService.cs b/examples/AElf.Client.Token/ITokenService.cs similarity index 100% rename from src/AElf.Client.Token/ITokenService.cs rename to examples/AElf.Client.Token/ITokenService.cs diff --git a/src/AElf.Client.Token/README.md b/examples/AElf.Client.Token/README.md similarity index 100% rename from src/AElf.Client.Token/README.md rename to examples/AElf.Client.Token/README.md diff --git a/src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs b/examples/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs similarity index 100% rename from src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs rename to examples/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoQueueService.cs diff --git a/src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs b/examples/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs similarity index 100% rename from src/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs rename to examples/AElf.Client.Token/SyncTokenInfo/ISyncTokenInfoService.cs diff --git a/src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs b/examples/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs similarity index 100% rename from src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs rename to examples/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoQueueService.cs diff --git a/src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs b/examples/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs similarity index 100% rename from src/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs rename to examples/AElf.Client.Token/SyncTokenInfo/SyncTokenInfoService.cs diff --git a/src/AElf.Client.Token/TokenService.Send.cs b/examples/AElf.Client.Token/TokenService.Send.cs similarity index 100% rename from src/AElf.Client.Token/TokenService.Send.cs rename to examples/AElf.Client.Token/TokenService.Send.cs diff --git a/src/AElf.Client.Token/TokenService.View.cs b/examples/AElf.Client.Token/TokenService.View.cs similarity index 54% rename from src/AElf.Client.Token/TokenService.View.cs rename to examples/AElf.Client.Token/TokenService.View.cs index b37cb6a..a98257b 100644 --- a/src/AElf.Client.Token/TokenService.View.cs +++ b/examples/AElf.Client.Token/TokenService.View.cs @@ -11,53 +11,40 @@ public partial class TokenService public async Task GetTokenInfoAsync(string symbol) { var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetTokenInfo", - new GetTokenInfoInput + return await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, + "GetTokenInfo", new GetTokenInfoInput { Symbol = symbol }, useClientAlias); - var tokenInfo = new TokenInfo(); - tokenInfo.MergeFrom(result); - return tokenInfo; } public async Task GetTokenBalanceAsync(string symbol, Address owner) { var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetBalance", - new GetBalanceInput + return await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, + "GetBalance", new GetBalanceInput { Owner = owner, Symbol = symbol }, useClientAlias); - var balance = new GetBalanceOutput(); - balance.MergeFrom(result); - Logger.LogInformation("{Address} {Symbol} {Balance}", owner, symbol, balance.Balance); - return balance; } public async Task GetTokenAllowanceAsync(string symbol, Address owner, Address spender) { var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetAllowance", - new GetAllowanceInput + return await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, + "GetAllowance", new GetAllowanceInput { Owner = owner, Spender = spender, Symbol = symbol }, useClientAlias); - var allowance = new GetAllowanceOutput(); - allowance.MergeFrom(result); - return allowance; } public async Task GetCalculateFeeCoefficientsForSenderAsync() { var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, + return await _clientService.ViewSystemAsync(AElfTokenConstants.TokenSmartContractName, "GetCalculateFeeCoefficientsForSender", new Empty(), useClientAlias); - var coefficients = new CalculateFeeCoefficients(); - coefficients.MergeFrom(result); - return coefficients; } } \ No newline at end of file diff --git a/examples/CrossChainManager/CrossChainManager.csproj b/examples/CrossChainManager/CrossChainManager.csproj deleted file mode 100644 index b0fdbcd..0000000 --- a/examples/CrossChainManager/CrossChainManager.csproj +++ /dev/null @@ -1,32 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - - - - - - - - - - - - PreserveNewest - Always - - - - diff --git a/examples/CrossChainManager/CrossChainManagerHostedService.cs b/examples/CrossChainManager/CrossChainManagerHostedService.cs deleted file mode 100644 index 20bef82..0000000 --- a/examples/CrossChainManager/CrossChainManagerHostedService.cs +++ /dev/null @@ -1,45 +0,0 @@ -using AElf.Client; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Serilog; -using TokenManager; -using Volo.Abp; - -namespace CrossChainManager; - -public class CrossChainManagerHostedService : IHostedService -{ - private IAbpApplicationWithInternalServiceProvider _abpApplication; - - private readonly IConfiguration _configuration; - private readonly IHostEnvironment _hostEnvironment; - - public CrossChainManagerHostedService(IConfiguration configuration, IHostEnvironment hostEnvironment) - { - _configuration = configuration; - _hostEnvironment = hostEnvironment; - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - _abpApplication = await AbpApplicationFactory.CreateAsync(options => - { - options.Services.ReplaceConfiguration(_configuration); - options.Services.AddSingleton(_hostEnvironment); - - options.UseAutofac(); - options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog()); - }); - - await _abpApplication.InitializeAsync(); - - var crossChainManagerService = _abpApplication.ServiceProvider.GetRequiredService(); - await crossChainManagerService.GetSyncedHeightByChainId(AElfClientConstants.MainChainId); - } - - public async Task StopAsync(CancellationToken cancellationToken) - { - await _abpApplication.ShutdownAsync(); - } -} \ No newline at end of file diff --git a/examples/CrossChainManager/CrossChainManagerModule.cs b/examples/CrossChainManager/CrossChainManagerModule.cs deleted file mode 100644 index f1d1a5c..0000000 --- a/examples/CrossChainManager/CrossChainManagerModule.cs +++ /dev/null @@ -1,19 +0,0 @@ -using AElf.Client.Core; -using AElf.Client.CrossChain; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.Modularity; - -namespace TokenManager; - -[DependsOn( - typeof(AElfClientModule), - typeof(AElfClientCrossChainModule) -)] -public class CrossChainManagerModule : AbpModule -{ - public override void ConfigureServices(ServiceConfigurationContext context) - { - var configuration = context.Services.GetConfiguration(); - } -} \ No newline at end of file diff --git a/examples/CrossChainManager/CrossChainManagerService.cs b/examples/CrossChainManager/CrossChainManagerService.cs deleted file mode 100644 index be20e27..0000000 --- a/examples/CrossChainManager/CrossChainManagerService.cs +++ /dev/null @@ -1,27 +0,0 @@ -using AElf.Client.CrossChain; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Volo.Abp.DependencyInjection; - -namespace CrossChainManager; - -public class CrossChainManagerService : ITransientDependency -{ - private readonly ICrossChainService _crossChainService; - private IServiceScopeFactory ServiceScopeFactory { get; } - - public ILogger Logger { get; set; } - - public CrossChainManagerService(ICrossChainService crossChainService, IServiceScopeFactory serviceScopeFactory) - { - _crossChainService = crossChainService; - ServiceScopeFactory = serviceScopeFactory; - } - - public async Task GetSyncedHeightByChainId(int chainId) - { - var height = await _crossChainService.GetSyncedHeightByChainId(chainId); - Logger.LogInformation("Synced height of chain id {ChainId}: {Height}", chainId, height); - return height; - } -} \ No newline at end of file diff --git a/examples/CrossChainManager/Program.cs b/examples/CrossChainManager/Program.cs deleted file mode 100644 index 97073af..0000000 --- a/examples/CrossChainManager/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CrossChainManager; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; - -Log.Logger = new LoggerConfiguration() - .MinimumLevel.Information() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning) -#if DEBUG - .MinimumLevel.Override("CrossChainManager", LogEventLevel.Debug) -#else - .MinimumLevel.Override("CrossChainManager", LogEventLevel.Information) -#endif - .Enrich.FromLogContext() - .WriteTo.Async(c => c.File($"Logs/aelf-cross-chain-manager-{DateTime.UtcNow:yyyy-MM-dd}.logs")) - .WriteTo.Async(c => c.Console()) - .CreateLogger(); - -try -{ - await Host.CreateDefaultBuilder(args) - .ConfigureServices(services => - { - services.AddHostedService(); - }) - .UseSerilog() - .RunConsoleAsync(); - return 0; -} -catch (Exception ex) -{ - Log.Fatal(ex, "Host terminated unexpectedly!"); - return 1; -} -finally -{ - Log.CloseAndFlush(); -} \ No newline at end of file diff --git a/examples/CrossChainManager/appsettings.json b/examples/CrossChainManager/appsettings.json deleted file mode 100644 index f4f09ae..0000000 --- a/examples/CrossChainManager/appsettings.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - }, - "AElfClient": { - "ClientConfigList": [ - { - "Alias": "Example", - "Endpoint": "http://192.168.0.31:6800", - "UserName": "", - "Password": "", - "Timeout": 100 - } - ] - }, - "AElfAccount": { - "KeyDirectory": "", - "AccountConfigList": [ - { - "Alias": "Ean", - "PrivateKey": "8cc296e44d9e8881942e75a21ebc116ed3f29e39e0eaace1c92dc21e86d215c3", - "Address": "2AiXjNszZwUMdonm2RYb3GsB3aLUU3hkD1fxoazMwqPAamerLQ", - "Password": "aelftest" - }, - { - "Alias": "Test1", - "Address": "215tht8WyakoxNK4SvsR132jChydxE27RtJN8HSk1UXxuDQnmM", - "Password": "aelftest" - }, - { - "Alias": "Test2", - "PrivateKey": "5e2f12d13e4527ad1128e07db00f1614ec6b8b51662e68d4fdb42125ab384195", - }, - { - "Alias": "eanz", - "Address": "2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT", - "Password": "zhaoyiqi" - } - ] - }, - "AElfClientConfig": { - "ClientAlias": "TestNetSideChain", - "MainChainClientAlias": "TestNetMainChain", - "SideChainClientAlias": "TestNetSideChain", - "AccountAlias": "eanz", - "CamelCase": false - } -} \ No newline at end of file diff --git a/examples/ElectionViewer/ElectionViewer.csproj b/examples/ElectionViewer/ElectionViewer.csproj deleted file mode 100644 index b9de063..0000000 --- a/examples/ElectionViewer/ElectionViewer.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - diff --git a/examples/ElectionViewer/Program.cs b/examples/ElectionViewer/Program.cs deleted file mode 100644 index e5dff12..0000000 --- a/examples/ElectionViewer/Program.cs +++ /dev/null @@ -1,3 +0,0 @@ -// See https://aka.ms/new-console-template for more information - -Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/examples/TokenManager/Program.cs b/examples/TokenManager/Program.cs deleted file mode 100644 index dae78b0..0000000 --- a/examples/TokenManager/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; -using TokenManager; - -Log.Logger = new LoggerConfiguration() - .MinimumLevel.Information() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning) -#if DEBUG - .MinimumLevel.Override("TokenManager", LogEventLevel.Debug) -#else - .MinimumLevel.Override("TokenManager", LogEventLevel.Information) -#endif - .Enrich.FromLogContext() - .WriteTo.Async(c => c.File($"Logs/aelf-token-manager-{DateTime.UtcNow:yyyy-MM-dd}.logs")) - .WriteTo.Async(c => c.Console()) - .CreateLogger(); - -try -{ - await Host.CreateDefaultBuilder(args) - .ConfigureServices(services => - { - services.AddHostedService(); - }) - .UseSerilog() - .RunConsoleAsync(); - return 0; -} -catch (Exception ex) -{ - Log.Fatal(ex, "Host terminated unexpectedly!"); - return 1; -} -finally -{ - Log.CloseAndFlush(); -} \ No newline at end of file diff --git a/examples/TokenManager/TokenManager.csproj b/examples/TokenManager/TokenManager.csproj deleted file mode 100644 index d8fa27a..0000000 --- a/examples/TokenManager/TokenManager.csproj +++ /dev/null @@ -1,31 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - - - - - - - - - - - PreserveNewest - Always - - - - diff --git a/examples/TokenManager/TokenManagerConstants.cs b/examples/TokenManager/TokenManagerConstants.cs deleted file mode 100644 index bf2ab06..0000000 --- a/examples/TokenManager/TokenManagerConstants.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace TokenManager; - -public class TokenManagerConstants -{ - public const string TokenSmartContractName = "AElf.ContractNames.Token"; - public const string NativeTokenSymbol = "ELF"; -} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerHostedService.cs b/examples/TokenManager/TokenManagerHostedService.cs deleted file mode 100644 index be3f260..0000000 --- a/examples/TokenManager/TokenManagerHostedService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using AElf.Client; -using AElf.Types; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Serilog; -using Volo.Abp; - -namespace TokenManager; - -public class TokenManagerHostedService : IHostedService -{ - private IAbpApplicationWithInternalServiceProvider _abpApplication; - - private readonly IConfiguration _configuration; - private readonly IHostEnvironment _hostEnvironment; - - public TokenManagerHostedService(IConfiguration configuration, IHostEnvironment hostEnvironment) - { - _configuration = configuration; - _hostEnvironment = hostEnvironment; - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - _abpApplication = await AbpApplicationFactory.CreateAsync(options => - { - options.Services.ReplaceConfiguration(_configuration); - options.Services.AddSingleton(_hostEnvironment); - - options.UseAutofac(); - options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog()); - }); - - await _abpApplication.InitializeAsync(); - - var tokenManagerService = _abpApplication.ServiceProvider.GetRequiredService(); - // await tokenManagerService.TransferAsync(Address.FromBase58("eyDPrhJdofZ9f7Qdyi8FtbA8BePubP1M3gwfVMs6MnMHHNwik"), - // "ELF", 10000_00000000); -/* - await tokenManagerService.CrossChainTransferAsync( - Address.FromBase58("2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT"), "ELF", 100000_00000000, - EndpointType.TestNetSideChain2.ToString()); - */ - await tokenManagerService.GetTokenInfoAsync("ELF"); - } - - public async Task StopAsync(CancellationToken cancellationToken) - { - await _abpApplication.ShutdownAsync(); - } -} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerModule.cs b/examples/TokenManager/TokenManagerModule.cs deleted file mode 100644 index 109ea9a..0000000 --- a/examples/TokenManager/TokenManagerModule.cs +++ /dev/null @@ -1,20 +0,0 @@ -using AElf.Client.Core; -using AElf.Client.Token; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.Modularity; - -namespace TokenManager; - -[DependsOn( - typeof(AElfClientModule), - typeof(AElfClientTokenModule) -)] -public class TokenManagerModule : AbpModule -{ - public override void ConfigureServices(ServiceConfigurationContext context) - { - var configuration = context.Services.GetConfiguration(); - Configure(options => { configuration.GetSection("TokenManager").Bind(options); }); - } -} \ No newline at end of file diff --git a/examples/TokenManager/TokenManagerService.cs b/examples/TokenManager/TokenManagerService.cs deleted file mode 100644 index e468e97..0000000 --- a/examples/TokenManager/TokenManagerService.cs +++ /dev/null @@ -1,69 +0,0 @@ -using AElf.Client; -using AElf.Client.Token; -using AElf.Client.Token.CrossChainTransfer; -using AElf.Client.Token.SyncTokenInfo; -using AElf.Contracts.MultiToken; -using AElf.Types; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Volo.Abp.DependencyInjection; - -namespace TokenManager; - -public class TokenManagerService : ITransientDependency -{ - private readonly ITokenService _tokenService; - private readonly ISyncTokenInfoQueueService _syncTokenInfoQueueService; - private readonly ICrossChainTransferQueueService _crossChainTransferQueueService; - private IServiceScopeFactory ServiceScopeFactory { get; } - - public ILogger Logger { get; set; } - - public TokenManagerService(IServiceScopeFactory serviceScopeFactory, - ITokenService tokenService, - ISyncTokenInfoQueueService syncTokenInfoQueueService, - ICrossChainTransferQueueService crossChainTransferQueueService) - { - _tokenService = tokenService; - _syncTokenInfoQueueService = syncTokenInfoQueueService; - _crossChainTransferQueueService = crossChainTransferQueueService; - ServiceScopeFactory = serviceScopeFactory; - - Logger = NullLogger.Instance; - } - - public async Task GetTokenInfoAsync(string symbol) - { - var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); - Logger.LogInformation("{TokenInfo}", tokenInfo.ToString()); - } - - public async Task SyncTokenInfoAsync(string symbol) - { - _syncTokenInfoQueueService.Enqueue(symbol); - Logger.LogInformation("Enqueued SyncTokenInfo"); - } - - public async Task CrossChainTransferAsync(Address to, string symbol, long amount, string toClientAlias) - { - _crossChainTransferQueueService.Enqueue( - to, symbol, amount, EndpointType.TestNetMainChain.ToString(), toClientAlias); - Logger.LogInformation("Enqueued CrossChainTransfer"); - } - - public async Task TransferAsync(Address to, string symbol, long amount) - { - await _tokenService.TransferAsync(new TransferInput - { - To = to, - Symbol = symbol, - Amount = amount, - }); - } - - public async Task GetBalanceAsync(Address owner, string symbol) - { - return (await _tokenService.GetTokenBalanceAsync(symbol, owner)).Balance; - } -} \ No newline at end of file diff --git a/examples/TokenManager/TokenMangerOptions.cs b/examples/TokenManager/TokenMangerOptions.cs deleted file mode 100644 index 67da3ec..0000000 --- a/examples/TokenManager/TokenMangerOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TokenManager; - -public class TokenManagerOptions -{ - public string NFTContractAddress { get; set; } -} \ No newline at end of file diff --git a/examples/TokenManager/appsettings.json b/examples/TokenManager/appsettings.json deleted file mode 100644 index 004dab3..0000000 --- a/examples/TokenManager/appsettings.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - }, - "AElfClient": { - "ClientConfigList": [ - { - "Alias": "Example", - "Endpoint": "http://192.168.0.31:6800", - "UserName": "", - "Password": "", - "Timeout": 100 - } - ] - }, - "AElfAccount": { - "KeyDirectory": "", - "AccountConfigList": [ - { - "Alias": "Ean", - "PrivateKey": "8cc296e44d9e8881942e75a21ebc116ed3f29e39e0eaace1c92dc21e86d215c3", - "Address": "2AiXjNszZwUMdonm2RYb3GsB3aLUU3hkD1fxoazMwqPAamerLQ", - "Password": "aelftest" - }, - { - "Alias": "Test1", - "Address": "215tht8WyakoxNK4SvsR132jChydxE27RtJN8HSk1UXxuDQnmM", - "Password": "aelftest" - }, - { - "Alias": "Test2", - "PrivateKey": "5e2f12d13e4527ad1128e07db00f1614ec6b8b51662e68d4fdb42125ab384195", - }, - { - "Alias": "eanz", - "Address": "2HeW7S9HZrbRJZeivMppUuUY3djhWdfVnP5zrDsz8wqq6hKMfT", - "Password": "zhaoyiqi" - } - ] - }, - "AElfContract": { - "NFTContractAddress": "" - }, - "AElfClientConfig": { - "ClientAlias": "TestNetSideChain", - "MainChainClientAlias": "TestNetMainChain", - "SideChainClientAlias": "TestNetSideChain", - "AccountAlias": "eanz", - "CamelCase": false - } -} \ No newline at end of file diff --git a/src/AElf.Client.Association/AElf.Client.Association.csproj b/src/AElf.Client.Association/AElf.Client.Association.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Association/AElf.Client.Association.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Association/AElfClientAssociationModule.cs b/src/AElf.Client.Association/AElfClientAssociationModule.cs deleted file mode 100644 index ed933d7..0000000 --- a/src/AElf.Client.Association/AElfClientAssociationModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Association; - -public class AElfClientAssociationModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Bridge/AElf.Client.Bridge.csproj b/src/AElf.Client.Bridge/AElf.Client.Bridge.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Bridge/AElf.Client.Bridge.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Bridge/AElfClientBridgeModule.cs b/src/AElf.Client.Bridge/AElfClientBridgeModule.cs deleted file mode 100644 index e8d08a9..0000000 --- a/src/AElf.Client.Bridge/AElfClientBridgeModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Bridge; - -public class AElfClientBridgeModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Configuration/AElf.Client.Configuration.csproj b/src/AElf.Client.Configuration/AElf.Client.Configuration.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Configuration/AElf.Client.Configuration.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Configuration/AElfClientConfigurationModule.cs b/src/AElf.Client.Configuration/AElfClientConfigurationModule.cs deleted file mode 100644 index 5564be6..0000000 --- a/src/AElf.Client.Configuration/AElfClientConfigurationModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Configuration; - -public class AElfClientConfigurationModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Core/AElfClientAbpConstants.cs b/src/AElf.Client.Core/AElfClientAbpConstants.cs deleted file mode 100644 index 2db31b0..0000000 --- a/src/AElf.Client.Core/AElfClientAbpConstants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Client.Core; - -public class AElfClientAbpConstants -{ - public const int DefaultWaitMilliseconds = 100; -} \ No newline at end of file diff --git a/src/AElf.Client.Core/AElfClientCoreConstants.cs b/src/AElf.Client.Core/AElfClientCoreConstants.cs new file mode 100644 index 0000000..a090699 --- /dev/null +++ b/src/AElf.Client.Core/AElfClientCoreConstants.cs @@ -0,0 +1,7 @@ +namespace AElf.Client.Core; + +public class AElfClientCoreConstants +{ + public const int DefaultWaitMilliseconds = 100; + public const string GenesisSmartContractName = "AElf.ContractNames.Genesis"; +} \ No newline at end of file diff --git a/src/AElf.Client.Core/AElfClientModule.cs b/src/AElf.Client.Core/AElfClientModule.cs index c8e4a16..700356e 100644 --- a/src/AElf.Client.Core/AElfClientModule.cs +++ b/src/AElf.Client.Core/AElfClientModule.cs @@ -20,7 +20,6 @@ public override void ConfigureServices(ServiceConfigurationContext context) Configure(options => { configuration.GetSection("AElfAccount").Bind(options); }); Configure(options => { configuration.GetSection("AElfContract").Bind(options); }); Configure(options => { configuration.GetSection("AElfClientConfig").Bind(options); }); - Configure(options => { configuration.GetSection("AElfMinerAccount").Bind(options); }); context.Services.AddAutoMapperObjectMapper(); diff --git a/src/AElf.Client.Core/AElfClientService.Blockchain.cs b/src/AElf.Client.Core/AElfClientService.Blockchain.cs index 7aa6d24..5256706 100644 --- a/src/AElf.Client.Core/AElfClientService.Blockchain.cs +++ b/src/AElf.Client.Core/AElfClientService.Blockchain.cs @@ -1,4 +1,6 @@ using AElf.Client.Dto; +using Google.Protobuf; +using Google.Protobuf.Reflection; using Microsoft.Extensions.Logging; namespace AElf.Client.Core; @@ -23,7 +25,7 @@ public async Task GetTransactionResultAsync(string transactio break; } - await Task.Delay(AElfClientAbpConstants.DefaultWaitMilliseconds); + await Task.Delay(AElfClientCoreConstants.DefaultWaitMilliseconds); result = await aelfClient.GetTransactionResultAsync(transactionId); i++; } @@ -44,8 +46,18 @@ public async Task GetMerklePathByTransactionIdAsync(string transacti if (merklePathDto == null) { Logger.LogError("Cannot get merkle path of transaction {TransactionId}", transactionId); + merklePathDto = new MerklePathDto(); } return _objectMapper.Map(merklePathDto); } + + public async Task GetContractFileDescriptorSetAsync(string contractAddress, string clientAlias) + { + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); + var result = await aelfClient.GetContractFileDescriptorSetAsync(contractAddress); + var fileDescriptorSet = new FileDescriptorSet(); + fileDescriptorSet.MergeFrom(result); + return fileDescriptorSet; + } } \ No newline at end of file diff --git a/src/AElf.Client.Core/AElfClientService.Send.cs b/src/AElf.Client.Core/AElfClientService.Send.cs index bed5e98..6cd9395 100644 --- a/src/AElf.Client.Core/AElfClientService.Send.cs +++ b/src/AElf.Client.Core/AElfClientService.Send.cs @@ -1,5 +1,5 @@ using AElf.Client.Dto; -using Castle.Core.Logging; +using AElf.Client.Services; using Google.Protobuf; namespace AElf.Client.Core; @@ -7,10 +7,10 @@ namespace AElf.Client.Core; public partial class AElfClientService { public async Task SendAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias, string? alias = null, string? address = null) + string clientAlias, string? accountAlias = null) { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = SetAccount(alias, address); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.AccountAlias); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseContract(contractAddress) @@ -22,10 +22,21 @@ public async Task SendAsync(string contractAddress, string methodNa } public async Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias, string? alias = null, string? address = null) + string clientAlias, string? accountAlias = null) { + if (!systemContractName.StartsWith("AElf.ContractNames.")) + { + throw new ArgumentException("Invalid system contract name."); + } + + if (systemContractName == AElfClientCoreConstants.GenesisSmartContractName) + { + return await SendAsync((await GetGenesisContractAddressAsync(clientAlias)).ToBase58(), methodName, + parameter, clientAlias, accountAlias); + } + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var aelfAccount = SetAccount(alias, address); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: _clientConfigOptions.AccountAlias); var tx = new TransactionBuilder(aelfClient) .UsePrivateKey(aelfAccount) .UseSystemContract(systemContractName) @@ -36,29 +47,11 @@ public async Task SendSystemAsync(string systemContractName, string return tx; } - private static async Task PerformSendAsync(AElfClient aelfClient, Transaction tx) + private static async Task PerformSendAsync(ITransactionAppService aelfClient, Transaction tx) { - var result = await aelfClient.SendTransactionAsync(new SendTransactionInput + await aelfClient.SendTransactionAsync(new SendTransactionInput { RawTransaction = tx.ToByteArray().ToHex() }); } - - private byte[] SetAccount(string? alias, string? address) - { - byte[] aelfAccount; - if (!string.IsNullOrWhiteSpace(address)) - { - _aelfAccountProvider.SetPrivateKey(address, _aelfAccountProvider.GetDefaultPassword()); - aelfAccount = _aelfAccountProvider.GetPrivateKey(null, address); - } - else - { - if (string.IsNullOrWhiteSpace(alias)) - alias = _clientConfigOptions.AccountAlias; - aelfAccount = _aelfAccountProvider.GetPrivateKey(alias); - } - - return aelfAccount; - } } \ No newline at end of file diff --git a/src/AElf.Client.Core/AElfClientService.View.cs b/src/AElf.Client.Core/AElfClientService.View.cs index 35f4e23..278ff3b 100644 --- a/src/AElf.Client.Core/AElfClientService.View.cs +++ b/src/AElf.Client.Core/AElfClientService.View.cs @@ -1,5 +1,6 @@ using AElf.Client.Dto; using AElf.Client.Core.Options; +using AElf.Client.Services; using Google.Protobuf; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -29,8 +30,8 @@ public AElfClientService(IAElfClientProvider aelfClientProvider, IAElfAccountPro Logger = NullLogger.Instance; } - public async Task ViewAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default") + public async Task ViewAsync(string contractAddress, string methodName, IMessage parameter, string clientAlias, + string accountAlias = "Default") where T : IMessage, new() { var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); @@ -40,24 +41,42 @@ public async Task ViewAsync(string contractAddress, string methodName, I .UseMethod(methodName) .UseParameter(parameter) .Build(); - return await PerformViewAsync(aelfClient, tx); + var returnValue = await PerformViewAsync(aelfClient, tx); + var result = new T(); + result.MergeFrom(returnValue); + return result; } - public async Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default") + + public async Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default") where T : IMessage, new() { + if (!systemContractName.StartsWith("AElf.ContractNames.")) + { + throw new ArgumentException("Invalid system contract name."); + } + var aelfClient = _aelfClientProvider.GetClient(alias: clientAlias); - var privateKey = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); + var aelfAccount = _aelfAccountProvider.GetPrivateKey(alias: accountAlias); var tx = new TransactionBuilder(aelfClient) - .UsePrivateKey(privateKey) + .UsePrivateKey(aelfAccount) .UseSystemContract(systemContractName) .UseMethod(methodName) .UseParameter(parameter) .Build(); - return await PerformViewAsync(aelfClient, tx); + var returnValue = await PerformViewAsync(aelfClient, tx); + var result = new T(); + result.MergeFrom(returnValue); + return result; + } + + public async Task
GetGenesisContractAddressAsync(string clientAlias) + { + var chainStatus = await GetChainStatusAsync(clientAlias); + return Address.FromBase58(chainStatus.GenesisContractAddress); } - private async Task PerformViewAsync(AElfClient aelfClient, Transaction tx) + private async Task PerformViewAsync(ITransactionAppService aelfClient, Transaction tx) { var result = await aelfClient.ExecuteTransactionAsync(new ExecuteTransactionDto { diff --git a/src/AElf.Client.Core/ContractServiceBase.cs b/src/AElf.Client.Core/ContractServiceBase.cs index 3120bbf..2f1901d 100644 --- a/src/AElf.Client.Core/ContractServiceBase.cs +++ b/src/AElf.Client.Core/ContractServiceBase.cs @@ -1,5 +1,6 @@ using Google.Protobuf; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Threading; namespace AElf.Client.Core; @@ -7,7 +8,7 @@ namespace AElf.Client.Core; public class ContractServiceBase { private readonly IAElfClientService _clientService; - protected string SmartContractName { get; } + protected string? SmartContractName { get; } protected Address? ContractAddress { get; set; } public ILogger Logger { get; set; } @@ -16,37 +17,42 @@ protected ContractServiceBase(IAElfClientService clientService, string smartCont { _clientService = clientService; SmartContractName = smartContractName; + + Logger = NullLogger.Instance; } protected ContractServiceBase(IAElfClientService clientService, Address contractAddress) { _clientService = clientService; ContractAddress = contractAddress; + + Logger = NullLogger.Instance; } - protected async Task PerformSendTransactionAsync(string methodName, IMessage parameter, - string useClientAlias, string? smartContractName = null) + protected async Task PerformSendTransactionAsync(string methodName, IMessage parameter, + string clientAlias) { - if (smartContractName == null) + if (ContractAddress != null) { - smartContractName = SmartContractName; + return await _clientService.SendAsync(ContractAddress.ToBase58(), methodName, parameter, clientAlias); } - if (ContractAddress != null) + if (SmartContractName != null) { - return await _clientService.SendAsync(ContractAddress.ToBase58(), methodName, parameter, useClientAlias); + return await _clientService.SendSystemAsync(SmartContractName, methodName, parameter, clientAlias); } - return await _clientService.SendSystemAsync(smartContractName, methodName, parameter, useClientAlias); + Logger.LogError($"Neither ContractAddress nor SmartContractName is set."); + return null; } protected async Task PerformGetTransactionResultAsync(string transactionId, - string useClientAlias) + string clientAlias) { TransactionResult txResult; do { - txResult = await _clientService.GetTransactionResultAsync(transactionId, useClientAlias); + txResult = await _clientService.GetTransactionResultAsync(transactionId, clientAlias); } while (txResult.Status == TransactionResultStatus.Pending); Logger.LogInformation("{TxResult}", txResult); diff --git a/src/AElf.Client.Core/IAElfAccountProvider.cs b/src/AElf.Client.Core/IAElfAccountProvider.cs index ba8781a..74d02cc 100644 --- a/src/AElf.Client.Core/IAElfAccountProvider.cs +++ b/src/AElf.Client.Core/IAElfAccountProvider.cs @@ -12,31 +12,29 @@ namespace AElf.Client.Core; public interface IAElfAccountProvider { byte[] GetPrivateKey(string? alias = null, string? address = null); - void SetPrivateKey(byte[] privateKey, string? alias = null, string? address = null); - void SetPrivateKey(string address, string password, string? alias = null); - string GetDefaultPassword(); + void SetPrivateKey(byte[] privateKey, string? accountAlias = null); + void SetPrivateKey(string address, string password, string? accountAlias = null); + string GetAliasByAddress(string address); + void AddAccountByDefaultPassword(string address); } public class AElfAccountProvider : Dictionary, IAElfAccountProvider, ISingletonDependency { private readonly IKeyDirectoryProvider _keyDirectoryProvider; private readonly AElfAccountOptions _aelfAccountOptions; - private readonly string _aelfMinerAccountPassword; private readonly KeyStoreService _keyStoreService; public ILogger Logger { get; set; } public AElfAccountProvider(IKeyDirectoryProvider keyDirectoryProvider, - IOptionsSnapshot aelfAccountOptions, - IOptionsSnapshot aelfMinerAccountOptions) + IOptionsSnapshot aelfAccountOptions) { Logger = NullLogger.Instance; _keyDirectoryProvider = keyDirectoryProvider; _aelfAccountOptions = aelfAccountOptions.Value; - _aelfMinerAccountPassword = aelfMinerAccountOptions.Value.DefaultPassword; var defaultPrivateKey = ByteArrayHelper.HexStringToByteArray(AElfClientConstants.DefaultPrivateKey); - SetPrivateKey(defaultPrivateKey, "Default", Address.FromPublicKey(defaultPrivateKey).ToBase58()); + SetPrivateKey(defaultPrivateKey, "Default"); _keyStoreService = new KeyStoreService(); foreach (var accountConfig in aelfAccountOptions.Value.AccountConfigList) @@ -50,21 +48,16 @@ public AElfAccountProvider(IKeyDirectoryProvider keyDirectoryProvider, var json = textReader.ReadToEnd(); return _keyStoreService.DecryptKeyStoreFromJson(accountConfig.Password, json); })); - SetPrivateKey(privateKey, accountConfig.Alias, accountConfig.Address); + SetPrivateKey(privateKey, accountConfig.Alias); } else { var privateKey = ByteArrayHelper.HexStringToByteArray(accountConfig.PrivateKey); - SetPrivateKey(privateKey, accountConfig.Alias, Address.FromPublicKey(privateKey).ToBase58()); + SetPrivateKey(privateKey, accountConfig.Alias); } } } - public string GetDefaultPassword() - { - return _aelfMinerAccountPassword; - } - public byte[] GetPrivateKey(string? alias = null, string? address = null) { var keys = Keys @@ -79,16 +72,16 @@ public byte[] GetPrivateKey(string? alias = null, string? address = null) return this[keys.Single()]; } - public void SetPrivateKey(byte[] privateKey, string? alias = null, string? address = null) + public void SetPrivateKey(byte[] privateKey, string? accountAlias = null) { TryAdd(new AElfAccountInfo { - Alias = alias, - Address = address + Alias = accountAlias, + Address = Address.FromPublicKey(privateKey).ToBase58() }, privateKey); } - public void SetPrivateKey(string address, string password, string? alias = null) + public void SetPrivateKey(string address, string password, string? accountAlias = null) { var keyFilePath = GetKeyFileFullPath(address, _aelfAccountOptions.KeyDirectory); var privateKey = AsyncHelper.RunSync(() => Task.Run(() => @@ -99,18 +92,36 @@ public void SetPrivateKey(string address, string password, string? alias = null) })); var keys = Keys - .WhereIf(!alias.IsNullOrWhiteSpace(), a => a.Alias == alias) + .WhereIf(!accountAlias.IsNullOrWhiteSpace(), a => a.Alias == accountAlias) .WhereIf(!address.IsNullOrWhiteSpace(), a => a.Address == address) .ToList(); if (keys.Count == 1) return; TryAdd(new AElfAccountInfo { - Alias = alias, + Alias = accountAlias, Address = address }, privateKey); } + public string GetAliasByAddress(string address) + { + var keys = Keys + .WhereIf(!address.IsNullOrWhiteSpace(), a => a.Address == address) + .ToList(); + if (keys.Count != 1) + { + throw new AElfClientException($"Failed to get alias of {address}."); + } + + return keys.First().Alias!; + } + + public void AddAccountByDefaultPassword(string address) + { + SetPrivateKey(address, _aelfAccountOptions.DefaultPassword); + } + private string GetKeyFileFullPath(string address, string configuredKeyDirectory) { var dirPath = GetKeystoreDirectoryPath(configuredKeyDirectory); diff --git a/src/AElf.Client.Core/IAElfClientService.cs b/src/AElf.Client.Core/IAElfClientService.cs index 2c1c770..980bee3 100644 --- a/src/AElf.Client.Core/IAElfClientService.cs +++ b/src/AElf.Client.Core/IAElfClientService.cs @@ -1,25 +1,72 @@ using AElf.Client.Dto; using Google.Protobuf; +using Google.Protobuf.Reflection; namespace AElf.Client.Core; public interface IAElfClientService { - Task ViewAsync(string contractAddress, string methodName, IMessage parameter, string clientAlias, - string accountAlias = "Default"); + /// + /// Build a transaction to view contract state and return the result. + /// + /// Transaction.To + /// Transaction.MethodName + /// Transaction.Parameter + /// Which client to use + /// Which account to use + /// Only IMessage type + /// Contract call result + Task ViewAsync(string contractAddress, string methodName, IMessage parameter, string clientAlias, + string accountAlias = "Default") where T : IMessage, new(); - Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias, string accountAlias = "Default"); + /// + /// Build a transaction to view system contract state and return the result. + /// + /// The System Contract Name with the format AElf.ContractNames.* + /// Transaction.MethodName + /// Transaction.Parameter + /// Which client to use + /// Which account to use + /// Only IMessage type + /// Contract call result + /// Throw Invalid system contract name if systemContractName + /// is not starts with AElf.ContractNames. + Task ViewSystemAsync(string systemContractName, string methodName, IMessage parameter, + string clientAlias, string accountAlias = "Default") where T : IMessage, new(); + /// + /// Send a transaction to a Contract. + /// + /// Transaction.tO + /// Transaction.MethodName + /// Transaction.Parameter + /// Which client to use + /// Which account to use + /// Contract call result Task SendAsync(string contractAddress, string methodName, IMessage parameter, - string clientAlias, string? accountAlias = null, string? accountAddress = null); + string clientAlias, string? accountAlias = null); + /// + /// Send a transaction to a System Contract. + /// + /// The System Contract Name with the format AElf.ContractNames.* + /// Transaction.MethodName + /// Transaction.Parameter + /// Which client to use + /// Which account to use + /// Contract call result + /// Throw Invalid system contract name if systemContractName + /// is not starts with AElf.ContractNames. Task SendSystemAsync(string systemContractName, string methodName, IMessage parameter, - string clientAlias, string? accountAlias = null, string? accountAddress = null); + string clientAlias, string? accountAlias = null); Task GetTransactionResultAsync(string transactionId, string clientAlias); Task GetChainStatusAsync(string clientAlias); + Task
GetGenesisContractAddressAsync(string clientAlias); + Task GetMerklePathByTransactionIdAsync(string transactionId, string clientAlias); + + Task GetContractFileDescriptorSetAsync(string contractAddress, string clientAlias); } \ No newline at end of file diff --git a/src/AElf.Client.Core/Options/AElfAccountOptions.cs b/src/AElf.Client.Core/Options/AElfAccountOptions.cs index a49e606..2df14ba 100644 --- a/src/AElf.Client.Core/Options/AElfAccountOptions.cs +++ b/src/AElf.Client.Core/Options/AElfAccountOptions.cs @@ -4,6 +4,7 @@ public class AElfAccountOptions { public string KeyDirectory { get; set; } public List AccountConfigList { get; set; } = new(); + public string DefaultPassword { get; set; } } public class AccountConfig diff --git a/src/AElf.Client.Election/AElf.Client.Election.csproj b/src/AElf.Client.Election/AElf.Client.Election.csproj deleted file mode 100644 index 7219577..0000000 --- a/src/AElf.Client.Election/AElf.Client.Election.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - - diff --git a/src/AElf.Client.Election/AElfClientElectionModule.cs b/src/AElf.Client.Election/AElfClientElectionModule.cs deleted file mode 100644 index 3b15cff..0000000 --- a/src/AElf.Client.Election/AElfClientElectionModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Election; - -public class AElfClientElectionModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Genesis/AElfContractOption.cs b/src/AElf.Client.Genesis/AElfContractOption.cs deleted file mode 100644 index f68c0ca..0000000 --- a/src/AElf.Client.Genesis/AElfContractOption.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace AElf.Client.Genesis; - -public class AElfContractOption -{ - public string NFTContractAddress { get; set; } - - public string GenesisContractAddress { get; set; } - public string ContractDirectory { get; set; } -} \ No newline at end of file diff --git a/src/AElf.Client.Genesis/GenesisService.View.cs b/src/AElf.Client.Genesis/GenesisService.View.cs deleted file mode 100644 index e8691ac..0000000 --- a/src/AElf.Client.Genesis/GenesisService.View.cs +++ /dev/null @@ -1,39 +0,0 @@ -using AElf.Standards.ACS0; -using AElf.Types; -using Google.Protobuf; -using Google.Protobuf.WellKnownTypes; - -namespace AElf.Client.Genesis; - -public partial class GenesisService -{ - public async Task GetContractDeploymentController() - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewAsync(_contractAddress, "GetContractDeploymentController", - new Empty(), useClientAlias); - var authorityInfo = new AuthorityInfo(); - authorityInfo.MergeFrom(result); - return authorityInfo; - } - - public async Task GetSmartContractRegistrationByCodeHash(Hash codeHash) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewAsync(_contractAddress, "GetSmartContractRegistrationByCodeHash", - codeHash, useClientAlias); - var smartContractRegistration = new SmartContractRegistration(); - smartContractRegistration.MergeFrom(result); - return smartContractRegistration; - } - - public async Task GetContractInfo(Address contractAddress) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewAsync(_contractAddress, "GetContractInfo", - contractAddress, useClientAlias); - var contractInfo = new ContractInfo(); - contractInfo.MergeFrom(result); - return contractInfo; - } -} \ No newline at end of file diff --git a/src/AElf.Client.Oracle/AElf.Client.Oracle.csproj b/src/AElf.Client.Oracle/AElf.Client.Oracle.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Oracle/AElf.Client.Oracle.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Oracle/AElfClientOracleModule.cs b/src/AElf.Client.Oracle/AElfClientOracleModule.cs deleted file mode 100644 index 09eafbd..0000000 --- a/src/AElf.Client.Oracle/AElfClientOracleModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Oracle; - -public class AElfClientOracleModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Parliament/Parliament.View.cs b/src/AElf.Client.Parliament/Parliament.View.cs deleted file mode 100644 index 933c026..0000000 --- a/src/AElf.Client.Parliament/Parliament.View.cs +++ /dev/null @@ -1,29 +0,0 @@ -using AElf.Contracts.Parliament; -using AElf.Standards.ACS3; -using AElf.Types; -using Google.Protobuf; - -namespace AElf.Client.Parliament; - -public partial class ParliamentService -{ - public async Task CheckProposal(Hash proposalId) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, "GetProposal", - proposalId, useClientAlias); - var proposalOutput = new ProposalOutput(); - proposalOutput.MergeFrom(result); - return proposalOutput; - } - - public async Task GetOrganization(Address organizationAddress) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var result = await _clientService.ViewSystemAsync(AElfParliamentConstants.ParliamentSmartContractName, "GetOrganization", - organizationAddress, useClientAlias); - var organization = new Organization(); - organization.MergeFrom(result); - return organization; - } -} \ No newline at end of file diff --git a/src/AElf.Client.Profit/AElf.Client.Profit.csproj b/src/AElf.Client.Profit/AElf.Client.Profit.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Profit/AElf.Client.Profit.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Profit/AElfClientProfitModule.cs b/src/AElf.Client.Profit/AElfClientProfitModule.cs deleted file mode 100644 index 31899b5..0000000 --- a/src/AElf.Client.Profit/AElfClientProfitModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Profit; - -public class AElfClientProfitModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Referendum/AElf.Client.Referendum.csproj b/src/AElf.Client.Referendum/AElf.Client.Referendum.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Referendum/AElf.Client.Referendum.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Referendum/AElfClientReferendumModule.cs b/src/AElf.Client.Referendum/AElfClientReferendumModule.cs deleted file mode 100644 index 15ac370..0000000 --- a/src/AElf.Client.Referendum/AElfClientReferendumModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Referendum; - -public class AElfClientReferendumModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Regiment/AElf.Client.Regiment.csproj b/src/AElf.Client.Regiment/AElf.Client.Regiment.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Regiment/AElf.Client.Regiment.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Regiment/AElfClientRegimentModule.cs b/src/AElf.Client.Regiment/AElfClientRegimentModule.cs deleted file mode 100644 index 18683e0..0000000 --- a/src/AElf.Client.Regiment/AElfClientRegimentModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Regiment; - -public class AElfClientRegimentModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj b/src/AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.TokenConverter/AElf.Client.TokenConverter.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs b/src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs deleted file mode 100644 index 641effb..0000000 --- a/src/AElf.Client.TokenConverter/AElfClientTokenConverterModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.TokenConverter; - -public class AElfClientTokenConverterModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj b/src/AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.TokenHolder/AElf.Client.TokenHolder.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs b/src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs deleted file mode 100644 index 07a915b..0000000 --- a/src/AElf.Client.TokenHolder/AElfClientTokenHolderModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.TokenHolder; - -public class AElfClientTokenHolderModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Vote/AElf.Client.Vote.csproj b/src/AElf.Client.Vote/AElf.Client.Vote.csproj deleted file mode 100644 index eb2460e..0000000 --- a/src/AElf.Client.Vote/AElf.Client.Vote.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/src/AElf.Client.Vote/AElfClientVoteModule.cs b/src/AElf.Client.Vote/AElfClientVoteModule.cs deleted file mode 100644 index bb3ccbb..0000000 --- a/src/AElf.Client.Vote/AElfClientVoteModule.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AElf.Client.Vote; - -public class AElfClientVoteModule -{ -} \ No newline at end of file diff --git a/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj b/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj deleted file mode 100644 index c73bdf0..0000000 --- a/src/AElf.Client.Whitelist/AElf.Client.Whitelist.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - diff --git a/src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs b/src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs deleted file mode 100644 index d49816c..0000000 --- a/src/AElf.Client.Whitelist/AElfClientWhitelistModule.cs +++ /dev/null @@ -1,13 +0,0 @@ -using AElf.Client.Core; -using Volo.Abp.Modularity; - -namespace AElf.Client.Whitelist; - -[DependsOn( - typeof(AElfClientModule), - typeof(CoreAElfModule) -)] -public class AElfClientWhitelistModule -{ - -} \ No newline at end of file diff --git a/src/AElf.Client.Whitelist/IWhitelistService.cs b/src/AElf.Client.Whitelist/IWhitelistService.cs deleted file mode 100644 index f06a6c2..0000000 --- a/src/AElf.Client.Whitelist/IWhitelistService.cs +++ /dev/null @@ -1,9 +0,0 @@ -using AElf.Client.Core; -using AElf.Contracts.Whitelist; - -namespace AElf.Client.Whitelist; - -public interface IWhitelistService -{ - Task CreateWhitelistAsync(CreateWhitelistInput createWhitelistInput); -} \ No newline at end of file diff --git a/src/AElf.Client.Whitelist/WhitelistService.cs b/src/AElf.Client.Whitelist/WhitelistService.cs deleted file mode 100644 index 75e9ca9..0000000 --- a/src/AElf.Client.Whitelist/WhitelistService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using AElf.Client.Core; -using AElf.Client.Core.Options; -using AElf.Contracts.Whitelist; -using AElf.Types; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; - -namespace AElf.Client.Whitelist; - -public class WhitelistService : ContractServiceBase, IWhitelistService, ITransientDependency -{ - private readonly IAElfClientService _clientService; - private readonly AElfClientConfigOptions _clientConfigOptions; - - protected WhitelistService(IAElfClientService clientService, - IOptionsSnapshot clientConfigOptions) : base(clientService, - Address.FromBase58("aceGtyU2fVcBkViZcaqZXHHjd7eNAJ6NPwbuFwhqv6He49BS1")) - { - _clientService = clientService; - _clientConfigOptions = clientConfigOptions.Value; - } - - public async Task CreateWhitelistAsync(CreateWhitelistInput createWhitelistInput) - { - var useClientAlias = _clientConfigOptions.ClientAlias; - var tx = await PerformSendTransactionAsync("CreateWhitelist", createWhitelistInput, useClientAlias); - return new SendTransactionResult - { - Transaction = tx, - TransactionResult = await PerformGetTransactionResultAsync(tx.GetHash().ToHex(), useClientAlias) - }; - } -} \ No newline at end of file diff --git a/src/AElf.Client/AElfClient.Chain.cs b/src/AElf.Client/AElfClient.Chain.cs index e42eb0f..eeeb460 100644 --- a/src/AElf.Client/AElfClient.Chain.cs +++ b/src/AElf.Client/AElfClient.Chain.cs @@ -32,7 +32,7 @@ public async Task GetContractFileDescriptorSetAsync(string? address) var set = await _httpService.GetResponseAsync(url); if (set == null) { - throw new AElfClientException("Failed to get chain status"); + throw new AElfClientException("Failed to get method descriptor"); } return set; diff --git a/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj b/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj deleted file mode 100644 index d2224fa..0000000 --- a/test/AElf.Client.Core.Test/AElf.Client.Core.Test.csproj +++ /dev/null @@ -1,32 +0,0 @@ - - - - net6.0 - enable - enable - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - - - diff --git a/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestBase.cs b/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestBase.cs deleted file mode 100644 index 2b1e5f7..0000000 --- a/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestBase.cs +++ /dev/null @@ -1,9 +0,0 @@ -using AElf.Client.TestBase; - -namespace AElf.Client.Test; - -public abstract class - AElfClientAbpContractServiceTestBase : AElfClientAbpTestBase -{ - -} \ No newline at end of file diff --git a/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestModule.cs b/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestModule.cs deleted file mode 100644 index 88fedbd..0000000 --- a/test/AElf.Client.Core.Test/AElfClientAbpContractServiceTestModule.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AElf.Client.Genesis; -using AElf.Client.TestBase; -using AElf.Client.Token; -using Volo.Abp.Modularity; - -namespace AElf.Client.Test; - -[DependsOn( - typeof(AElfClientAbpTestBaseModule), - typeof(AElfClientTokenModule), - typeof(AElfClientGenesisModule) -)] -public class AElfClientAbpContractServiceTestModule : AbpModule -{ - -} \ No newline at end of file diff --git a/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs b/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs deleted file mode 100644 index 4f9be51..0000000 --- a/test/AElf.Client.Core.Test/Genesis/GenesisServiceTests.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using AElf.Client.Genesis; -using AElf.Client.Test; -using AElf.Client.TestBase; -using AElf.Types; -using Shouldly; - -namespace AElf.Client.Abp.Test.Genesis; - -[Trait("Category", "GenesisContractService")] - -public sealed class GenesisServiceTests : AElfClientAbpContractServiceTestBase -{ - private readonly IGenesisService _genesisService; - private readonly IDeployContractService _deployService; - - public GenesisServiceTests() - { - _genesisService = GetRequiredService(); - _deployService = GetRequiredService(); - } - - [IgnoreOnCITheory] - [InlineData("AElf.Contracts.NFT")] - public async Task DeployContract(string contractName) - { - var address = await _deployService.DeployContract(contractName); - address.ShouldNotBeNull(); - } - - [IgnoreOnCITheory] - [InlineData("UoHeeCXZ6fV481oD3NXASSexWVtsPLgv2Wthm3BGrPAgqdS5d")] - public async Task GetContractInfo(string contractAddress) - { - var address = Address.FromBase58(contractAddress); - var contractInfo = await _genesisService.GetContractInfo(address); - contractInfo.Author.ToBase58().ShouldBe("2UKQnHcQvhBT6X6ULtfnuh3b9PVRvVMEroHHkcK4YfcoH1Z1x2"); - } -} \ No newline at end of file diff --git a/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs b/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs deleted file mode 100644 index 28293f2..0000000 --- a/test/AElf.Client.Core.Test/Token/TokenServiceTests.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using AElf.Client.TestBase; -using AElf.Client.Token; -using AElf.Client.Token.SyncTokenInfo; -using AElf.Contracts.Bridge; -using AElf.Contracts.NFT; -using AElf.Types; -using Google.Protobuf; -using Shouldly; -using Xunit.Abstractions; -using TransferInput = AElf.Contracts.MultiToken.TransferInput; - -namespace AElf.Client.Test.Token; - -[Trait("Category", "TokenContractService")] -public sealed class TokenServiceTests : AElfClientAbpContractServiceTestBase -{ - private readonly ITestOutputHelper _testOutputHelper; - private readonly ITokenService _tokenService; - private readonly ISyncTokenInfoQueueService _syncTokenInfoQueueService; - - public TokenServiceTests(ITestOutputHelper testOutputHelper) - { - _testOutputHelper = testOutputHelper; - _tokenService = GetRequiredService(); - _syncTokenInfoQueueService = GetRequiredService(); - } - - [IgnoreOnCITheory] - [InlineData("USDT")] - public async Task GetTokenInfoTest(string symbol) - { - var tokenInfo = await _tokenService.GetTokenInfoAsync(symbol); - tokenInfo.Symbol.ShouldBe(symbol); - _testOutputHelper.WriteLine(tokenInfo.ToString()); - } - - [IgnoreOnCITheory] - [InlineData("HyGoexPnPnJFgqTUPaBg5TrvvbgvRdu6sPZt19WjRdXZJk2jN", "ELF", 1_00000000)] - public async Task TransferTest(string address, string symbol, long amount) - { - var result = await _tokenService.TransferAsync(new TransferInput - { - To = Address.FromBase58(address), - Symbol = symbol, - Amount = amount - }); - result.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined); - var logEvent = result.TransactionResult.Logs.First(l => l.Name == nameof(Contracts.MultiToken.Transferred)); - var transferred = new Contracts.MultiToken.Transferred(); - foreach (var indexed in logEvent.Indexed) - { - transferred.MergeFrom(indexed); - } - - transferred.MergeFrom(logEvent.NonIndexed); - transferred.Symbol.ShouldBe(symbol); - transferred.To.ToBase58().ShouldBe(address); - transferred.Amount.ShouldBe(amount); - } - - [IgnoreOnCITheory] - [InlineData("BA994198147")] - public async Task SyncTokenInfoTest(string symbol) - { - _syncTokenInfoQueueService.Enqueue(symbol); - } - - [IgnoreOnCITheory] - [InlineData("CO429872652")] - public async Task CrossChainCreateNFTProtocolTest(string symbol) - { - await _tokenService.CrossChainCreateNFTProtocolAsync(new CrossChainCreateInput - { - Symbol = symbol - }); - } - - [IgnoreOnCITheory] - [InlineData("BA417054001", "JQkVTWz5HXxEmNXzTtsAVHC7EUTeiFktzoFUu9TyA6MWngkem")] - public async Task AddMintersTest(string symbol, string addressBase58) - { - var address = Address.FromBase58(addressBase58); - await _tokenService.AddMintersAsync(new AddMintersInput - { - Symbol = symbol, - MinterList = new MinterList - { - Value = { address } - } - }); - } - - [IgnoreOnCITheory] - [InlineData("bb16f381b0f2e795a988285dec3a68affacdccd7d3ac2e74edc808c102efcd95", 228, "9413000000000000000000")] - public async Task SwapTokenTest(string swapIdHex, long receiptId, string amount) - { - var swapId = Hash.LoadFromHex(swapIdHex); - await _tokenService.SwapTokenAsync(new SwapTokenInput - { - SwapId = swapId, - OriginAmount = amount, - ReceiptId = receiptId - }); - } - - [IgnoreOnCIFact] - public async Task GetCalculateFeeCoefficientsForSenderTest() - { - var coefficients = await _tokenService.GetCalculateFeeCoefficientsForSenderAsync(); - coefficients.FeeTokenType.ShouldBe(4); - } -} \ No newline at end of file diff --git a/test/AElf.Client.Core.Test/Usings.cs b/test/AElf.Client.Core.Test/Usings.cs deleted file mode 100644 index 8c927eb..0000000 --- a/test/AElf.Client.Core.Test/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Xunit; \ No newline at end of file diff --git a/test/AElf.Client.TestBase/appsettings.json b/test/AElf.Client.TestBase/appsettings.json index ef4f6f1..6bd9fdb 100644 --- a/test/AElf.Client.TestBase/appsettings.json +++ b/test/AElf.Client.TestBase/appsettings.json @@ -51,7 +51,7 @@ } }, "AElfClientConfig": { - "ClientAlias": "MainNetSideChain1", + "ClientAlias": "MainNetMainChain", "MainChainClientAlias": "TestNetMainChain", "SideChainClientAlias": "TestNetSideChain2", "AccountAlias": "eanz",