コード例 #1
0
        public IReadOnlyTaggedTokens Tag(Address owner, BigInteger amount)
        {
            if (amount <= 0)
            {
                throw new NonPositiveTokenAmountException(nameof(amount), amount);
            }

            var tokens = new ReadOnlyTaggedTokens(new SortedDictionary <string, BigInteger>
            {
                [TokenTag] = amount,
            });

            return(tokens);
        }
コード例 #2
0
        public void Mint_WhenMintingToSplitter_ShouldSplitToRecipients(int splitAmount)
        {
            this.registry.SendMessage(this.permissionManager, this.tokenManager, MintAction.Type, new Dictionary <string, object>()
            {
                { MintAction.To, this.splitter.ToString() },
                { MintAction.Amount, splitAmount.ToString() },
            });

            foreach (Address recipient in this.recipients)
            {
                BigInteger expectedBalance = splitAmount / this.recipients.Count;
                BigInteger actualBalance   = new ReadOnlyTaggedTokens(
                    this.registry.GetContract(this.tokenManager).GetState()
                    .GetDictionary("Balances")
                    .GetDictionary(recipient.ToString()) ?? new Dictionary <string, object>()).TotalBalance;
                Assert.Equal(expectedBalance, actualBalance);
            }
        }
コード例 #3
0
        public IReadOnlyTaggedTokens Pick(IReadOnlyTaggedTokens tokens, BigInteger amount)
        {
            if (amount < 0)
            {
                throw new NonPositiveTokenAmountException(nameof(amount), amount);
            }

            BigInteger availableTokens = tokens.TotalBalanceByTag(TokenTag);

            if (availableTokens < amount)
            {
                throw new InsufficientTokenAmountException(nameof(amount), availableTokens, amount);
            }

            var pickedTokens = new ReadOnlyTaggedTokens(new SortedDictionary <string, BigInteger>
            {
                [TokenTag] = amount,
            });

            return(pickedTokens);
        }