Exemplo n.º 1
0
        public void GetTransactionById(NodeCoreAdminClient adminClient)
        {
            Console.WriteLine("GetTransactionById");
            Console.WriteLine("NC_CLI command: gettransaction <txId> [searchLength]");

            String txId = "DED0DB5035D90A756B6F5333157F13D55103C5F76378FD732809CDE27E6B57F3";

            GetTransactionsRequest request = new GetTransactionsRequest();

            request.Ids.Add(txId.ToByteString());
            request.SearchLength = 2000;

            GetTransactionsReply reply = adminClient.AdminClient.GetTransactions(request);

            if (reply.Success)
            {
                if (reply.Transactions.Count > 0)
                {
                    //Display info
                    int    iBlockIndex  = reply.Transactions[0].BlockNumber;
                    double sourceAmount = Utils.ConvertAtomicToVbkUnits(reply.Transactions[0].Transaction.SourceAmount);
                    Console.WriteLine("BlockIndex={0}, sourceAmount={1}", iBlockIndex, sourceAmount);
                }
            }

            Console.WriteLine("--------------------");
            Console.WriteLine();
        }
Exemplo n.º 2
0
        public override async Task <GetTransactionsReply> GetTransactions(GetTransactionsRequest request, ServerCallContext context)
        {
            var resp = new GetTransactionsReply {
            };

            try
            {
                var client = LyraRestClient.Create(_config["network"], Environment.OSVersion.ToString(), "LyraBroker", "1.0");
                var result = await client.SearchTransactionsAsync(request.AccountId,
                                                                  request.StartTime.ToDateTime().Ticks,
                                                                  request.EndTime.ToDateTime().Ticks,
                                                                  request.Count);

                if (result.ResultCode == APIResultCodes.Success)
                {
                    for (int i = 0; i < result.Transactions.Count; i++)
                    {
                        var txDesc = result.Transactions[i];
                        var tx     = new LyraTransaction
                        {
                            Height    = txDesc.Height,
                            Time      = Timestamp.FromDateTime(txDesc.TimeStamp),
                            IsReceive = txDesc.IsReceive,

                            SendAccountId = txDesc.SendAccountId ?? "",
                            SendHash      = txDesc.SendHash ?? "",
                            RecvAccountId = txDesc.RecvAccountId,
                            RecvHash      = txDesc.RecvHash ?? ""   // protobuf not like null
                        };

                        if (txDesc.Changes == null || !txDesc.Changes.ContainsKey(LyraGlobal.OFFICIALTICKERCODE))
                        {
                            tx.BalanceChange = 0;
                        }
                        else
                        {
                            tx.BalanceChange = txDesc.Changes[LyraGlobal.OFFICIALTICKERCODE] / LyraGlobal.TOKENSTORAGERITO;
                        }

                        if (txDesc.Balances == null || !txDesc.Balances.ContainsKey(LyraGlobal.OFFICIALTICKERCODE))
                        {
                            tx.Balance = 0;
                        }
                        else
                        {
                            tx.Balance = txDesc.Balances[LyraGlobal.OFFICIALTICKERCODE] / LyraGlobal.TOKENSTORAGERITO;
                        }



                        resp.Transactions.Add(tx);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning("In OpenWallet: " + ex.ToString());
            }

            return(resp);
        }