public BlockHeader GetHeader(uint256 hash)
 {
     var pos = _Index.Get<DiskBlockPos>(hash.ToString());
     if(pos == null)
         return null;
     var stored = _Store.Enumerate(false, new DiskBlockPosRange(pos)).FirstOrDefault();
     if(stored == null)
         return null;
     return stored.Item.Header;
 }
        public Block GetBlock(uint256 blockId)
        {
            var ms = new MemoryStream();
            var container = Configuration.GetBlocksContainer();
            try
            {

                container.GetPageBlobReference(blockId.ToString()).DownloadToStream(ms);
                ms.Position = 0;
                Block b = new Block();
                b.ReadWrite(ms, false);
                return b;
            }
            catch(StorageException ex)
            {
                if(ex.RequestInformation != null && ex.RequestInformation.HttpStatusCode == 404)
                {
                    return null;
                }
                throw;
            }
        }
Beispiel #3
0
 public void UInt256_ToString_NBitcoin()
 {
     _ = _nBitcoinData.ToString();
 }
        public async Task<TransactionEntry> GetTransactionAsync(bool loadPreviousOutput, bool fetchColor, uint256 txId)
        {
            if(txId == null)
                return null;
            TransactionEntry result = null;

            var table = Configuration.GetTransactionTable();
            var searchedEntity = new TransactionEntry.Entity(txId);
            var query = new TableQuery()
                            .Where(
                                    TableQuery.CombineFilters(
                                        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, searchedEntity.PartitionKey),
                                        TableOperators.And,
                                        TableQuery.CombineFilters(
                                            TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThan, txId.ToString() + "-"),
                                            TableOperators.And,
                                            TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThan, txId.ToString() + "|")
                                        )
                                  ));
            query.TakeCount = 10; //Should not have more
            List<TransactionEntry.Entity> entities = new List<TransactionEntry.Entity>();
            foreach(var e in await table.ExecuteQuerySegmentedAsync(query, null).ConfigureAwait(false))
            {
                if(e.IsFat())
                    entities.Add(new TransactionEntry.Entity(await FetchFatEntity(e).ConfigureAwait(false)));
                else
                    entities.Add(new TransactionEntry.Entity(e));
            }
            if(entities.Count == 0)
                result = null;
            else
            {
                result = new TransactionEntry(entities.ToArray());
                if(result.Transaction == null)
                {
                    foreach(var block in result.BlockIds.Select(id => GetBlock(id)).Where(b => b != null))
                    {
                        result.Transaction = block.Transactions.FirstOrDefault(t => t.GetHash() == txId);
                        entities[0].Transaction = result.Transaction;
                        if(entities[0].Transaction != null)
                        {
                            await UpdateEntity(table, entities[0].CreateTableEntity()).ConfigureAwait(false);
                        }
                        break;
                    }
                }

                if(fetchColor && result.ColoredTransaction == null)
                {
                    result.ColoredTransaction = await ColoredTransaction.FetchColorsAsync(txId, result.Transaction, new CachedColoredTransactionRepository(new IndexerColoredTransactionRepository(Configuration))).ConfigureAwait(false);
                    entities[0].ColoredTransaction = result.ColoredTransaction;
                    if(entities[0].ColoredTransaction != null)
                    {
                        await UpdateEntity(table, entities[0].CreateTableEntity()).ConfigureAwait(false);
                    }
                }
                var needTxOut = result.SpentCoins == null && loadPreviousOutput && result.Transaction != null;
                if(needTxOut)
                {
                    var inputs = result.Transaction.Inputs.Select(o => o.PrevOut).ToArray();
                    var parents = await
                            GetTransactionsAsync(false, false, inputs
                             .Select(i => i.Hash)
                             .ToArray()).ConfigureAwait(false);

                    for(int i = 0; i < parents.Length; i++)
                    {
                        if(parents[i] == null)
                        {
                            IndexerTrace.MissingTransactionFromDatabase(result.Transaction.Inputs[i].PrevOut.Hash);
                            return null;
                        }
                    }

                    var outputs = parents.Select((p, i) => p.Transaction.Outputs[inputs[i].N]).ToArray();

                    result.SpentCoins = Enumerable
                                            .Range(0, inputs.Length)
                                            .Select(i => new Spendable(inputs[i], outputs[i]))
                                            .ToList();
                    entities[0].PreviousTxOuts.Clear();
                    entities[0].PreviousTxOuts.AddRange(outputs);
                    if(entities[0].IsLoaded)
                    {
                        await UpdateEntity(table, entities[0].CreateTableEntity()).ConfigureAwait(false);
                    }
                }
            }
            return result != null && result.Transaction != null ? result : null;
        }
		private string GetId(uint256 txId)
		{
			return "tx-" + txId.ToString();
		}
 public void PutAsync(uint256 trxId, uint256 blockId)
 {
     repository.PutAsync(trxId.ToString(), blockId.AsBitcoinSerializable());
 }
 public uint256 GetBlockHash(uint256 trxHash)
 {
     return(repository.GetAsync <uint256.MutableUint256>(trxHash.ToString()).Result?.Value);
 }
Beispiel #8
0
 public void SetCoins(uint256 txId, Coins coins)
 {
     Index.Put(txId.ToString(), coins);
 }
 public Task <Block> GetBlockAsync(uint256 blockId)
 {
     return(repository.GetAsync <Block>(blockId.ToString()));
 }
Beispiel #10
0
 public Coins GetCoins(uint256 txId)
 {
     return Index.Get<Coins>(txId.ToString());
 }
Beispiel #11
0
 public void SetCoins(uint256 txId, Coins coins)
 {
     Index.Put(txId.ToString(), coins);
 }
		public Task PutAsync(uint256 blockId, Block block)
		{
			return _Repository.PutAsync(blockId.ToString(), block);
		}
		public Task<Block> GetBlockAsync(uint256 blockId)
		{
			return _Repository.GetAsync<Block>(blockId.ToString());
		}
 public Block Get(uint256 id)
 {
     return(Get(id.ToString()));
 }
 public Task PutAsync(uint256 blockId, Block block)
 {
     return(repository.PutAsync(blockId.ToString(), block));
 }
Beispiel #16
0
 private string GetId(uint256 txId)
 {
     return("tx-" + txId.ToString());
 }
Beispiel #17
0
 public Coins GetCoins(uint256 txId)
 {
     return(Index.Get <Coins>(txId.ToString()));
 }