コード例 #1
0
ファイル: BlockMiningService.cs プロジェクト: wymoon2690/AElf
        /// <summary>
        /// Only deploy provided contracts as system contract.
        /// Should initial each contract after if necessary.
        /// </summary>
        /// <param name="nameToCode"></param>
        /// <returns></returns>
        public async Task <Dictionary <Hash, Address> > DeploySystemContractsAsync(Dictionary <Hash, byte[]> nameToCode)
        {
            var map = new Dictionary <Hash, Address>();
            var zeroContractStub =
                _contractTesterFactory.Create <BasicContractZeroContainer.BasicContractZeroStub>(
                    _smartContractAddressService.GetZeroSmartContractAddress(),
                    MissionedECKeyPairs.InitialKeyPairs.First());

            if (!nameToCode.Keys.Contains(ConsensusSmartContractAddressNameProvider.Name))
            {
                nameToCode.Add(ConsensusSmartContractAddressNameProvider.Name,
                               ContractsDeployer.GetContractCodes <ContractTestAEDPoSExtensionModule>().First().Value);
            }

            foreach (var(name, code) in nameToCode)
            {
                var address = (await zeroContractStub.DeploySystemSmartContract.SendAsync(
                                   new SystemContractDeploymentInput
                {
                    Name = name,
                    Category = KernelConstants.CodeCoverageRunnerCategory,
                    Code = ByteString.CopyFrom(code),
                })).Output;
                map.Add(name, address);
                if (name == ConsensusSmartContractAddressNameProvider.Name)
                {
                    _consensusContractAddress = address;
                }
            }

            _isSystemContractsDeployed = true;
            var currentBlockTime = TimestampHelper.GetUtcNow().ToDateTime();

            _testDataProvider.SetBlockTime(currentBlockTime.ToTimestamp()
                                           .AddMilliseconds(AEDPoSExtensionConstants.MiningInterval));

            InitialContractStubs();
            InitialConsensus(currentBlockTime);

            return(map);
        }