Пример #1
0
        public async Task <string> GrantTokensAsync(
            Property property,
            BitcoinAddress from,
            BitcoinAddress?to,
            TokenAmount amount,
            string?note,
            CancellationToken cancellationToken = default)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is not valid.");
            }

            // Setup arguments.
            var args = new Collection <object>()
            {
                from.ToString(),
                ReferenceEquals(to, null) ? string.Empty : to.ToString(),
                property.Id.Value,
                amount.ToString(property.TokenType),
            };

            if (note != null)
            {
                args.Add(note);
            }

            // Invoke RPC.
            var resp = await this.Client.SendCommandAsync("elysium_sendgrant", args.ToArray());

            return(resp.Result.Value <string>());
        }
Пример #2
0
        public async Task <string> SendTokensAsync(
            Property property,
            BitcoinAddress from,
            BitcoinAddress to,
            TokenAmount amount,
            Money?referenceAmount,
            CancellationToken cancellationToken = default)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is not valid.");
            }

            // Setup arguments.
            var args = new Collection <object>()
            {
                from.ToString(),
                to.ToString(),
                property.Id.Value,
                amount.ToString(property.TokenType),
            };

            if (referenceAmount != null)
            {
                if (referenceAmount <= Money.Zero)
                {
                    throw new ArgumentOutOfRangeException(
                              nameof(referenceAmount),
                              referenceAmount,
                              "The value is not valid.");
                }

                args.Add(string.Empty); // redeemaddress, which Zcoin did not use.
                args.Add(referenceAmount.ToDecimal(MoneyUnit.BTC).ToString());
            }

            // Invoke RPC.
            var resp = await this.Client.SendCommandAsync("elysium_send", args.ToArray());

            return(resp.Result.Value <string>());
        }
Пример #3
0
        public void ToString_WithoutArguments_ShouldReturnFullTypeName()
        {
            var amount = new TokenAmount(1);

            Assert.Equal(typeof(TokenAmount).FullName, amount.ToString());
        }
Пример #4
0
        public void ToString_WithInvalidType_ShouldThrow()
        {
            var amount = new TokenAmount(0);

            Assert.Throws <ArgumentOutOfRangeException>("type", () => amount.ToString((TokenType)100));
        }
Пример #5
0
        public void ToString_WithIndivisible_ShouldSuccess(long value)
        {
            var amount = new TokenAmount(value);

            Assert.Equal(value.ToString(), amount.ToString(TokenType.Indivisible));
        }
Пример #6
0
        public void ToString_WithDivisible_ShouldSuccess(long value, string expect)
        {
            var amount = new TokenAmount(value);

            Assert.Equal(expect, amount.ToString(TokenType.Divisible));
        }