public AccountHttpTests()
 {
     _accountHttp = new AccountHttp(BaseUrl)
     {
         NetworkType = NetworkType.MIJIN_TEST
     };
 }
 public AccountHttpTests(ITestOutputHelper log)
 {
     _accountHttp = new AccountHttp(BaseUrl)
     {
         NetworkType = NetworkType.TEST_NET
     };
     Log = log;
 }
Ejemplo n.º 3
0
        public static async Task GetAccInfo()
        {
            var accountHttp = new AccountHttp(host);
            var address     = Address.CreateFromEncoded("TCTUIF-557ZCQ-OQPW2M-6GH4TC-DPM2ZY-BBL54K-GNHR");
            var accountInfo = await accountHttp.GetAccountInfo(address);

            Console.WriteLine(accountInfo.Address.Pretty);
        }
 public NamespaceHttpTests()
 {
     _namespaceHttp = new NamespaceHttp(BaseUrl)
     {
         NetworkType = NetworkType.TEST_NET
     };
     _accountHttp = new AccountHttp(BaseUrl)
     {
         NetworkType = NetworkType.TEST_NET
     };
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="SiriusClient" /> class.
 /// </summary>
 /// <param name="host">The network host</param>
 public SiriusClient(string host = @"http://localhost:3000")
 {
     Host            = host;
     NetworkHttp     = new NetworkHttp(host);
     AccountHttp     = new AccountHttp(host, NetworkHttp);
     BlockHttp       = new BlockHttp(host, NetworkHttp);
     ChainHttp       = new ChainHttp(host, NetworkHttp);
     MetadataHttp    = new MetadataHttp(host, NetworkHttp);
     MosaicHttp      = new MosaicHttp(host, NetworkHttp);
     NamespaceHttp   = new NamespaceHttp(host, NetworkHttp);
     TransactionHttp = new TransactionHttp(host, NetworkHttp);
     NodeHttp        = new NodeHttp(host, NetworkHttp);
 }
 // constructor for unit testing purposes
 internal AccountClient(AccountHttp accountHttp)
 {
     AccountHttp = accountHttp;
 }
 public AccountClient(BlockchainNetworkConnection blockchainNetworkConnection)
 {
     AccountHttp = new AccountHttp(blockchainNetworkConnection.RestApiUrl);
 }
Ejemplo n.º 8
0
        public async Task <(BlockchainAction[] actions, string state)> TraceDepositsAsync(string state, Func <string, Task <IAsset> > getAsset)
        {
            var lastConfirmedBlockNumber = await new BlockchainHttp(_nemUrl).GetBlockchainHeight() - (ulong)_requiredConfirmations;
            var actions     = new List <BlockchainAction>();
            var accountHttp = new AccountHttp(_nemUrl);
            var txs         = (await accountHttp.IncomingTransactions(_hotWallet))
                              .Where(tx => tx.TransactionInfo.Height <= lastConfirmedBlockNumber)
                              .OrderByDescending(tx => tx.TransactionInfo.Id)
                              .ToList();
            var lastTransactionHash = txs.FirstOrDefault()?.TransactionInfo.Hash;
            var processedCount      = 0;

            while (txs.Any())
            {
                _log.Info($"Retrieved {txs.Count} transactions");

                foreach (var tx in txs)
                {
                    if (tx.TransactionInfo.Hash == state)
                    {
                        _log.Info(processedCount > 0
                            ? $"Processed {processedCount} transactions"
                            : $"No new data since {lastTransactionHash}");

                        return(actions.ToArray(), lastTransactionHash);
                    }

                    if ((tx.TransactionType != TransactionTypes.Types.Transfer) &&
                        (tx.TransactionType != TransactionTypes.Types.Multisig || (tx as MultisigTransaction)?.InnerTransaction.TransactionType != TransactionTypes.Types.Transfer))
                    {
                        _log.Warning($"Not a transfer, skipped", context: tx.TransactionInfo);
                        continue;
                    }

                    TransferTransaction transfer = null;
                    string hash = null;

                    if (tx.TransactionType == TransactionTypes.Types.Multisig)
                    {
                        transfer = (tx as MultisigTransaction)?.InnerTransaction as TransferTransaction;
                        hash     = tx.TransactionInfo.InnerHash;
                    }

                    if (tx.TransactionType == TransactionTypes.Types.Transfer)
                    {
                        transfer = tx as TransferTransaction;
                        hash     = tx.TransactionInfo.Hash;
                    }

                    if (transfer == null || string.IsNullOrEmpty(hash))
                    {
                        throw new InvalidOperationException($"Wrongly parsed transaction {tx.TransactionInfo.Hash}");
                    }

                    var blockNumber = (long)tx.TransactionInfo.Height;
                    var blockTime   = _nemesis.AddSeconds(tx.TransactionInfo.TimeStamp);
                    var memo        = (transfer.Message as PlainMessage)?.GetStringPayload().TrimAllSpacesAroundNullSafe();
                    var to          = string.IsNullOrEmpty(memo)
                        ? transfer.Address.Plain
                        : transfer.Address.Plain + "$" + memo;

                    _log.Info($"New transfer detected", new { tx.TransactionInfo, from = transfer.Signer.Address.Plain, to, transfer.Mosaics });

                    foreach (var mos in transfer.Mosaics)
                    {
                        var assetId = $"{mos.NamespaceName}:{mos.MosaicName}";
                        var asset   = await getAsset(assetId);

                        if (asset == null)
                        {
                            _log.Info($"Unknown asset", new { assetId, mos.Amount });
                            continue;
                        }

                        var actionId = $"{asset.AssetId}:{mos.Amount}".CalculateHexHash32();
                        var amount   = asset.FromBaseUnit((long)mos.Amount);

                        actions.Add(new BlockchainAction(actionId, blockNumber, blockTime, hash, transfer.Signer.Address.Plain, asset.AssetId, (-1) * amount));
                        actions.Add(new BlockchainAction(actionId, blockNumber, blockTime, hash, to, asset.AssetId, amount));
                    }

                    processedCount++;
                }

                txs = await accountHttp.IncomingTransactions(_hotWallet, new TransactionQueryParams(txs.Last().TransactionInfo.Hash));
            }

            _log.Info(processedCount > 0
                ? $"Processed {processedCount} transactions"
                : $"No new data since {lastTransactionHash}");

            return(actions.ToArray(), lastTransactionHash);
        }