コード例 #1
0
 internal static CryptoGetAccountBalanceQuery ForAccount(AddressOrAlias account)
 {
     return(new CryptoGetAccountBalanceQuery
     {
         AccountID = new AccountID(account)
     });
 }
コード例 #2
0
 internal TokenWipeAccountTransactionBody(Hashgraph.Address token, AddressOrAlias address, ulong amount) : this()
 {
     if (amount == 0)
     {
         throw new ArgumentOutOfRangeException(nameof(amount), "The amount to confiscate must be greater than zero.");
     }
     Token   = new TokenID(token);
     Account = new AccountID(address);
     Amount  = amount;
 }
コード例 #3
0
    public void AddressCastAsObjectIsconsideredEqual()
    {
        var    shardNum       = Generator.Integer(0, 200);
        var    realmNum       = Generator.Integer(0, 200);
        var    accountNum     = Generator.Integer(0, 200);
        var    addressOrAlias = new AddressOrAlias(new Address(shardNum, realmNum, accountNum));
        object equivalent     = new AddressOrAlias(new Address(shardNum, realmNum, accountNum));

        Assert.True(addressOrAlias.Equals(equivalent));
        Assert.True(equivalent.Equals(addressOrAlias));
    }
コード例 #4
0
    public void AliasCastAsObjectIsconsideredEqual()
    {
        var shardNum = Generator.Integer(0, 200);
        var realmNum = Generator.Integer(0, 200);

        var(publicKey, _) = Generator.KeyPair();
        var    alias      = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));
        object equivalent = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));

        Assert.True(alias.Equals(equivalent));
        Assert.True(equivalent.Equals(alias));
    }
コード例 #5
0
    public void OtherObjectsAreNotConsideredEqual()
    {
        var shardNum   = Generator.Integer(0, 200);
        var realmNum   = Generator.Integer(0, 200);
        var accountNum = Generator.Integer(0, 200);

        var(publicKey, _) = Generator.KeyPair();
        var addressOrAlias1 = new AddressOrAlias(new Address(shardNum, realmNum, accountNum));
        var addressOrAlias2 = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));

        Assert.False(addressOrAlias1.Equals("Something that is not an addressOrAlias"));
        Assert.False(addressOrAlias2.Equals("Something that is not an Alias"));
    }
コード例 #6
0
 internal CryptoDeleteTransactionBody(AddressOrAlias addressToDelete, AddressOrAlias transferToAddress) : this()
 {
     if (addressToDelete is null)
     {
         throw new ArgumentNullException(nameof(addressToDelete), "Address to Delete is missing. Please check that it is not null.");
     }
     if (transferToAddress is null)
     {
         throw new ArgumentNullException(nameof(transferToAddress), "Transfer address is missing. Please check that it is not null.");
     }
     DeleteAccountID   = new AccountID(addressToDelete);
     TransferAccountID = new AccountID(transferToAddress);
 }
コード例 #7
0
 internal TokenWipeAccountTransactionBody(Asset asset, AddressOrAlias address) : this()
 {
     if (Hashgraph.Asset.None.Equals(asset))
     {
         throw new ArgumentOutOfRangeException(nameof(asset), "The asset to confiscate is missing.");
     }
     if (Hashgraph.Address.None.Equals(address))
     {
         throw new ArgumentOutOfRangeException(nameof(address), "The account Addresss can not be empty or None.  Please provide a valid value.");
     }
     Token   = new TokenID(asset);
     Account = new AccountID(address);
     SerialNumbers.Add(asset.SerialNum);
 }
コード例 #8
0
    public void NullAddressAreNotConsideredEqual()
    {
        object asNull         = null;
        var    shardNum       = Generator.Integer(0, 200);
        var    realmNum       = Generator.Integer(0, 200);
        var    accountNum     = Generator.Integer(0, 200);
        var    addressOrAlias = new AddressOrAlias(new Address(shardNum, realmNum, accountNum));

        Assert.False(addressOrAlias == null);
        Assert.False(null == addressOrAlias);
        Assert.True(addressOrAlias != null);
        Assert.False(addressOrAlias.Equals(null));
        Assert.False(addressOrAlias.Equals(asNull));
    }
コード例 #9
0
    public void NullAliasesAreNotConsideredEqual()
    {
        object asNull   = null;
        var    shardNum = Generator.Integer(0, 200);
        var    realmNum = Generator.Integer(0, 200);

        var(publicKey, _) = Generator.KeyPair();
        var addressOrAlias = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));

        Assert.False(addressOrAlias == null);
        Assert.False(null == addressOrAlias);
        Assert.True(addressOrAlias != null);
        Assert.False(addressOrAlias.Equals(null));
        Assert.False(addressOrAlias.Equals(asNull));
    }
コード例 #10
0
    public void AddressAndAliasTypesAreNotEquivalent()
    {
        var shardNum = Generator.Integer(0, 200);
        var realmNum = Generator.Integer(0, 200);
        var acctNum  = Generator.Integer(0, 200);

        var(publicKey1, _) = Generator.KeyPair();
        var(publicKey2, _) = Generator.KeyPair();
        var addressOrAlias1 = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey1));
        var addressOrAlias2 = new AddressOrAlias(new Address(shardNum, realmNum, acctNum));

        Assert.NotEqual(addressOrAlias1, addressOrAlias2);
        Assert.False(addressOrAlias1 == addressOrAlias2);
        Assert.True(addressOrAlias1 != addressOrAlias2);
        Assert.False(addressOrAlias1.Equals(addressOrAlias2));
    }
コード例 #11
0
    public void DisimilarAddressAreNotConsideredEqual()
    {
        var shardNum        = Generator.Integer(0, 200);
        var realmNum        = Generator.Integer(0, 200);
        var accountNum      = Generator.Integer(0, 200);
        var addressOrAlias1 = new AddressOrAlias(new Address(shardNum, realmNum, accountNum));

        Assert.NotEqual(addressOrAlias1, new AddressOrAlias(new Address(shardNum, realmNum + 1, accountNum)));
        Assert.NotEqual(addressOrAlias1, new AddressOrAlias(new Address(shardNum + 1, realmNum, accountNum)));
        Assert.NotEqual(addressOrAlias1, new AddressOrAlias(new Address(shardNum, realmNum, accountNum + 1)));
        Assert.False(addressOrAlias1 == new AddressOrAlias(new Address(shardNum, realmNum, accountNum + 1)));
        Assert.True(addressOrAlias1 != new AddressOrAlias(new Address(shardNum, realmNum, accountNum + 1)));
        Assert.False(addressOrAlias1.Equals(new AddressOrAlias(new Address(shardNum + 1, realmNum, accountNum))));
        Assert.False(addressOrAlias1.Equals(new AddressOrAlias(new Address(shardNum, realmNum + 1, accountNum))));
        Assert.False(addressOrAlias1.Equals(new AddressOrAlias(new Address(shardNum, realmNum, accountNum + 1))));
    }
コード例 #12
0
    public void EquivalentAliasAreConsideredEqual()
    {
        var shardNum = Generator.Integer(0, 200);
        var realmNum = Generator.Integer(0, 200);

        var(publicKey, _) = Generator.KeyPair();
        var addressOrAlias1 = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));
        var addressOrAlias2 = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));

        Assert.Equal(addressOrAlias1, addressOrAlias2);
        Assert.True(addressOrAlias1 == addressOrAlias2);
        Assert.False(addressOrAlias1 != addressOrAlias2);
        Assert.True(addressOrAlias1.Equals(addressOrAlias2));
        Assert.True(addressOrAlias2.Equals(addressOrAlias1));
        Assert.True(null as Alias == null as Alias);
    }
コード例 #13
0
 internal AccountID(AddressOrAlias account) : this()
 {
     if (account is null)
     {
         throw new ArgumentNullException(nameof(account), "Account Address/Alias is missing. Please check that it is not null.");
     }
     ShardNum = account.ShardNum;
     RealmNum = account.RealmNum;
     if (account.Endorsement is null)
     {
         AccountNum = account.AccountNum;
     }
     else
     {
         Alias = new Key(account.Endorsement).ToByteString();
     }
 }
コード例 #14
0
    public void EquivalentAddressAreConsideredEqual()
    {
        var shardNum        = Generator.Integer(0, 200);
        var realmNum        = Generator.Integer(0, 200);
        var accountNum      = Generator.Integer(0, 200);
        var address1        = new Address(shardNum, realmNum, accountNum);
        var address2        = new Address(shardNum, realmNum, accountNum);
        var addressOrAlias1 = new AddressOrAlias(address1);
        var addressOrAlias2 = new AddressOrAlias(address2);

        Assert.Equal(addressOrAlias1, addressOrAlias2);
        Assert.True(addressOrAlias1 == addressOrAlias2);
        Assert.False(addressOrAlias1 != addressOrAlias2);
        Assert.True(addressOrAlias1.Equals(addressOrAlias2));
        Assert.True(addressOrAlias2.Equals(addressOrAlias1));
        Assert.True(null as AddressOrAlias == null as AddressOrAlias);
    }
コード例 #15
0
    public void ReferenceEqualIsconsideredEqual()
    {
        var shardNum   = Generator.Integer(0, 200);
        var realmNum   = Generator.Integer(0, 200);
        var accountNum = Generator.Integer(0, 200);

        var(publicKey, _) = Generator.KeyPair();
        var    addressOrAlias1 = new AddressOrAlias(new Address(shardNum, realmNum, accountNum));
        var    addressOrAlias2 = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey));
        object reference1      = addressOrAlias1;
        object reference2      = addressOrAlias2;

        Assert.True(addressOrAlias1.Equals(reference1));
        Assert.True(reference1.Equals(addressOrAlias1));
        Assert.True(addressOrAlias2.Equals(reference2));
        Assert.True(reference2.Equals(addressOrAlias2));
    }
コード例 #16
0
    public void DisimilarAliasesAreNotConsideredEqual()
    {
        var shardNum = Generator.Integer(0, 200);
        var realmNum = Generator.Integer(0, 200);

        var(publicKey1, _) = Generator.KeyPair();
        var(publicKey2, _) = Generator.KeyPair();
        var alias1 = new AddressOrAlias(new Alias(shardNum, realmNum, publicKey1));

        Assert.NotEqual(alias1, new AddressOrAlias(new Alias(shardNum, realmNum + 1, publicKey1)));
        Assert.NotEqual(alias1, new AddressOrAlias(new Alias(shardNum + 1, realmNum, publicKey1)));
        Assert.NotEqual(alias1, new AddressOrAlias(new Alias(shardNum, realmNum, publicKey2)));
        Assert.False(alias1 == new AddressOrAlias(new Alias(shardNum, realmNum, publicKey2)));
        Assert.True(alias1 != new AddressOrAlias(new Alias(shardNum, realmNum, publicKey2)));
        Assert.False(alias1.Equals(new AddressOrAlias(new Alias(shardNum + 1, realmNum, publicKey1))));
        Assert.False(alias1.Equals(new AddressOrAlias(new Alias(shardNum, realmNum + 1, publicKey1))));
        Assert.False(alias1.Equals(new AddressOrAlias(new Alias(shardNum, realmNum, publicKey2))));
    }
コード例 #17
0
 internal TokenTransferList(Address token, AddressOrAlias fromAddress, AddressOrAlias toAddress, long amount) : this()
 {
     if (fromAddress is null)
     {
         throw new ArgumentNullException(nameof(toAddress), "Account to transfer from is missing. Please check that it is not null.");
     }
     if (toAddress is null)
     {
         throw new ArgumentNullException(nameof(toAddress), "Account to transfer to is missing. Please check that it is not null.");
     }
     if (amount < 1)
     {
         throw new ArgumentOutOfRangeException(nameof(amount), "The amount to transfer must be non-negative.");
     }
     Token = new TokenID(token);
     Transfers.Add(new AccountAmount(fromAddress, -amount));
     Transfers.Add(new AccountAmount(toAddress, amount));
 }
コード例 #18
0
    internal CryptoTransferTransactionBody(AddressOrAlias fromAddress, AddressOrAlias toAddress, long amount) : this()
    {
        if (fromAddress is null)
        {
            throw new ArgumentNullException(nameof(fromAddress), "Account to transfer from is missing. Please check that it is not null.");
        }
        if (toAddress is null)
        {
            throw new ArgumentNullException(nameof(toAddress), "Account to transfer to is missing. Please check that it is not null.");
        }
        if (amount < 1)
        {
            throw new ArgumentOutOfRangeException(nameof(amount), "The amount to transfer must be non-negative.");
        }
        var xferList = new TransferList();

        xferList.AccountAmounts.Add(new AccountAmount(fromAddress, -amount));
        xferList.AccountAmounts.Add(new AccountAmount(toAddress, amount));
        Transfers = xferList;
    }
コード例 #19
0
 internal TokenDissociateTransactionBody(IEnumerable <Address> tokens, AddressOrAlias account) : this()
 {
     if (tokens is null)
     {
         throw new ArgumentNullException(nameof(tokens), "The list of tokens cannot be null.");
     }
     Tokens.AddRange(tokens.Select(token =>
     {
         if (token.IsNullOrNone())
         {
             throw new ArgumentOutOfRangeException(nameof(tokens), "The list of tokens cannot contain an empty or null address.");
         }
         return(new TokenID(token));
     }));
     if (Tokens.Count == 0)
     {
         throw new ArgumentOutOfRangeException(nameof(tokens), "The list of tokens cannot be empty.");
     }
     Account = new AccountID(account);
 }
コード例 #20
0
 internal TokenTransferList(Asset asset, AddressOrAlias fromAddress, AddressOrAlias toAddress) : this()
 {
     if (asset is null)
     {
         throw new ArgumentNullException(nameof(asset), "Asset to transfer is missing. Please check that it is not null.");
     }
     if (fromAddress is null)
     {
         throw new ArgumentNullException(nameof(fromAddress), "Account to transfer from is missing. Please check that it is not null.");
     }
     if (toAddress is null)
     {
         throw new ArgumentNullException(nameof(toAddress), "Account to transfer to is missing. Please check that it is not null.");
     }
     Token = new TokenID(asset);
     NftTransfers.Add(new NftTransfer
     {
         SenderAccountID   = new AccountID(fromAddress),
         ReceiverAccountID = new AccountID(toAddress),
         SerialNumber      = asset.SerialNum
     });
 }
コード例 #21
0
    /// <summary>
    /// Helper method to retrieve just the balance of a single token for
    /// a given address.  Under the hood it is calling <see cref="Client.GetAccountBalancesAsync(Address, Action{IContext}?)"/>
    /// </summary>
    /// <param name="client">
    /// The client
    /// </param>
    /// <param name="address">
    /// Address of the account to look up.
    /// </param>
    /// <param name="token">
    /// Address of the token to look up (symbol name is not supported)
    /// </param>
    /// <param name="configure">
    /// Optional callback method providing an opportunity to modify
    /// the execution configuration for just this method call.
    /// It is executed prior to submitting the request to the network.
    /// </param>
    /// <returns></returns>
    public static async Task <ulong> GetAccountTokenBalanceAsync(this Client client, AddressOrAlias address, Address token, Action <IContext>?configure = null)
    {
        var balances = await client.GetAccountBalancesAsync(address, configure).ConfigureAwait(false);

        return(balances.Tokens.TryGetValue(token, out CryptoBalance? crypto) ? crypto.Balance : 0);
    }
コード例 #22
0
 /// <summary>
 /// Transfer tokens from one account to another.
 /// </summary>
 /// <param name="token">
 /// The identifier (Address/Symbol) of the token to transfer.
 /// </param>
 /// <param name="fromAddress">
 /// The address to transfer the tokens from.  Ensure that
 /// a signatory either in the context or passed with this
 /// call can fulfill the signing requrements to transfer
 /// crypto out of the account identified by this address.
 /// </param>
 /// <param name="toAddress">
 /// The address receiving the tokens.
 /// </param>
 /// <param name="amount">
 /// The amount of tokens to transfer.
 /// </param>
 /// <param name="signatory">
 /// The signatory containing any additional private keys or callbacks
 /// to meet the requirements for the sending and receiving accounts.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A transfer receipt indicating success of the operation.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
 /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
 public async Task <TransactionReceipt> TransferTokensAsync(Address token, AddressOrAlias fromAddress, AddressOrAlias toAddress, long amount, Signatory signatory, Action <IContext>?configure = null)
 {
     return(new TransactionReceipt(await ExecuteTransactionAsync(new CryptoTransferTransactionBody(token, fromAddress, toAddress, amount), configure, false, signatory).ConfigureAwait(false)));
 }
コード例 #23
0
 /// <summary>
 /// Transfer tokens from one account to another.
 /// </summary>
 /// <param name="token">
 /// The identifier (Address/Symbol) of the token to transfer.
 /// </param>
 /// <param name="fromAddress">
 /// The address to transfer the tokens from.  Ensure that
 /// a signatory either in the context can fulfill the signing
 /// requrements to transfer crypto out of the account identified
 /// by this address.
 /// </param>
 /// <param name="toAddress">
 /// The address receiving the tokens.
 /// </param>
 /// <param name="amount">
 /// The amount of tokens to transfer.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A transfer record describing the details of the concensus transaction.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
 /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
 public async Task <TransactionRecord> TransferTokensWithRecordAsync(Address token, AddressOrAlias fromAddress, AddressOrAlias toAddress, long amount, Action <IContext>?configure = null)
 {
     return(new TransactionRecord(await ExecuteTransactionAsync(new CryptoTransferTransactionBody(token, fromAddress, toAddress, amount), configure, true).ConfigureAwait(false)));
 }
コード例 #24
0
 internal CryptoGetStakersQuery(AddressOrAlias address) : this()
 {
     AccountID = new AccountID(address);
 }
コード例 #25
0
    /// <summary>
    /// Retreives the accounts that are proxy staking to this account.
    /// </summary>
    /// <param name="address">
    /// The Hedera Network Address to retrieve the stakers of.
    /// </param>
    /// <param name="configure">
    /// Optional callback method providing an opportunity to modify
    /// the execution configuration for just this method call.
    /// It is executed prior to submitting the request to the network.
    /// </param>
    /// <returns>
    /// A dictionary mapping account addresses to the amount of stake.
    /// </returns>
    /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
    /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
    /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
    ///
    /// <remarks>
    /// Marked internal at this point because it is not yet implemented by the network
    /// </remarks>
    internal async Task <Dictionary <Address, long> > GetStakers(AddressOrAlias address, Action <IContext>?configure = null)
    {
        var response = await ExecuteQueryAsync(new CryptoGetStakersQuery(address), configure).ConfigureAwait(false);

        return(response.CryptoGetProxyStakers.Stakers.ProxyStaker.ToDictionary(ps => ps.AccountID.AsAddress(), ps => ps.Amount));
    }
コード例 #26
0
 /// <summary>
 /// Deletes an account from the network returning the remaining
 /// crypto balance to the specified account.  Must be signed
 /// by the account being deleted.
 /// </summary>
 /// <param name="addressToDelete">
 /// The address for account that will be deleted.
 /// </param>
 /// <param name="transferToAddress">
 /// The account that will receive any remaining balance from the deleted account.
 /// </param>
 /// <param name="signatory">
 /// The signatory containing any additional private keys or callbacks
 /// to meet the requirements for deleting the account and transferring
 /// the remaining crypto balance.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A transaction receipt indicating a successful operation.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
 /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
 public async Task <TransactionReceipt> DeleteAccountAsync(AddressOrAlias addressToDelete, AddressOrAlias transferToAddress, Signatory signatory, Action <IContext>?configure = null)
 {
     return(new TransactionReceipt(await ExecuteTransactionAsync(new CryptoDeleteTransactionBody(addressToDelete, transferToAddress), configure, false, signatory).ConfigureAwait(false)));
 }
コード例 #27
0
 internal CryptoGetAccountRecordsQuery(AddressOrAlias address) : this()
 {
     AccountID = new AccountID(address);
 }
コード例 #28
0
 internal TokenFreezeAccountTransactionBody(Address token, AddressOrAlias address) : this()
 {
     Token   = new TokenID(token);
     Account = new AccountID(address);
 }
コード例 #29
0
 internal AccountAmount(AddressOrAlias psudoAddress, long amount) : this()
 {
     AccountID = new AccountID(psudoAddress);
     Amount    = amount;
 }
コード例 #30
0
 /// <summary>
 /// Retrieves detailed information regarding a Hedera Network Account.
 /// </summary>
 /// <param name="address">
 /// The Hedera Network Address to retrieve detailed information of.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A detailed description of the account.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 public async Task <AccountInfo> GetAccountInfoAsync(AddressOrAlias address, Action <IContext>?configure = null)
 {
     return(new AccountInfo(await ExecuteQueryAsync(new CryptoGetInfoQuery(address), configure).ConfigureAwait(false)));
 }