コード例 #1
0
        public ActionResult GetAddress(string address)
        {
            bool exists;

            if (_cache.TryGetValue(_ip, out exists))
            {
                var strIPTimeout = "{ \"error\" : \"too much requests from your IP, put sleep 1 sec between requests\" }";
                return(Content(strIPTimeout, "application/json"));;
            }
            string str = string.Empty;

            try
            {
                //{"address":"REjXTrh64hKd4x6QvXiQzwTM47qXfWv63R","sent":0,"received":1000,"balance":"1000","last_txs":[{"type":"vout","addresses":"7ea8373b87dee6fc8846b0bd86ddfe2f9874e3a1df8bc33564f893525e397266"}]}
                var            addressInfo = mainCoins.GetAddressInfo(address);
                AddressinfoApi json;
                if (addressInfo == null)
                {
                    json = new AddressinfoApi()
                    {
                        address  = address,
                        balance  = 0,
                        received = 0,
                        sent     = 0
                    };
                }
                else
                {
                    json = new AddressinfoApi()
                    {
                        address  = addressInfo.AddressInfo.Address,
                        balance  = addressInfo.AddressInfo.Total,
                        received = addressInfo.AddressInfo.Received,
                        sent     = -addressInfo.AddressInfo.Sent
                    };
                    var transactions = mainCoins.GetAddressTransactions(address, 0, 1000);
                    foreach (var tx in transactions)
                    {
                        json.last_txs.Add(new AddressinfoApiTx()
                        {
                            addresses = tx.Transaction,
                            type      = tx.Type
                        });
                    }
                }
                str = JsonConvert.SerializeObject(json);
            }
            catch
            {
                str = "{ \"error\" : \"data error\" }";
            }
            _cache.Set(_ip, true, _memoryCacheEntryOptions);
            return(Content(str, "application/json"));
        }
コード例 #2
0
        public ActionResult AddressTransactions(string address, string draw, int start)
        {
            var  addressInfo  = mainCoins.GetAddressInfo(address);
            var  transactions = mainCoins.GetAddressTransactions(address, start, ON_PAGE);
            long count        = 0;

            if (addressInfo != null)
            {
                count = Convert.ToInt64(Math.Round(addressInfo.AddressInfo.Transactions));
            }
            else
            {
                count = mainCoins.GetAddressTransactionsCount(address);
            }
            var json = new AddressTransactionJson();

            json.draw            = draw;
            json.recordsTotal    = count;
            json.recordsFiltered = count;
            json.data            = new List <string[]>();
            foreach (var tr in transactions)
            {
                json.data.Add(new string[7]
                {
                    tr.BlockTime.ToString("yyyy-MM-dd HH:mm"),
                    tr.Height.ToString(),
                    tr.Transaction.ToString(),
                    tr.Amount.ToString(),
                    tr.Total.ToString(),
                    tr.Type.ToString(),
                    tr.Valid.ToString()
                });
            }
            var str = JsonConvert.SerializeObject(json);

            return(Content(str, "application/json"));
        }