Esempio n. 1
0
        public FilteredTransactionsResponseModel GetFilteredTransactions(RequestFilteredListModel model)
        {
            var res = new FilteredTransactionsResponseModel();

            using (var client = GetClientByModel(model))
            {
                var args = new API.FilteredTransactionsListGet_args();
                args.GeneralQuery         = new TransactionsQuery();
                args.GeneralQuery.Flag    = Convert.ToInt16((model.Flagg == "in") ? 1 : (model.Flagg == "out" ? 2 : 3));
                args.GeneralQuery.Queries = new List <SingleQuery>();
                foreach (var qry in model.Queries)
                {
                    //var nq = new SingleQuery();
                    var sq = new SingleQuery();
                    sq.FromId           = BCTransactionTools.GetTransactionIdByStr(qry.FromId == null ? "0.0" : qry.FromId);
                    sq.RequestedAddress = SimpleBase.Base58.Bitcoin.Decode(qry.Address).ToArray();
                    if (qry.TokenQueries != null)
                    {
                        sq.TokensList = new List <SingleTokenQuery>();
                        foreach (var tokenReq in qry.TokenQueries)
                        {
                            var sqt = new SingleTokenQuery();
                            sqt.FromId       = BCTransactionTools.GetTransactionIdByStr(tokenReq.FromId);
                            sqt.TokenAddress = SimpleBase.Base58.Bitcoin.Decode(tokenReq.TokenAddress).ToArray();
                            sq.TokensList.Add(sqt);
                        }
                    }
                    args.GeneralQuery.Queries.Add(sq);
                }

                var qResult = client.FilteredTransactionsListGet(args.GeneralQuery);
                if (model.Queries.Count() < qResult.QueryResponse.Count)
                {
                    throw new Exception("Query and response lists are not syncronized");
                }

                foreach (var qRep in qResult.QueryResponse)
                {
                    var qRes = new QueryResponseItem();
                    qRes.QueryAddress = SimpleBase.Base58.Bitcoin.Encode(qRep.RequestedAddress);
                    foreach (var tr in qRep.Transactions)
                    {
                        var newTr = new ShortTransactionInfo();
                        newTr.Amount   = BCTransactionTools.GetDecimalByAmount(tr.Amount);
                        newTr.Currency = Convert.ToUInt16(tr.Currency);
                        var feeStr = Utils.ConvertCommission(tr.Fee.Commission).Replace(",", ".");

                        var style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
                        newTr.Fee = Decimal.Parse(feeStr, style, CultureInfo.InvariantCulture);

                        if (model.Flagg == "in")
                        {
                            newTr.Source = SimpleBase.Base58.Bitcoin.Encode(tr.Source);
                        }
                        else if (model.Flagg == "out")
                        {
                            newTr.Target = SimpleBase.Base58.Bitcoin.Encode(tr.Target);
                        }
                        else
                        {
                            newTr.Source = SimpleBase.Base58.Bitcoin.Encode(tr.Source);
                            newTr.Target = SimpleBase.Base58.Bitcoin.Encode(tr.Target);
                        }
                        newTr.TimeCreation  = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(tr.TimeCreation / 1000);
                        newTr.TransactionId = Convert.ToString(tr.Id.PoolSeq) + "." + Convert.ToString(tr.Id.Index);
                        newTr.Type          = Convert.ToByte(tr.Type);
                        newTr.UserData      = SimpleBase.Base58.Bitcoin.Encode(tr.UserFields);
                        qRes.Transactions.Add(newTr);
                    }
                    if (qRep.TransfersList != null)
                    {
                        foreach (var tokenResp in qRep.TransfersList)
                        {
                            var SingleTokenResponse = new QueryTokenResponseItem();
                            SingleTokenResponse.TokenAddress = SimpleBase.Base58.Bitcoin.Encode(tokenResp.TokenAddress);
                            SingleTokenResponse.TokenName    = tokenResp.TokenName;
                            SingleTokenResponse.TokenTiker   = tokenResp.TokenTiker;
                            if (tokenResp.Transfers != null)
                            {
                                foreach (var singleTokenTransfer in tokenResp.Transfers)
                                {
                                    var singleTokenTransferResult = new TokenTransferInfo();
                                    singleTokenTransferResult.TokenAddress      = SimpleBase.Base58.Bitcoin.Encode(singleTokenTransfer.Token);
                                    singleTokenTransferResult.Sender            = SimpleBase.Base58.Bitcoin.Encode(singleTokenTransfer.Sender);
                                    singleTokenTransferResult.Receiver          = SimpleBase.Base58.Bitcoin.Encode(singleTokenTransfer.Receiver);
                                    singleTokenTransferResult.TransferInitiator = SimpleBase.Base58.Bitcoin.Encode(singleTokenTransfer.Initiator);
                                    singleTokenTransferResult.TokenCode         = singleTokenTransfer.Code;
                                    singleTokenTransferResult.TokenAmount       = Convert.ToDecimal(singleTokenTransfer.Amount, CultureInfo.InvariantCulture);
                                    singleTokenTransferResult.TransactionID     = Convert.ToString(singleTokenTransfer.Transaction.PoolSeq) + "." + Convert.ToString(singleTokenTransfer.Transaction.Index);
                                    singleTokenTransferResult.TimeCreation      = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(singleTokenTransfer.Time / 1000);
                                    singleTokenTransferResult.UserData          = SimpleBase.Base58.Bitcoin.Encode(singleTokenTransfer.UserFields);
                                    if (singleTokenTransfer.Fee != null)
                                    {
                                        singleTokenTransferResult.Fee = Convert.ToDecimal(Utils.FeeByIndex(singleTokenTransfer.Fee.Commission), CultureInfo.InvariantCulture);
                                    }
                                    if (singleTokenTransfer.ExtraFee != null)
                                    {
                                        foreach (var it in singleTokenTransfer.ExtraFee)
                                        {
                                            var item = new EFeeItem();
                                            item.Fee     = Convert.ToDecimal(FormatAmount(it.Sum), CultureInfo.InvariantCulture);
                                            item.Comment = it.Comment;
                                            singleTokenTransferResult.ExtraFee.Add(item);
                                        }
                                    }
                                    SingleTokenResponse.Transfers.Add(singleTokenTransferResult);
                                }
                                qRes.TransfersList.Add(SingleTokenResponse);
                            }
                        }
                    }

                    res.QuerieResponses.Add(qRes);
                }
            }
            return(res);
        }
Esempio n. 2
0
        public ActionResult <FilteredTransactionsResponseModel> GetFilteredTransactionsList(RequestFilteredListModel model)
        {
            var response = new FilteredTransactionsResponseModel();

            try
            {
                response         = serviceProvider.GetService <MonitorService>().GetFilteredTransactions(model);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }