コード例 #1
0
        private void ProposeNewSideChain(SideChainCreationRequest request, Address proposer)
        {
            var sideChainLifeTimeController = GetSideChainLifetimeController();
            var proposalCreationInput       = new CreateProposalBySystemContractInput
            {
                ProposalInput =
                    new CreateProposalInput
                {
                    ContractMethodName = nameof(CreateSideChain),
                    ToAddress          = Context.Self,
                    ExpiredTime        =
                        Context.CurrentBlockTime.AddSeconds(SideChainCreationProposalExpirationTimePeriod),
                    Params = new CreateSideChainInput {
                        SideChainCreationRequest = request, Proposer = proposer
                    }
                    .ToByteString(),
                OrganizationAddress = sideChainLifeTimeController.OwnerAddress
                },
                OriginProposer = Context.Sender
            };

            Context.SendInline(sideChainLifeTimeController.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput);
        }
コード例 #2
0
        public override Hash CreateProposalBySystemContract(CreateProposalBySystemContractInput input)
        {
            Assert(Context.GetSystemContractNameToAddressMapping().Values.Contains(Context.Sender),
                   "Not authorized to propose.");
            AssertIsAuthorizedProposer(input.ProposalInput.OrganizationAddress, input.OriginProposer);
            var proposalId = CreateNewProposal(input.ProposalInput);

            return(proposalId);
        }
コード例 #3
0
        public override Hash CreateProposalBySystemContract(CreateProposalBySystemContractInput input)
        {
            Assert(Context.GetSystemContractNameToAddressMapping().Values.Contains(Context.Sender),
                   "Not authorized to propose.");
            AssertIsAuthorizedProposer(input.ProposalInput.OrganizationAddress, input.OriginProposer);
            var proposalId = CreateNewProposal(input.ProposalInput);

            if (!string.IsNullOrEmpty(input.ProposalIdFeedbackMethod))
            {
                Context.SendInline(Context.Sender, input.ProposalIdFeedbackMethod, proposalId); // proposal id feedback
            }
            return(proposalId);
        }
コード例 #4
0
        public override Hash ProposeUpdateContract(ContractUpdateInput input)
        {
            var proposedContractInputHash = CalculateHashFromInput(input);

            Assert(State.ContractProposingInputMap[proposedContractInputHash] == null, "Already proposed.");
            State.ContractProposingInputMap[proposedContractInputHash] = new ContractProposingInput
            {
                Proposer = Context.Sender,
                Status   = ContractProposingInputStatus.Proposed
            };

            var contractAddress = input.Address;
            var info            = State.ContractInfos[contractAddress];

            Assert(info != null, "Contract does not exist.");
            AssertAuthorityByContractInfo(info, Context.Sender);

            // Create proposal for deployment
            RequireParliamentContractAddressSet();
            var proposalCreationInput = new CreateProposalBySystemContractInput
            {
                ProposalInput = new CreateProposalInput
                {
                    ToAddress          = Context.Self,
                    ContractMethodName =
                        nameof(BasicContractZeroContainer.BasicContractZeroBase.ProposeContractCodeCheck),
                    Params = new ContractCodeCheckInput
                    {
                        ContractInput        = input.ToByteString(),
                        IsContractDeployment = false
                    }.ToByteString(),
                    OrganizationAddress = State.ContractDeploymentController.Value.OwnerAddress,
                    ExpiredTime         = Context.CurrentBlockTime.AddSeconds(ContractProposalExpirationTimePeriod)
                },
                OriginProposer = Context.Sender
            };

            Context.SendInline(State.ContractDeploymentController.Value.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput);

            // Fire event to trigger BPs checking contract code
            Context.Fire(new ContractProposed
            {
                ProposedContractInputHash = proposedContractInputHash
            });

            return(proposedContractInputHash);
        }
コード例 #5
0
        public override Hash ProposeUpdateContract(ContractUpdateInput input)
        {
            var proposedContractInputHash = CalculateHashFromInput(input);

            RegisterContractProposingData(proposedContractInputHash);

            var contractAddress = input.Address;
            var info            = State.ContractInfos[contractAddress];

            Assert(info != null, "Contract not found.");
            AssertAuthorityByContractInfo(info, Context.Sender);

            // Create proposal for contract update
            var proposalCreationInput = new CreateProposalBySystemContractInput
            {
                ProposalInput = new CreateProposalInput
                {
                    ToAddress          = Context.Self,
                    ContractMethodName =
                        nameof(BasicContractZeroImplContainer.BasicContractZeroImplBase.ProposeContractCodeCheck),
                    Params = new ContractCodeCheckInput
                    {
                        ContractInput             = input.ToByteString(),
                        CodeCheckReleaseMethod    = nameof(UpdateSmartContract),
                        ProposedContractInputHash = proposedContractInputHash,
                        Category         = info.Category,
                        IsSystemContract = info.IsSystemContract
                    }.ToByteString(),
                    OrganizationAddress = State.ContractDeploymentController.Value.OwnerAddress,
                    ExpiredTime         = Context.CurrentBlockTime.AddSeconds(ContractProposalExpirationTimePeriod),
                },
                OriginProposer = Context.Sender
            };

            Context.SendInline(State.ContractDeploymentController.Value.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput);

            Context.Fire(new ContractProposed
            {
                ProposedContractInputHash = proposedContractInputHash
            });

            return(proposedContractInputHash);
        }
コード例 #6
0
        public override Hash ProposeContractCodeCheck(ContractCodeCheckInput input)
        {
            RequireSenderAuthority(State.ContractDeploymentController.Value.OwnerAddress);
            // AssertDeploymentProposerAuthority(Context.Origin);
            var proposedContractInputHash = Hash.FromRawBytes(input.ContractInput.ToByteArray());
            var proposedInfo = State.ContractProposingInputMap[proposedContractInputHash];

            Assert(proposedInfo != null && proposedInfo.Status == ContractProposingInputStatus.Approved,
                   "Invalid contract proposing status.");
            proposedInfo.Status = ContractProposingInputStatus.PreCodeChecked;
            State.ContractProposingInputMap[proposedContractInputHash] = proposedInfo;

            RequireParliamentContractAddressSet();

            var codeCheckController   = State.CodeCheckController.Value;
            var proposalCreationInput = new CreateProposalBySystemContractInput
            {
                ProposalInput = new CreateProposalInput
                {
                    ToAddress          = Context.Self,
                    ContractMethodName = input.IsContractDeployment
                        ? nameof(BasicContractZeroContainer.BasicContractZeroBase.DeploySmartContract)
                        : nameof(BasicContractZeroContainer.BasicContractZeroBase.UpdateSmartContract),
                    Params = input.ContractInput,
                    OrganizationAddress = codeCheckController.OwnerAddress,
                    ExpiredTime         = Context.CurrentBlockTime.AddSeconds(CodeCheckProposalExpirationTimePeriod)
                },
                OriginProposer = proposedInfo.Proposer
            };

            // Create proposal for deployment
            Context.SendInline(codeCheckController.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput);

            // Fire event to trigger BPs checking contract code
            Context.Fire(new CodeCheckRequired
            {
                Code = ExtractCodeFromContractCodeCheckInput(input),
                ProposedContractInputHash = proposedContractInputHash
            });

            return(proposedContractInputHash);
        }
コード例 #7
0
        public override Hash ProposeContractCodeCheck(ContractCodeCheckInput input)
        {
            RequireSenderAuthority(State.ContractDeploymentController.Value.OwnerAddress);
            AssertCodeCheckProposingInput(input);
            var proposedContractInputHash = input.ProposedContractInputHash;
            var proposedInfo = State.ContractProposingInputMap[proposedContractInputHash];

            Assert(proposedInfo != null && proposedInfo.Status == ContractProposingInputStatus.Approved,
                   "Invalid contract proposing status.");
            proposedInfo.Status = ContractProposingInputStatus.CodeCheckProposed;
            State.ContractProposingInputMap[proposedContractInputHash] = proposedInfo;

            var codeCheckController   = State.CodeCheckController.Value;
            var proposalCreationInput = new CreateProposalBySystemContractInput
            {
                ProposalInput = new CreateProposalInput
                {
                    ToAddress           = Context.Self,
                    ContractMethodName  = input.CodeCheckReleaseMethod,
                    Params              = input.ContractInput,
                    OrganizationAddress = codeCheckController.OwnerAddress,
                    ExpiredTime         = Context.CurrentBlockTime.AddSeconds(CodeCheckProposalExpirationTimePeriod)
                },
                OriginProposer = proposedInfo.Proposer
            };

            proposedInfo.ExpiredTime = proposalCreationInput.ProposalInput.ExpiredTime;
            State.ContractProposingInputMap[proposedContractInputHash] = proposedInfo;
            Context.SendInline(codeCheckController.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput);

            // Fire event to trigger BPs checking contract code
            Context.Fire(new CodeCheckRequired
            {
                Code = ExtractCodeFromContractCodeCheckInput(input),
                ProposedContractInputHash = proposedContractInputHash,
                Category         = input.Category,
                IsSystemContract = input.IsSystemContract
            });

            return(proposedContractInputHash);
        }
コード例 #8
0
ファイル: BasicContractZero.cs プロジェクト: zhoujue1110/AElf
        public override Hash ProposeNewContract(ContractDeploymentInput input)
        {
            // AssertDeploymentProposerAuthority(Context.Sender);
            var proposedContractInputHash = CalculateHashFromInput(input);

            RegisterContractProposingData(proposedContractInputHash);

            // Create proposal for deployment
            var proposalCreationInput = new CreateProposalBySystemContractInput
            {
                ProposalInput = new CreateProposalInput
                {
                    ToAddress          = Context.Self,
                    ContractMethodName =
                        nameof(BasicContractZeroContainer.BasicContractZeroBase.ProposeContractCodeCheck),
                    Params = new ContractCodeCheckInput
                    {
                        ContractInput             = input.ToByteString(),
                        CodeCheckReleaseMethod    = nameof(DeploySmartContract),
                        ProposedContractInputHash = proposedContractInputHash,
                        Category = input.Category
                    }.ToByteString(),
                    OrganizationAddress = State.ContractDeploymentController.Value.OwnerAddress,
                    ExpiredTime         = Context.CurrentBlockTime.AddSeconds(ContractProposalExpirationTimePeriod)
                },
                OriginProposer = Context.Sender
            };

            Context.SendInline(State.ContractDeploymentController.Value.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput.ToByteString());

            Context.Fire(new ContractProposed
            {
                ProposedContractInputHash = proposedContractInputHash
            });

            return(proposedContractInputHash);
        }
コード例 #9
0
        private void ProposeCrossChainBlockData(CrossChainBlockData crossChainBlockData, Address proposer)
        {
            var crossChainIndexingController = GetCrossChainIndexingController();
            var proposalCreationInput        = new CreateProposalBySystemContractInput
            {
                ProposalInput = new CreateProposalInput
                {
                    Params = new RecordCrossChainDataInput
                    {
                        ProposedCrossChainData = crossChainBlockData,
                        Proposer = proposer
                    }.ToByteString(),
                ContractMethodName  = nameof(RecordCrossChainData),
                ExpiredTime         = Context.CurrentBlockTime.AddSeconds(CrossChainIndexingProposalExpirationTimePeriod),
                OrganizationAddress = crossChainIndexingController.OwnerAddress,
                ToAddress           = Context.Self
                },
                ProposalIdFeedbackMethod = nameof(FeedbackCrossChainIndexingProposalId),
                OriginProposer           = Context.Sender
            };

            Context.SendInline(crossChainIndexingController.ContractAddress,
                               nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                      .CreateProposalBySystemContract), proposalCreationInput);
            var crossChainIndexingProposal = new CrossChainIndexingProposal
            {
                Proposer = proposer,
                ProposedCrossChainBlockData = crossChainBlockData
            };

            SetCrossChainIndexingProposalStatus(crossChainIndexingProposal, CrossChainIndexingProposalStatus.Proposed);

            Context.Fire(new CrossChainIndexingDataProposedEvent
            {
                ProposedCrossChainData = crossChainBlockData
            });
        }
コード例 #10
0
        private void ProposeCrossChainBlockData(CrossChainDataDto crossChainDataDto, Address proposer)
        {
            var crossChainIndexingController = GetCrossChainIndexingController();

            foreach (var chainId in crossChainDataDto.GetChainIdList())
            {
                Assert(!TryGetIndexingProposal(chainId, out _), "Chain indexing already proposed.");
                var proposalToken =
                    HashHelper.ConcatAndCompute(Context.PreviousBlockHash, ConvertChainIdToHash(chainId));
                var proposalCreationInput = new CreateProposalBySystemContractInput
                {
                    ProposalInput = new CreateProposalInput
                    {
                        Params = new AcceptCrossChainIndexingProposalInput
                        {
                            ChainId = chainId
                        }.ToByteString(),
                    ContractMethodName = nameof(AcceptCrossChainIndexingProposal),
                    ExpiredTime        =
                            Context.CurrentBlockTime.AddSeconds(CrossChainIndexingProposalExpirationTimePeriod),
                    OrganizationAddress = crossChainIndexingController.OwnerAddress,
                    ToAddress           = Context.Self,
                    Token = proposalToken
                    },
                    OriginProposer = Context.Sender
                };

                Context.SendInline(crossChainIndexingController.ContractAddress,
                                   nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                          .CreateProposalBySystemContract), proposalCreationInput);

                var proposedCrossChainBlockData = new CrossChainBlockData();
                if (crossChainDataDto.ParentChainToBeIndexedData.TryGetValue(chainId,
                                                                             out var parentChainToBeIndexedData))
                {
                    proposedCrossChainBlockData.ParentChainBlockDataList.Add(parentChainToBeIndexedData);
                }
                else if (crossChainDataDto.SideChainToBeIndexedData.TryGetValue(chainId,
                                                                                out var sideChainToBeIndexedData))
                {
                    proposedCrossChainBlockData.SideChainBlockDataList.Add(sideChainToBeIndexedData);
                }

                var crossChainIndexingProposal = new ChainIndexingProposal
                {
                    ChainId  = chainId,
                    Proposer = proposer,
                    ProposedCrossChainBlockData = proposedCrossChainBlockData
                };
                var proposalId = Context.GenerateId(crossChainIndexingController.ContractAddress, proposalToken);
                crossChainIndexingProposal.ProposalId = proposalId;
                SetCrossChainIndexingProposalStatus(crossChainIndexingProposal,
                                                    CrossChainIndexingProposalStatus.Pending);
                Context.Fire(new CrossChainIndexingDataProposedEvent
                {
                    ProposedCrossChainData = proposedCrossChainBlockData,
                    ProposalId             = proposalId
                });

                Context.LogDebug(() =>
                                 $"Proposed cross chain data for chain {ChainHelper.ConvertChainIdToBase58(chainId)}");
            }
        }