public void TestDBreezeInsertOrder() { using (NodeContext ctx = NodeContext.Create(this)) { using (var engine = new DBreeze.DBreezeEngine(ctx.FolderName + "/2")) { var data = new[] { new uint256(3), new uint256(2), new uint256(2439425), new uint256(5), new uint256(243945), new uint256(10), new uint256(Hashes.Hash256(new byte[0])), new uint256(Hashes.Hash256(new byte[] { 1 })), new uint256(Hashes.Hash256(new byte[] { 2 })), }; Array.Sort(data, new UInt256Comparer()); using (DBreeze.Transactions.Transaction tx = engine.GetTransaction()) { foreach (uint256 d in data) { tx.Insert("Table", d.ToBytes(false), d.ToBytes()); } tx.Commit(); } var data2 = new uint256[data.Length]; using (DBreeze.Transactions.Transaction tx = engine.GetTransaction()) { int i = 0; foreach (Row <byte[], byte[]> row in tx.SelectForward <byte[], byte[]>("Table")) { data2[i++] = new uint256(row.Key, false); } } Assert.True(data.SequenceEqual(data2)); } } }
public void DBreezeEngineAbleToAccessExistingTransactionData() { string dir = CreateTestDir(this); uint256[] data = SetupTransactionData(dir); using (var engine = new DBreezeEngine(dir)) { using (DBreeze.Transactions.Transaction transaction = engine.GetTransaction()) { var data2 = new uint256[data.Length]; int i = 0; foreach (Row<int, byte[]> row in transaction.SelectForward<int, byte[]>("Table")) { data2[i++] = new uint256(row.Value, false); } Assert.True(data.SequenceEqual(data2)); } } }
public Task LoadAsync(ConcurrentChain chain) { Guard.Assert(chain.Tip == chain.Genesis); Task task = Task.Run(() => { using (DBreeze.Transactions.Transaction transaction = this.dbreeze.GetTransaction()) { ChainedBlock tip = null; bool first = true; foreach (Row <int, BlockHeader> row in transaction.SelectForward <int, BlockHeader>("Chain")) { if ((tip != null) && (row.Value.HashPrevBlock != tip.HashBlock)) { break; } tip = new ChainedBlock(row.Value, null, tip); if (first) { first = false; Guard.Assert(tip.HashBlock == chain.Genesis.HashBlock); // can't swap networks } } if (tip == null) { return; } this.locator = tip.GetLocator(); chain.SetTip(tip); } }); return(task); }