Exemplo n.º 1
0
    public async Task RunTest()
    {
        await using var client = _network.NewClient();

        // Build a TX from Scratch, Including a Signature
        var txid      = client.CreateNewTxId();
        var transfers = new Proto.TransferList();

        transfers.AccountAmounts.Add(new Proto.AccountAmount
        {
            AccountID = new Proto.AccountID(_network.Payer),
            Amount    = -1
        });
        transfers.AccountAmounts.Add(new Proto.AccountAmount
        {
            AccountID = new Proto.AccountID(_network.Gateway),
            Amount    = 1
        });
        var body = new Proto.TransactionBody
        {
            TransactionID            = new Proto.TransactionID(txid),
            NodeAccountID            = new Proto.AccountID(_network.Gateway),
            TransactionFee           = 30_00_000_000,
            TransactionValidDuration = new Proto.Duration {
                Seconds = 180
            },
            Memo           = "Unsafe Test",
            CryptoTransfer = new Proto.CryptoTransferTransactionBody {
                Transfers = transfers
            }
        };
        var invoice = new Invoice(body, 6);

        await(_network.Signatory as ISignatory).SignAsync(invoice);
        var transaction = new Proto.Transaction
        {
            SignedTransactionBytes = invoice.GenerateSignedTransactionFromSignatures().ToByteString()
        };

        using (new ConsoleRedirector(_network.Output))
        {
            var arg0 = _network.Gateway.Url;
            var arg1 = _network.Gateway.AccountNum.ToString();
            var arg2 = _network.Payer.AccountNum.ToString();
            var arg3 = Hex.FromBytes(_network.PrivateKey);
            var arg4 = Hex.FromBytes(transaction.ToByteArray());
            await Main(new string[] { arg0, arg1, arg2, arg3, arg4 });
        }
    }
}
Exemplo n.º 2
0
    public async Task SubmitUnsafeTransaction()
    {
        await using var client = _network.NewClient();
        var systemAddress = await _network.GetSystemAccountAddress();

        if (systemAddress is null)
        {
            _network.Output?.WriteLine("TEST SKIPPED: No access to System Administrator Account.");
            return;
        }
        // Ok, lets build a TX from Scratch, Including a Signature
        var txid      = client.CreateNewTxId();
        var transfers = new Proto.TransferList();

        transfers.AccountAmounts.Add(new Proto.AccountAmount
        {
            AccountID = new Proto.AccountID(_network.Payer),
            Amount    = -1
        });
        transfers.AccountAmounts.Add(new Proto.AccountAmount
        {
            AccountID = new Proto.AccountID(_network.Gateway),
            Amount    = 1
        });
        var body = new Proto.TransactionBody
        {
            TransactionID            = new Proto.TransactionID(txid),
            NodeAccountID            = new Proto.AccountID(_network.Gateway),
            TransactionFee           = 30_00_000_000,
            TransactionValidDuration = new Proto.Duration {
                Seconds = 180
            },
            Memo           = "Unsafe Test",
            CryptoTransfer = new Proto.CryptoTransferTransactionBody {
                Transfers = transfers
            }
        };
        var invoice = new Invoice(body, 6);

        await(_network.Signatory as ISignatory).SignAsync(invoice);
        var transaction = new Proto.Transaction
        {
            SignedTransactionBytes = invoice.GenerateSignedTransactionFromSignatures().ToByteString()
        };

        var receipt = await client.SubmitUnsafeTransactionAsync(transaction.ToByteArray(), ctx => ctx.Payer = systemAddress);

        Assert.Equal(ResponseCode.Success, receipt.Status);
        Assert.Equal(txid, receipt.Id);
    }
Exemplo n.º 3
0
    public async Task SubmitUnsafeTransactionWithRecord()
    {
        await using var client = _network.NewClient();
        var systemAddress = await _network.GetSystemAccountAddress();

        if (systemAddress is null)
        {
            _network.Output?.WriteLine("TEST SKIPPED: No access to System Administrator Account.");
            return;
        }
        // Ok, lets build a TX from Scratch, Including a Signature
        var txid      = client.CreateNewTxId();
        var transfers = new Proto.TransferList();

        transfers.AccountAmounts.Add(new Proto.AccountAmount
        {
            AccountID = new Proto.AccountID(_network.Payer),
            Amount    = -1
        });
        transfers.AccountAmounts.Add(new Proto.AccountAmount
        {
            AccountID = new Proto.AccountID(_network.Gateway),
            Amount    = 1
        });
        var body = new Proto.TransactionBody
        {
            TransactionID            = new Proto.TransactionID(txid),
            NodeAccountID            = new Proto.AccountID(_network.Gateway),
            TransactionFee           = 30_00_000_000,
            TransactionValidDuration = new Proto.Duration {
                Seconds = 180
            },
            Memo           = "Unsafe Test",
            CryptoTransfer = new Proto.CryptoTransferTransactionBody {
                Transfers = transfers
            }
        };
        var invoice = new Invoice(body, 6);

        await(_network.Signatory as ISignatory).SignAsync(invoice);
        var transaction = new Proto.Transaction
        {
            SignedTransactionBytes = invoice.GenerateSignedTransactionFromSignatures().ToByteString()
        };

        var record = await client.SubmitUnsafeTransactionWithRecordAsync(transaction.ToByteArray(), ctx => ctx.Payer = systemAddress);

        Assert.Equal(ResponseCode.Success, record.Status);
        Assert.Equal(txid, record.Id);
        Assert.False(record.Hash.IsEmpty);
        Assert.NotNull(record.Concensus);
        Assert.NotNull(record.CurrentExchangeRate);
        Assert.NotNull(record.NextExchangeRate);
        Assert.NotEmpty(record.Hash.ToArray());
        Assert.Equal("Unsafe Test", record.Memo);
        Assert.InRange(record.Fee, 0UL, ulong.MaxValue);
        Assert.Equal(_network.Payer, record.Id.Address);
        Assert.Equal(3, record.Transfers.Count);
        Assert.Equal(-1 - (long)record.Fee, record.Transfers[_network.Payer]);
    }
}
Exemplo n.º 4
0
 internal CryptoGetInfoQuery(Address address) : this()
 {
     AccountID = new AccountID(address);
 }
 internal TokenUpdateTransactionBody(Hashgraph.UpdateTokenParams updateParameters) : this()
 {
     if (updateParameters is null)
     {
         throw new ArgumentNullException(nameof(updateParameters), "Token Update Parameters argument is missing. Please check that it is not null.");
     }
     if (updateParameters.Token.IsNullOrNone())
     {
         throw new ArgumentNullException(nameof(updateParameters.Token), "The Token is missing.  Please check that it is not null or empty.");
     }
     if (updateParameters.Treasury is null &&
         updateParameters.Administrator is null &&
         updateParameters.GrantKycEndorsement is null &&
         updateParameters.SuspendEndorsement is null &&
         updateParameters.ConfiscateEndorsement is null &&
         updateParameters.SupplyEndorsement is null &&
         string.IsNullOrWhiteSpace(updateParameters.Symbol) &&
         string.IsNullOrWhiteSpace(updateParameters.Name) &&
         !updateParameters.Expiration.HasValue &&
         !updateParameters.RenewPeriod.HasValue &&
         updateParameters.RenewAccount is null &&
         updateParameters.Memo is null)
     {
         throw new ArgumentException("The Topic Updates contain no update properties, it is blank.", nameof(updateParameters));
     }
     Token = new TokenID(updateParameters.Token);
     if (!string.IsNullOrWhiteSpace(updateParameters.Symbol))
     {
         if (updateParameters.Symbol.Trim().Length != updateParameters.Symbol.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Symbol), "The new token symbol cannot contain leading or trailing white space.");
         }
         if (updateParameters.Symbol.Length > 32)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Symbol), "The new token symbol cannot exceed 32 characters in length.");
         }
         if (!updateParameters.Symbol.Equals(updateParameters.Symbol.ToUpperInvariant()))
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Symbol), "The new token symbol must contain upper case characters.");
         }
         Symbol = updateParameters.Symbol;
     }
     if (!string.IsNullOrWhiteSpace(updateParameters.Name))
     {
         if (updateParameters.Name.Trim().Length != updateParameters.Name.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Name), "The new token name cannot contain leading or trailing white space.");
         }
         Name = updateParameters.Name;
     }
     if (updateParameters.Expiration.HasValue)
     {
         if (updateParameters.Expiration.Value < DateTime.UtcNow)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Expiration), "The new expiration can not be set to the past.");
         }
         Expiry = new Timestamp(updateParameters.Expiration.Value);
     }
     if (updateParameters.RenewPeriod.HasValue)
     {
         if (updateParameters.RenewPeriod.Value.TotalSeconds < 1)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.RenewPeriod), "The renew period must be non negative.");
         }
         AutoRenewPeriod = new Duration(updateParameters.RenewPeriod.Value);
     }
     if (updateParameters.Memo is not null)
     {
         if (updateParameters.Memo.Trim().Length != updateParameters.Memo.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Memo), "The new token memo cannot contain leading or trailing white space.");
         }
         Memo = updateParameters.Memo;
     }
     if (!(updateParameters.Treasury is null))
     {
         Treasury = new AccountID(updateParameters.Treasury);
     }
     if (!(updateParameters.Administrator is null))
     {
         AdminKey = new Key(updateParameters.Administrator);
     }
     if (!(updateParameters.GrantKycEndorsement is null))
     {
         KycKey = new Key(updateParameters.GrantKycEndorsement);
     }
     if (!(updateParameters.SuspendEndorsement is null))
     {
         FreezeKey = new Key(updateParameters.SuspendEndorsement);
     }
     if (!(updateParameters.ConfiscateEndorsement is null))
     {
         WipeKey = new Key(updateParameters.ConfiscateEndorsement);
     }
     if (!(updateParameters.SupplyEndorsement is null))
     {
         SupplyKey = new Key(updateParameters.SupplyEndorsement);
     }
     if (!(updateParameters.RenewAccount is null))
     {
         AutoRenewAccount = new AccountID(updateParameters.RenewAccount);
     }
 }
Exemplo n.º 6
0
 internal TokenDissociateTransactionBody(Address token, Address account) : this()
 {
     Tokens.Add(new TokenID(token));
     Account = new AccountID(account);
 }