public async Task InitialSideChainAsync(int chainId, Action <List <GenesisSmartContractDto> > configureSmartContract = null) { var osBlockchainNodeContextService = Application.ServiceProvider.GetRequiredService <IOsBlockchainNodeContextService>(); var dto = new OsBlockchainNodeContextStartDto { ChainId = chainId, ZeroSmartContract = typeof(BasicContractZero), SmartContractRunnerCategory = SmartContractTestConstants.TestRunnerCategory }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name, new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList { Value = { new SystemContractDeploymentInput.Types.SystemTransactionMethodCall { MethodName = nameof(AEDPoSContractContainer.AEDPoSContractStub.InitialAElfConsensusContract), Params = new InitialAElfConsensusContractInput{ IsSideChain = true }.ToByteString() }, } }); configureSmartContract?.Invoke(dto.InitializationSmartContracts); await osBlockchainNodeContextService.StartAsync(dto); }
public async Task <OsBlockchainNodeContext> InitialChainAsyncWithAuthAsync( Action <List <GenesisSmartContractDto> > configureSmartContract = null) { var osBlockchainNodeContextService = Application.ServiceProvider.GetRequiredService <IOsBlockchainNodeContextService>(); var contractOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ContractOptions> >().Value; var consensusOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ConsensusOptions> >().Value; consensusOptions.StartTimestamp = TimestampHelper.GetUtcNow(); var dto = new OsBlockchainNodeContextStartDto { ChainId = ChainHelper.ConvertBase58ToChainId("AELF"), ZeroSmartContract = typeof(BasicContractZero), SmartContractRunnerCategory = SmartContractTestConstants.TestRunnerCategory, ContractDeploymentAuthorityRequired = contractOptions.ContractDeploymentAuthorityRequired }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name, GenerateConsensusInitializationCallList(consensusOptions)); configureSmartContract?.Invoke(dto.InitializationSmartContracts); return(await osBlockchainNodeContextService.StartAsync(dto)); }
public async Task <OsBlockchainNodeContext> InitialCustomizedChainAsync(int chainId, List <string> initialMiners = null, int miningInterval = 4000, Timestamp startTimestamp = null, Action <List <GenesisSmartContractDto> > configureSmartContract = null) { if (initialMiners == null) { initialMiners = Enumerable.Range(0, 3).Select(i => SampleECKeyPairs.KeyPairs[i].PublicKey.ToHex()) .ToList(); } if (startTimestamp == null) { startTimestamp = TimestampHelper.GetUtcNow(); } var osBlockchainNodeContextService = Application.ServiceProvider.GetRequiredService <IOsBlockchainNodeContextService>(); var contractOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ContractOptions> >().Value; var dto = new OsBlockchainNodeContextStartDto { ChainId = chainId, ZeroSmartContract = typeof(BasicContractZero), SmartContractRunnerCategory = SmartContractTestConstants.TestRunnerCategory, ContractDeploymentAuthorityRequired = contractOptions.ContractDeploymentAuthorityRequired }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name, GenerateConsensusInitializationCallList(initialMiners, miningInterval, startTimestamp)); configureSmartContract?.Invoke(dto.InitializationSmartContracts); return(await osBlockchainNodeContextService.StartAsync(dto)); }
private async Task StartNodeAsync() { var dto = new OsBlockchainNodeContextStartDto { ZeroSmartContract = typeof(BasicContractZero), ChainId = _chainOptions.ChainId }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name); var ownAddress = await _accountService.GetAccountAsync(); var callList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList(); callList.Add(nameof(TokenContractContainer.TokenContractStub.Create), new CreateInput { Symbol = "ELF", TokenName = "ELF_Token", TotalSupply = 1000_0000L, Decimals = 2, Issuer = ownAddress, IsBurnable = true });
public override void OnApplicationInitialization(ApplicationInitializationContext context) { var chainOptions = context.ServiceProvider.GetService <IOptionsSnapshot <ChainOptions> >().Value; var dto = new OsBlockchainNodeContextStartDto() { ChainId = chainOptions.ChainId, ZeroSmartContract = typeof(BasicContractZero) }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract( TokenContractCode, TokenSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract( ElectionContractCode, ElectionSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract( FeeReceiverContractCode, ResourceFeeReceiverSmartContractAddressNameProvider.Name); var osService = context.ServiceProvider.GetService <IOsBlockchainNodeContextService>(); var that = this; AsyncHelper.RunSync(async() => { that.OsBlockchainNodeContext = await osService.StartAsync(dto); }); }
private async Task StartNodeAsync() { var dto = new OsBlockchainNodeContextStartDto { ZeroSmartContract = typeof(BasicContractZero), ChainId = _chainOptions.ChainId }; dto.SmartContractRunnerCategory = KernelConstants.CodeCoverageRunnerCategory; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name); var ownAddress = await _accountService.GetAccountAsync(); var callList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList(); callList.Add(nameof(TokenContractContainer.TokenContractStub.Create), new CreateInput { Symbol = "ELF", TokenName = "ELF_Token", TotalSupply = TokenTotalSupply, Decimals = 2, Issuer = ownAddress, IsBurnable = true }); callList.Add(nameof(TokenContractContainer.TokenContractStub.SetPrimaryTokenSymbol), new SetPrimaryTokenSymbolInput { Symbol = "ELF" }); callList.Add(nameof(TokenContractContainer.TokenContractStub.Issue), new IssueInput { Symbol = "ELF", Amount = TokenTotalSupply, To = ownAddress, Memo = "Issue" }); callList.Add(nameof(TokenContractContainer.TokenContractStub.InitialCoefficients), new Empty()); dto.InitializationSmartContracts.AddGenesisSmartContract( ElectionContractCode, ElectionSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract( TokenContractCode, TokenSmartContractAddressNameProvider.Name, callList); _blockchainNodeCtxt = await _osBlockchainNodeContextService.StartAsync(dto); }
private async Task StartNodeAsync() { var ownAddress = await _accountService.GetAccountAsync(); var callList = new List <ContractInitializationMethodCall>(); callList.Add(nameof(TokenContractContainer.TokenContractStub.Create), new CreateInput { Symbol = _nativeSymbol, TokenName = "ELF_Token", TotalSupply = TokenTotalSupply, Decimals = 8, Issuer = ownAddress, IsBurnable = true }); callList.Add(nameof(TokenContractContainer.TokenContractStub.SetPrimaryTokenSymbol), new SetPrimaryTokenSymbolInput { Symbol = _nativeSymbol }); callList.Add(nameof(TokenContractContainer.TokenContractStub.Issue), new IssueInput { Symbol = _nativeSymbol, Amount = TokenTotalSupply, To = ownAddress, Memo = "Issue" }); var tokenContractCode = Codes.Single(kv => kv.Key.Split(",").First().Trim().EndsWith("MultiToken")).Value; var dto = new OsBlockchainNodeContextStartDto { ZeroSmartContract = typeof(BasicContractZero), ChainId = ChainHelper.ConvertBase58ToChainId("AELF"), SmartContractRunnerCategory = KernelConstants.CodeCoverageRunnerCategory, }; var genesisSmartContractDto = new GenesisSmartContractDto { Code = tokenContractCode, SystemSmartContractName = TokenSmartContractAddressNameProvider.Name, }; genesisSmartContractDto.AddGenesisTransactionMethodCall(callList.ToArray()); dto.InitializationSmartContracts.Add(genesisSmartContractDto); await _osBlockchainNodeContextService.StartAsync(dto); }
public async Task StartAsync() { var chainOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ChainOptions> >().Value; var dto = new OsBlockchainNodeContextStartDto() { ChainId = chainOptions.ChainId, ZeroSmartContract = typeof(BasicContractZero) }; dto.InitializationSmartContracts.AddGenesisSmartContract <ConsensusContract>(ConsensusSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract <TokenContract>(TokenSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract <DividendContract>(DividendSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract <ResourceContract>(ResourceSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract <FeeReceiverContract>(ResourceFeeReceiverSmartContractAddressNameProvider.Name); var osService = Application.ServiceProvider.GetService <IOsBlockchainNodeContextService>(); await osService.StartAsync(dto); }
public override void OnApplicationInitialization(ApplicationInitializationContext context) { var chainOptions = context.ServiceProvider.GetService<IOptionsSnapshot<ChainOptions>>().Value; var dto = new OsBlockchainNodeContextStartDto() { ChainId = chainOptions.ChainId, ZeroSmartContract = typeof(BasicContractZero) }; var dtoProvider = context.ServiceProvider.GetRequiredService<IGenesisSmartContractDtoProvider>(); dto.InitializationSmartContracts = dtoProvider.GetGenesisSmartContractDtos().ToList(); var contractOptions = context.ServiceProvider.GetService<IOptionsSnapshot<ContractOptions>>().Value; dto.ContractDeploymentAuthorityRequired = contractOptions.ContractDeploymentAuthorityRequired; var osService = context.ServiceProvider.GetService<IOsBlockchainNodeContextService>(); var that = this; AsyncHelper.RunSync(async () => { that.OsBlockchainNodeContext = await osService.StartAsync(dto); }); }
/// <summary> /// Initial a chain with given chain id (passed to ctor), /// and produce the genesis block with provided smart contract configuration. /// Will deploy consensus contract by default. /// </summary> /// <returns>Return contract addresses as the param order.</returns> public async Task <OsBlockchainNodeContext> InitialChainAsync(Action <List <GenesisSmartContractDto> > configureSmartContract = null) { var osBlockchainNodeContextService = Application.ServiceProvider.GetRequiredService <IOsBlockchainNodeContextService>(); var chainOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ChainOptions> >().Value; var dposOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <DPoSOptions> >().Value; var dto = new OsBlockchainNodeContextStartDto { ChainId = chainOptions.ChainId, ZeroSmartContract = typeof(BasicContractZero), SmartContractRunnerCategory = SmartContractTestConstants.TestRunnerCategory }; dto.InitializationSmartContracts.AddGenesisSmartContract <ConsensusContract>( ConsensusSmartContractAddressNameProvider.Name, GenerateConsensusInitializationCallList(dposOptions)); configureSmartContract?.Invoke(dto.InitializationSmartContracts); return(await osBlockchainNodeContextService.StartAsync(dto)); }
public async Task <OsBlockchainNodeContext> InitialChainAsyncWithAuthAsync( Action <List <GenesisSmartContractDto> > configureSmartContract = null) { var osBlockchainNodeContextService = Application.ServiceProvider.GetRequiredService <IOsBlockchainNodeContextService>(); var contractOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ContractOptions> >().Value; var consensusOptions = Application.ServiceProvider.GetService <IOptionsSnapshot <ConsensusOptions> >().Value; consensusOptions.StartTimestamp = TimestampHelper.GetUtcNow(); var dto = new OsBlockchainNodeContextStartDto { ChainId = ChainHelper.ConvertBase58ToChainId("AELF"), ZeroSmartContract = typeof(BasicContractZero), SmartContractRunnerCategory = SmartContractTestConstants.TestRunnerCategory, ContractDeploymentAuthorityRequired = contractOptions.ContractDeploymentAuthorityRequired }; dto.InitializationSmartContracts.AddGenesisSmartContract( ConsensusContractCode, ConsensusSmartContractAddressNameProvider.Name, GenerateConsensusInitializationCallList(consensusOptions)); configureSmartContract?.Invoke(dto.InitializationSmartContracts); var result = await osBlockchainNodeContextService.StartAsync(dto); var blockChainService = Application.ServiceProvider.GetRequiredService <IBlockchainService>(); var transactionManager = Application.ServiceProvider.GetRequiredService <ITransactionResultManager>(); var chain = await blockChainService.GetChainAsync(); var block = await blockChainService.GetBlockByHashAsync(chain.GenesisBlockHash); foreach (var transactionId in block.TransactionIds) { var transactionResult = await transactionManager.GetTransactionResultAsync(transactionId, block.GetHash()); transactionResult.Status.ShouldBe(TransactionResultStatus.Mined, transactionResult.Error); } return(result); }
public override void OnApplicationInitialization(ApplicationInitializationContext context) { var chainOptions = context.ServiceProvider.GetService <IOptionsSnapshot <ChainOptions> >().Value; var dto = new OsBlockchainNodeContextStartDto() { ChainId = chainOptions.ChainId, ZeroSmartContract = typeof(BasicContractZero) }; var consensusOptions = context.ServiceProvider.GetService <IOptionsSnapshot <ConsensusOptions> >().Value; var zeroContractAddress = context.ServiceProvider.GetRequiredService <ISmartContractAddressService>() .GetZeroSmartContractAddress(); dto.InitializationSmartContracts.AddGenesisSmartContract <ElectionContract>( ElectionSmartContractAddressNameProvider.Name); dto.InitializationSmartContracts.AddGenesisSmartContract <TokenContract>( TokenSmartContractAddressNameProvider.Name, GenerateTokenInitializationCallList(zeroContractAddress, context.ServiceProvider.GetService <IOptions <ConsensusOptions> >().Value.InitialMiners)); dto.InitializationSmartContracts.AddGenesisSmartContract <AEDPoSContract>( ConsensusSmartContractAddressNameProvider.Name, GenerateConsensusInitializationCallList(consensusOptions)); dto.InitializationSmartContracts .AddGenesisSmartContract <HelloWorldContract.HelloWorldContract>(Hash.FromString("HelloWorldContract")); dto.InitializationSmartContracts.AddGenesisSmartContract <BingoGameContract.BingoGameContract>( Hash.FromString("BingoGameContract"), GenerateBingoGameInitializationCallList()); var osService = context.ServiceProvider.GetService <IOsBlockchainNodeContextService>(); var that = this; AsyncHelper.RunSync(async() => { that.OsBlockchainNodeContext = await osService.StartAsync(dto); }); }
private async Task StartNodeAsync() { var dto = new OsBlockchainNodeContextStartDto { ZeroSmartContract = typeof(BasicContractZero), ChainId = _chainOptions.ChainId }; dto.SmartContractRunnerCategory = KernelConstants.CodeCoverageRunnerCategory; var consensusContractDto = new GenesisSmartContractDto { Code = ConsensusContractCode, SystemSmartContractName = ConsensusSmartContractAddressNameProvider.Name, ContractInitializationMethodCallList = new List <ContractInitializationMethodCall>() }; dto.InitializationSmartContracts.Add(consensusContractDto); var tokenContractDto = new GenesisSmartContractDto { Code = TokenContractCode, SystemSmartContractName = TokenSmartContractAddressNameProvider.Name, ContractInitializationMethodCallList = new List <ContractInitializationMethodCall>() }; var ownAddress = await _accountService.GetAccountAsync(); tokenContractDto .AddGenesisTransactionMethodCall(new ContractInitializationMethodCall { MethodName = nameof(TokenContractContainer.TokenContractStub.Create), Params = new CreateInput { Symbol = "ELF", TokenName = "ELF_Token", TotalSupply = TokenTotalSupply, Decimals = 2, Issuer = ownAddress, IsBurnable = true }.ToByteString() }); tokenContractDto.AddGenesisTransactionMethodCall(new ContractInitializationMethodCall { MethodName = nameof(TokenContractContainer.TokenContractStub.SetPrimaryTokenSymbol), Params = new SetPrimaryTokenSymbolInput { Symbol = "ELF" }.ToByteString() }); tokenContractDto.AddGenesisTransactionMethodCall(new ContractInitializationMethodCall { MethodName = nameof(TokenContractContainer.TokenContractStub.Issue), Params = new IssueInput { Symbol = "ELF", Amount = TokenTotalSupply, To = ownAddress, Memo = "Issue" }.ToByteString() }); tokenContractDto.AddGenesisTransactionMethodCall(new ContractInitializationMethodCall { MethodName = nameof(TokenContractContainer.TokenContractStub.InitialCoefficients), Params = new Empty().ToByteString() }); dto.InitializationSmartContracts.Add(tokenContractDto); var electionContractDto = new GenesisSmartContractDto { Code = ElectionContractCode, SystemSmartContractName = ElectionSmartContractAddressNameProvider.Name, ContractInitializationMethodCallList = new List <ContractInitializationMethodCall>() }; dto.InitializationSmartContracts.Add(electionContractDto); _blockchainNodeCtxt = await _osBlockchainNodeContextService.StartAsync(dto); }