예제 #1
0
        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);
                        }
                    }
                }
        }
예제 #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);
        }
예제 #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);
     }
 }
예제 #4
0
        public void TestTxKeyEquality()
        {
            var randomTxKey = RandomData.RandomTxKey();

            var sameTxKey = new TxKey
            (
                txHash: randomTxKey.TxHash,
                blockHash: randomTxKey.BlockHash,
                txIndex: randomTxKey.TxIndex
            );

            var differentTxKeyBlockHash = new TxKey
            (
                txHash: randomTxKey.TxHash,
                blockHash: ~randomTxKey.BlockHash,
                txIndex: randomTxKey.TxIndex
            );

            var differentTxKeyTxIndex = new TxKey
            (
                txHash: randomTxKey.TxHash,
                blockHash: randomTxKey.BlockHash,
                txIndex: ~randomTxKey.TxIndex
            );

            var differentTxKeyTxHash = new TxKey
            (
                txHash: ~randomTxKey.TxHash,
                blockHash: randomTxKey.BlockHash,
                txIndex: randomTxKey.TxIndex
            );

            Assert.IsTrue(randomTxKey.Equals(sameTxKey));
            Assert.IsTrue(randomTxKey == sameTxKey);
            Assert.IsFalse(randomTxKey != sameTxKey);

            Assert.IsFalse(randomTxKey.Equals(differentTxKeyBlockHash));
            Assert.IsFalse(randomTxKey == differentTxKeyBlockHash);
            Assert.IsTrue(randomTxKey != differentTxKeyBlockHash);

            Assert.IsFalse(randomTxKey.Equals(differentTxKeyTxIndex));
            Assert.IsFalse(randomTxKey == differentTxKeyTxIndex);
            Assert.IsTrue(randomTxKey != differentTxKeyTxIndex);

            Assert.IsFalse(randomTxKey.Equals(differentTxKeyTxHash));
            Assert.IsFalse(randomTxKey == differentTxKeyTxHash);
            Assert.IsTrue(randomTxKey != differentTxKeyTxHash);
        }
예제 #5
0
        public void TestTxKeyEquality()
        {
            var randomTxKey = RandomData.RandomTxKey();

            var sameTxKey = new TxKey
                            (
                txHash: randomTxKey.TxHash,
                blockHash: randomTxKey.BlockHash,
                txIndex: randomTxKey.TxIndex
                            );

            var differentTxKeyBlockHash = new TxKey
                                          (
                txHash: randomTxKey.TxHash,
                blockHash: ~randomTxKey.BlockHash,
                txIndex: randomTxKey.TxIndex
                                          );

            var differentTxKeyTxIndex = new TxKey
                                        (
                txHash: randomTxKey.TxHash,
                blockHash: randomTxKey.BlockHash,
                txIndex: ~randomTxKey.TxIndex
                                        );

            var differentTxKeyTxHash = new TxKey
                                       (
                txHash: ~randomTxKey.TxHash,
                blockHash: randomTxKey.BlockHash,
                txIndex: randomTxKey.TxIndex
                                       );

            Assert.IsTrue(randomTxKey.Equals(sameTxKey));
            Assert.IsTrue(randomTxKey == sameTxKey);
            Assert.IsFalse(randomTxKey != sameTxKey);

            Assert.IsFalse(randomTxKey.Equals(differentTxKeyBlockHash));
            Assert.IsFalse(randomTxKey == differentTxKeyBlockHash);
            Assert.IsTrue(randomTxKey != differentTxKeyBlockHash);

            Assert.IsFalse(randomTxKey.Equals(differentTxKeyTxIndex));
            Assert.IsFalse(randomTxKey == differentTxKeyTxIndex);
            Assert.IsTrue(randomTxKey != differentTxKeyTxIndex);

            Assert.IsFalse(randomTxKey.Equals(differentTxKeyTxHash));
            Assert.IsFalse(randomTxKey == differentTxKeyTxHash);
            Assert.IsTrue(randomTxKey != differentTxKeyTxHash);
        }
예제 #6
0
 public bool TryReadTransaction(TxKey txKey, out Transaction transaction)
 {
     throw new NotImplementedException();
 }