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>()); } }
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; }
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); }
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>()); } }
public void TestSetup() { uut = new SpentCoinState(); }