Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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.");
            RequireAuthorityByContractInfo(info);

            // Create proposal for deployment
            RequireParliamentAuthAddressSet();
            State.ParliamentAuthContract.CreateProposal.Send(new CreateProposalInput
            {
                ToAddress          = Context.Self,
                ContractMethodName = nameof(BasicContractZeroContainer.BasicContractZeroBase.ProposeContractCodeCheck),
                Params             = new ContractCodeCheckInput
                {
                    ContractInput        = input.ToByteString(),
                    IsContractDeployment = false
                }.ToByteString(),
                OrganizationAddress = State.GenesisOwner.Value,
                ExpiredTime         = Context.CurrentBlockTime.AddMinutes(10) // Maybe, get the interval from configuration
            });

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

            return(proposedContractInputHash);
        }