Beispiel #1
0
        public void ProcessProposal(ProposalCapsule proposal)
        {
            List <ByteString> active_witness = this.db_manager.WitnessSchedule.GetActiveWitnesses();

            if (proposal.HasMostApprovals(active_witness))
            {
                Logger.Info(
                    string.Format("Processing proposal,id:{0},it has received most approvals, "
                                  + "begin to set dynamic parameter:{1}, "
                                  + "and set proposal state as APPROVED",
                                  proposal.Id,
                                  proposal.Parameters));

                SetDynamicParameters(proposal);
                proposal.State = Protocol.Proposal.Types.State.Approved;
                this.db_manager.Proposal.Put(proposal.CreateDatabaseKey(), proposal);
            }
            else
            {
                Logger.Info(
                    string.Format("Processing proposal,id:{0}, "
                                  + "it has not received enough approvals, set proposal state as DISAPPROVED",
                                  proposal.Id));

                proposal.State = Protocol.Proposal.Types.State.Disapproved;
                this.db_manager.Proposal.Put(proposal.CreateDatabaseKey(), proposal);
            }
        }
Beispiel #2
0
        public override bool Execute(TransactionResultCapsule result)
        {
            long fee = CalcFee();

            try
            {
                ProposalCreateContract proposal_create_contract = this.contract.Unpack <ProposalCreateContract>();

                long id = Deposit == null?
                          this.db_manager.DynamicProperties.GetLatestProposalNum() + 1 : Deposit.GetLatestProposalNum() + 1;

                ProposalCapsule proposal = new ProposalCapsule(proposal_create_contract.OwnerAddress, id);

                proposal.Parameters = new Dictionary <long, long>(proposal_create_contract.Parameters);

                long now = this.db_manager.GetHeadBlockTimestamp();
                long maintenance_interval = Deposit == null?
                                            this.db_manager.DynamicProperties.GetMaintenanceTimeInterval() : Deposit.GetMaintenanceTimeInterval();

                proposal.CreateTime = now;

                long current_maintenance_time = Deposit == null?
                                                this.db_manager.DynamicProperties.GetNextMaintenanceTime() : Deposit.GetNextMaintenanceTime();

                long now3            = now + (int)Args.Instance.Block.ProposalExpireTime;
                long round           = (now3 - current_maintenance_time) / maintenance_interval;
                long expiration_time = current_maintenance_time + (round + 1) * maintenance_interval;
                proposal.ExpirationTime = expiration_time;

                if (Deposit == null)
                {
                    this.db_manager.Proposal.Put(proposal.CreateDatabaseKey(), proposal);
                    this.db_manager.DynamicProperties.PutLatestProposalNum(id);
                }
                else
                {
                    Deposit.PutProposalValue(proposal.CreateDatabaseKey(), proposal);
                    Deposit.PutDynamicPropertiesWithLatestProposalNum(id);
                }

                result.SetStatus(fee, code.Sucess);
            }
            catch (InvalidProtocolBufferException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            return(true);
        }
        public override bool Execute(TransactionResultCapsule result)
        {
            long fee = CalcFee();

            try
            {
                ProposalApproveContract proposal_approve_contract = this.contract.Unpack <ProposalApproveContract>();
                ProposalCapsule         proposal = Deposit == null?
                                                   this.db_manager.Proposal.Get(BitConverter.GetBytes(proposal_approve_contract.ProposalId))
                                                       : Deposit.GetProposalCapsule(BitConverter.GetBytes(proposal_approve_contract.ProposalId));

                ByteString committee_address = proposal_approve_contract.OwnerAddress;
                if (proposal_approve_contract.IsAddApproval)
                {
                    proposal.AddApproval(committee_address);
                }
                else
                {
                    proposal.RemoveApproval(committee_address);
                }

                if (Deposit == null)
                {
                    this.db_manager.Proposal.Put(proposal.CreateDatabaseKey(), proposal);
                }
                else
                {
                    deposit.PutProposalValue(proposal.CreateDatabaseKey(), proposal);
                }

                result.SetStatus(fee, code.Sucess);
            }
            catch (ItemNotFoundException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            catch (InvalidProtocolBufferException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }

            return(true);
        }
        public override bool Execute(TransactionResultCapsule result)
        {
            long fee = CalcFee();

            try
            {
                ProposalDeleteContract proposal_delete_contract = this.contract.Unpack <ProposalDeleteContract>();
                ProposalCapsule        proposal = (Deposit == null) ?
                                                  this.db_manager.Proposal.Get(BitConverter.GetBytes(proposal_delete_contract.ProposalId))
                    : Deposit.GetProposalCapsule(BitConverter.GetBytes(proposal_delete_contract.ProposalId));

                proposal.State = Proposal.Types.State.Canceled;
                if (Deposit == null)
                {
                    this.db_manager.Proposal.Put(proposal.CreateDatabaseKey(), proposal);
                }
                else
                {
                    Deposit.PutProposalValue(proposal.CreateDatabaseKey(), proposal);
                }

                result.SetStatus(fee, code.Sucess);
            }
            catch (InvalidProtocolBufferException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            catch (ItemNotFoundException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            return(true);
        }