From: CryptoManiac Date: Fri, 28 Aug 2015 12:04:17 +0000 (+0300) Subject: CChainNode X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=990d6bd8adc9dbff4f1e3229537b51fbeecd1e65 CChainNode --- diff --git a/Novacoin/CBlockStore.cs b/Novacoin/CBlockStore.cs index 7f1f9ae..7df6887 100644 --- a/Novacoin/CBlockStore.cs +++ b/Novacoin/CBlockStore.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Collections.Generic; using SQLite.Net; using SQLite.Net.Attributes; @@ -9,6 +10,14 @@ using SQLite.Net.Platform.Generic; namespace Novacoin { + public enum BlockType + { + PROOF_OF_WORK, + PROOF_OF_WORK_MODIFIER, + PROOF_OF_STAKE, + PROOF_OF_STAKE_MODIFIER + }; + [Table("BlockStorage")] class CBlockStoreItem { @@ -22,7 +31,12 @@ namespace Novacoin /// PBKDF2+Salsa20 of block hash /// [Unique] - public byte[] ScryptHash { get; set; } + public byte[] Hash { get; set; } + + /// + /// Next block hash + /// + public byte[] NextHash { get; set; } /// /// Serialized representation of block header @@ -30,6 +44,11 @@ namespace Novacoin public byte[] BlockHeader { get; set; } /// + /// Block type flags + /// + public BlockType BlockTypeFlag { get; set; } + + /// /// Block position in file /// public long nBlockPos { get; set; } @@ -40,11 +59,39 @@ namespace Novacoin public int nBlockSize { get; set; } } + /// + /// Block chain node + /// + public class CChainNode + { + /// + /// Block number + /// + public int nDepth; + + /// + /// Block header + /// + public CBlockHeader blockHeader; + + /// + /// Block type flag + /// + public BlockType blockType; + + /// + /// Next block hash + /// + public ScryptHash256 hashNextBlock; + } + public class CBlockStore : IDisposable { private bool disposed = false; private object LockObj = new object(); private SQLiteConnection dbConn = null; + + private Dictionary blockIndex = new Dictionary(); /// /// Init the block storage manager. @@ -128,8 +175,9 @@ namespace Novacoin var result = dbConn.Insert(new CBlockStoreItem() { - ScryptHash = block.header.Hash, + Hash = block.header.Hash, BlockHeader = block.header, + BlockTypeFlag = block.IsProofOfStake ? BlockType.PROOF_OF_STAKE : BlockType.PROOF_OF_WORK, nBlockPos = nOffset, nBlockSize = nBlockSize });