示例#1
0
        public override Dictionary <ushort, SpentCoin> GetUnclaimed(UInt256 hash)
        {
            int         height;
            Transaction tx = GetTransaction(ReadOptions.Default, hash, out height);

            if (tx == null)
            {
                return(null);
            }
            SpentCoinState state = db.TryGet <SpentCoinState>(ReadOptions.Default, DataEntryPrefix.ST_SpentCoin, hash);

            if (state != null)
            {
                return(state.Items.ToDictionary(p => p.Key, p => new SpentCoin
                {
                    Output = tx.Outputs[p.Key],
                    StartHeight = (uint)height,
                    EndHeight = p.Value
                }));
            }
            else
            {
                return(new Dictionary <ushort, SpentCoin>());
            }
        }
示例#2
0
        private void setupSpentCoinStateWithValues(SpentCoinState spentCoinState, out UInt256 transactionHash, out uint transactionHeight)
        {
            transactionHash = new UInt256(TestUtils.GetByteArray(32, 0x20));
            spentCoinState.TransactionHash = transactionHash;
            transactionHeight = 757859114;
            spentCoinState.TransactionHeight = transactionHeight;
            Dictionary <ushort, uint> dict = new Dictionary <ushort, uint>();

            dict.Add(42, 100);
            spentCoinState.Items = dict;
        }
示例#3
0
        public void TestFromReplica()
        {
            uut.Items = new Dictionary <ushort, uint>();
            uut.Items.Add(1, 3);

            var a = ((ICloneable <SpentCoinState>)uut).Clone();
            var b = new SpentCoinState();

            ((ICloneable <SpentCoinState>)b).FromReplica(uut);

            CollectionAssert.AreEqual(a.Items.Keys, uut.Items.Keys);
            CollectionAssert.AreEqual(a.Items.Values, uut.Items.Values);
            CollectionAssert.AreEqual(b.Items.Keys, uut.Items.Keys);
            CollectionAssert.AreEqual(b.Items.Values, uut.Items.Values);

            a.Items.Clear();
            b.Items.Clear();

            CollectionAssert.AreNotEqual(a.Items.Keys, uut.Items.Keys);
            CollectionAssert.AreNotEqual(b.Items.Keys, uut.Items.Keys);
            CollectionAssert.AreNotEqual(a.Items.Values, uut.Items.Values);
            CollectionAssert.AreNotEqual(b.Items.Values, uut.Items.Values);
        }
示例#4
0
        public Dictionary <ushort, SpentCoin> GetUnclaimed(UInt256 hash)
        {
            TransactionState tx_state = Transactions.TryGet(hash);

            if (tx_state == null)
            {
                return(null);
            }
            SpentCoinState coin_state = SpentCoins.TryGet(hash);

            if (coin_state != null)
            {
                return(coin_state.Items.ToDictionary(p => p.Key, p => new SpentCoin
                {
                    Output = tx_state.Transaction.Outputs[p.Key],
                    StartHeight = tx_state.BlockIndex,
                    EndHeight = p.Value
                }));
            }
            else
            {
                return(new Dictionary <ushort, SpentCoin>());
            }
        }
示例#5
0
 public void TestSetup()
 {
     uut = new SpentCoinState();
 }