public bool TryReadTransaction(TxKey txKey, out Transaction transaction)
        {
            using (var conn = this.OpenConnection())
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = @"
                    SELECT TxHash, TxBytes
                    FROM BlockTransactions
                    WHERE BlockHash = @blockHash AND TxIndex = @txIndex";

                cmd.Parameters.SetValue("@blockHash", SqlDbType.Binary, 32).Value = txKey.BlockHash.ToDbByteArray();
                cmd.Parameters.SetValue("@txIndex", SqlDbType.Int).Value = txKey.TxIndex.ToIntChecked();

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        var txHash = reader.GetUInt256(0);
                        var txBytes = reader.GetBytes(1);

                        transaction = StorageEncoder.DecodeTransaction(txBytes.ToMemoryStream(), txHash);
                        return true;
                    }
                    else
                    {
                        transaction = default(Transaction);
                        return false;
                    }
                }
            }
        }
Example #2
0
        public static Transaction GetTransaction(this CacheContext cacheContext, TxKey txKey, bool saveInCache = true)
        {
            Transaction transaction;
            if (!cacheContext.TransactionCache.TryGetValue(txKey, out transaction, saveInCache))
            {
                throw new MissingDataException(DataType.Transaction, txKey.TxHash);
            }

            return transaction;
        }
Example #3
0
 public bool TryGetTransaction(TxKey txKey, out Transaction transaction, bool saveInCache = true)
 {
     if (this.CacheContext.TransactionCache.TryGetValue(txKey, out transaction))
     {
         this.missingTransactions.TryRemove(txKey.TxHash);
         return true;
     }
     else
     {
         this.missingTransactions.TryAdd(txKey.TxHash);
         transaction = default(Transaction);
         return false;
     }
 }
 public bool TryReadTransaction(TxKey txKey, out Transaction transaction)
 {
     throw new NotImplementedException();
 }