示例#1
0
        public JsonResult Index()
        {
            var rawTxs   = RpcHelper.RequestJson <TxPoolResp>("f_on_transactions_pool_json", new Dictionary <string, object>()).result.transactions;
            var txHashes = new List <string>();

            foreach (var rawTx in rawTxs)
            {
                txHashes.Add(rawTx.hash);
            }
            var tx_args = new Dictionary <string, object>();

            tx_args.Add("transactionHashes", txHashes.ToArray());
            var txs = RpcHelper.Request <TxDetailResp>("get_transaction_details_by_hashes", tx_args);

            List <CachedTx> transactions = new List <CachedTx>();

            if (txs != null)
            {
                foreach (var rawTx in txs.transactions)
                {
                    var memPoolTx = TransactionHelpers.MapTx(rawTx);
                    memPoolTx.height = 0;
                    transactions.Add(memPoolTx);
                }
            }
            return(new JsonResult(JsonConvert.SerializeObject(transactions)));
        }
示例#2
0
        private JsonResult GetDirect(int Height, int startHeight, int chainHeight)
        {
            List <int> blockHeights = new List <int>();

            for (var x = startHeight; x < chainHeight; x++)
            {
                blockHeights.Add(x);
            }
            //fetch the transactions directly from the Blockchain
            var args = new Dictionary <string, object>();

            args.Add("blockHeights", blockHeights);
            var             blocks       = RpcHelper.Request <BlockResp>("get_blocks_details_by_heights", args).blocks;
            List <CachedTx> transactions = new List <CachedTx>();

            foreach (var block in blocks)
            {
                foreach (var transaction in block.transactions)
                {
                    var cachedTx = TransactionHelpers.MapTx(transaction);
                    //persist tx's to cache
                    if (cachedTx != null)
                    {
                        transactions.Add(cachedTx);
                    }
                }
            }
            return(new JsonResult(JsonConvert.SerializeObject(transactions)));
        }
示例#3
0
        public JsonResult Get(int height = 0)
        {
            //TODO: Update this to split get Tx's from Split BC cache
            var sizeBlock   = 1000;
            var startHeight = height;
            var endHeight   = startHeight + 100;

            if (startHeight < 1)
            {
                startHeight = 1;
            }
            //todo, we don't have to query the chain height every time this is requested
            var chainHeight = RpcHelper.Request <GetHeightResp>("getheight").Height;

            if (chainHeight == 0)
            {
                chainHeight = endHeight + 100;
            }
            if (endHeight > chainHeight)
            {
                endHeight = chainHeight;
            }

            List <int> dbSegments   = new List <int>();
            var        segmentStart = Convert.ToInt32(Math.Floor((double)(startHeight / sizeBlock) * sizeBlock)) + 1;

            dbSegments.Add(segmentStart);
            if (startHeight + 100 > segmentStart + sizeBlock - 1)
            {
                dbSegments.Add(segmentStart + sizeBlock);
            }
            try
            {
                //TODO:... if we find a problem - ie: there are ANY tx's that don't return at least one Tx poer height, then we need to re-cache the DB file we're working with for this height...
                //we need to ensure that there is at least one Tx per block
                //should this be in a seperate "validation background job that's checking completed files - maybe to run once per day?
                List <LightTx> transactions = new List <LightTx>();
                foreach (var start in dbSegments)
                {
                    var end = start + sizeBlock - 1;

                    using (var db = new LiteDatabase(string.Concat(AppContext.BaseDirectory, @"App_Data\", "transactions_", start, "-", end, ".db")))
                    {
                        var cachedtxs = db.GetCollection <CachedTx>("cached_txs");
                        var txs       = cachedtxs.Find(x => x.height >= startHeight && x.height <= endHeight).Distinct().ToList();
                        transactions.AddRange(TransactionHelpers.MapTxs(txs));
                    }
                }
                return(new JsonResult(JsonConvert.SerializeObject(transactions)));
            }
            catch (Exception ex)
            {
                //todo: log and return client handlable exception
            }

            return(new JsonResult(""));
        }
        public JsonResult Index([FromForm] string value)
        {
            var x    = value;
            var args = new Dictionary <string, object>();

            args.Add("tx_as_hex", value);
            var response = RpcHelper.Request <RawTxResp>("sendrawtransaction", args);

            return(new JsonResult(response));
        }
示例#5
0
        public JsonResult Get(int height = 0)
        {
            //TODO: Update this to split get Tx's from Split BC cache
            var startHeight = Convert.ToInt32(Math.Floor((double)(height / 100) * 100));
            var endHeight   = startHeight + 100;

            if (startHeight < 1)
            {
                startHeight = 1;
            }
            var chainHeight = RpcHelper.Request <GetHeightResp>("getheight").Height;

            if (chainHeight == 0)
            {
                chainHeight = endHeight + 100;
            }
            if (endHeight > chainHeight)
            {
                endHeight = chainHeight;
            }
            //used to pick the correct file
            var start = Convert.ToInt32(Math.Floor((double)(height / 10000) * 10000)) + 1;
            var end   = start + 10000 - 1;

            try
            {
                //if we are close to the top of the chain (within 100 blocks) get the data directly from the node and return it..
                //this is a bit slower than a cache hit, but ensures we keep the wallet sync'd up to it's current actual height, rather than working a block or two behind.
                var lastSegment = Convert.ToInt32(Math.Floor((double)(chainHeight / 100) * 100));
                if (lastSegment < height)
                {
                    return(GetDirect(height, startHeight, chainHeight));
                }
                else
                {
                    //get from cache
                    //TODO: If there's an error, (wallet cache get's stuck), we need to re-create that segment of the chain somehow
                    //drop the cache file, and let it rebuild, and return the queries from the chain directly...
                    //need some for of checking mechanism to ensure that each block in the segment wh're querying has at least one transaction
                    using (var db = new LiteDatabase(string.Concat(AppContext.BaseDirectory, @"App_Data\", "transactions_", start, "-", end, ".db")))
                    {
                        var transactions = db.GetCollection <CachedTx>("cached_txs");
                        var txs          = transactions.Find(x => x.height >= startHeight && x.height <= endHeight).Distinct().ToList();

                        return(new JsonResult(JsonConvert.SerializeObject(txs)));
                    }
                }
            }
            catch (Exception ex)
            {
                //todo: log and return client handlable exception
            }

            return(new JsonResult(""));
        }
 public ContentResult Get()
 {
     try
     {
         return(Content((RpcHelper.Request <GetHeightResp>("getheight").Height - 1).ToString()));
     }
     catch (Exception ex)
     {
         //if the daemon is down, getheight will return an error and get stuck, so we return the latest cache height that we have available in this instance...
         return(Content("0")); //fail if daemon not responding
     }
 }
        public JsonResult Get(int height = 0)
        {
            //TODO: Update this to split get Tx's from Split BC cache
            var sizeBlock   = 1000;
            var startHeight = Convert.ToInt32(Math.Floor((double)(height / 100) * 100));
            var endHeight   = startHeight + 100;

            if (startHeight < 1)
            {
                startHeight = 1;
            }
            var chainHeight = RpcHelper.Request <GetHeightResp>("getheight").Height;

            if (chainHeight == 0)
            {
                chainHeight = endHeight + 100;
            }
            if (endHeight > chainHeight)
            {
                endHeight = chainHeight;
            }
            //used to pick the correct file
            var start = Convert.ToInt32(Math.Floor((double)(height / sizeBlock) * sizeBlock)) + 1;
            var end   = start + sizeBlock - 1;

            try
            {
                //TODO:... if we find a problem - ie: there are ANY tx's that don't return at least one Tx poer height, then we need to re-cache the DB file we're working with for this height...
                //we need to ensure that there is at least one Tx per block
                //should this be in a seperate "validation background job that's checking completed files - maybe to run once per day?
                using (var db = new LiteDatabase(string.Concat(AppContext.BaseDirectory, @"App_Data/", "transactions_", start, "-", end, ".db")))
                {
                    var transactions = db.GetCollection <CachedTx>("cached_txs");
                    var txs          = transactions.Find(x => x.height >= startHeight && x.height <= endHeight).Distinct().ToList();

                    return(new JsonResult(JsonConvert.SerializeObject(txs)));
                }
            }
            catch (Exception ex)
            {
                //todo: log and return client handlable exception
                throw ex;
            }

            return(new JsonResult(""));
        }
        public JsonResult Get(int height = 0)
        {
            //TODO: Update this to split get Tx's from Split BC cache
            var startHeight = height;
            var endHeight   = startHeight + 100;

            if (startHeight < 1)
            {
                startHeight = 1;
            }
            var chainHeight = RpcHelper.Request <GetHeightResp>("getheight").Height;

            if (chainHeight == 0)
            {
                chainHeight = endHeight + 100;
            }
            if (endHeight > chainHeight)
            {
                endHeight = chainHeight;
            }
            //used to pick the correct file
            var start = Convert.ToInt32(Math.Floor((double)(height / 10000) * 10000)) + 1;
            var end   = start + 10000 - 1;

            try
            {
                using (var db = new LiteDatabase(string.Concat(AppContext.BaseDirectory, @"App_Data\", "transactions_", start, "-", end, ".db")))
                {
                    var transactions = db.GetCollection <CachedTx>("cached_txs");
                    var txs          = transactions.Find(x => x.height >= startHeight && x.height <= endHeight);
                    return(new JsonResult(JsonConvert.SerializeObject(txs)));
                }
            }
            catch (Exception ex)
            {
                //todo: log and return client handlable exception
            }

            return(new JsonResult(""));
        }
 public ContentResult Get()
 {
     return(Content((RpcHelper.Request <GetHeightResp>("getheight").Height - 1).ToString()));
 }