Esempio n. 1
0
        public override BoolValue Approve(ApproveInput input)
        {
            var proposal = GetValidProposal(input.ProposalId);

            Assert(input.Quantity > 0, "Invalid vote.");
            var lockAmount = input.Quantity;

            Assert(State.LockedTokenAmount[Context.Sender][input.ProposalId] == null, "Cannot approve more than once.");
            State.ApprovedTokenAmount[input.ProposalId] =
                State.ApprovedTokenAmount[input.ProposalId].Add(lockAmount);

            var organization = State.Organisations[proposal.OrganizationAddress];

            LockToken(new LockInput
            {
                Address = Context.Sender,
                Symbol  = organization.TokenSymbol,
                Amount  = lockAmount,
                LockId  = Context.TransactionId,
                Usage   = "Referendum."
            });
            // Register receipt
            State.LockedTokenAmount[Context.Sender][input.ProposalId] = new Receipt
            {
                Amount      = lockAmount,
                LockId      = Context.TransactionId,
                TokenSymbol = organization.TokenSymbol
            };
            return(new BoolValue {
                Value = true
            });
        }
Esempio n. 2
0
        public override BoolValue Approve(ApproveInput approval)
        {
            var proposalInfo = State.Proposals[approval.ProposalId];

            Assert(proposalInfo != null, "Proposal not found.");
            DateTime timestamp = proposalInfo.ExpiredTime.ToDateTime();

            if (Context.CurrentBlockTime > timestamp)
            {
                // expired proposal
                //State.Proposals[approval.ProposalId] = null;
                return(new BoolValue {
                    Value = false
                });
            }
            Assert(approval.Quantity > 0, "Invalid vote.");
            var lockedTokenAmount = approval.Quantity;

            Assert(State.LockedTokenAmount[Context.Sender][approval.ProposalId] == null,
                   "Cannot approve more than once.");
            var organization = GetOrganization(proposalInfo.OrganizationAddress);

            State.LockedTokenAmount[Context.Sender][approval.ProposalId] = new Receipt
            {
                Amount      = lockedTokenAmount,
                LockId      = Context.TransactionId,
                TokenSymbol = organization.TokenSymbol
            };
            State.ApprovedTokenAmount[approval.ProposalId] += lockedTokenAmount;

            LockToken(new LockInput
            {
                From   = Context.Sender,
                To     = Context.Self,
                Symbol = organization.TokenSymbol,
                Amount = lockedTokenAmount,
                LockId = Context.TransactionId,
                Usage  = "Referendum."
            });

            if (IsReadyToRelease(approval.ProposalId, organization))
            {
                Context.SendVirtualInline(organization.OrganizationHash, proposalInfo.ToAddress, proposalInfo.ContractMethodName,
                                          proposalInfo.Params);
                //State.Proposals[approval.ProposalId] = null;
            }
            return(new BoolValue {
                Value = true
            });
        }
Esempio n. 3
0
        public override BoolValue Approve(ApproveInput approval)
        {
            var proposalInfo = State.Proposals[approval.ProposalId];

            Assert(proposalInfo != null, "Proposal not found.");
            if (Context.CurrentBlockTime > proposalInfo.ExpiredTime)
            {
                // expired proposal
                //State.Proposals[approval.ProposalId] = null;
                return(new BoolValue {
                    Value = false
                });
            }
            Assert(approval.Quantity > 0, "Invalid vote.");
            var lockedTokenAmount = approval.Quantity;

            Assert(State.LockedTokenAmount[Context.Sender][approval.ProposalId] == null,
                   "Cannot approve more than once.");
            var organization = GetOrganization(proposalInfo.OrganizationAddress);

            State.LockedTokenAmount[Context.Sender][approval.ProposalId] = new Receipt
            {
                Amount      = lockedTokenAmount,
                LockId      = Context.TransactionId,
                TokenSymbol = organization.TokenSymbol
            };
            State.ApprovedTokenAmount[approval.ProposalId] += lockedTokenAmount;

            LockToken(new LockInput
            {
                Address = Context.Sender,
                Symbol  = organization.TokenSymbol,
                Amount  = lockedTokenAmount,
                LockId  = Context.TransactionId,
                Usage   = "Referendum."
            });

            return(new BoolValue {
                Value = true
            });
        }