\feffusing System;
using System.IO;
using System.Linq;
+using System.Collections.Generic;
using SQLite.Net;
using SQLite.Net.Attributes;
namespace Novacoin
{
+ public enum BlockType
+ {
+ PROOF_OF_WORK,
+ PROOF_OF_WORK_MODIFIER,
+ PROOF_OF_STAKE,
+ PROOF_OF_STAKE_MODIFIER
+ };
+
[Table("BlockStorage")]
class CBlockStoreItem
{
/// PBKDF2+Salsa20 of block hash
/// </summary>
[Unique]
- public byte[] ScryptHash { get; set; }
+ public byte[] Hash { get; set; }
+
+ /// <summary>
+ /// Next block hash
+ /// </summary>
+ public byte[] NextHash { get; set; }
/// <summary>
/// Serialized representation of block header
public byte[] BlockHeader { get; set; }
/// <summary>
+ /// Block type flags
+ /// </summary>
+ public BlockType BlockTypeFlag { get; set; }
+
+ /// <summary>
/// Block position in file
/// </summary>
public long nBlockPos { get; set; }
public int nBlockSize { get; set; }
}
+ /// <summary>
+ /// Block chain node
+ /// </summary>
+ public class CChainNode
+ {
+ /// <summary>
+ /// Block number
+ /// </summary>
+ public int nDepth;
+
+ /// <summary>
+ /// Block header
+ /// </summary>
+ public CBlockHeader blockHeader;
+
+ /// <summary>
+ /// Block type flag
+ /// </summary>
+ public BlockType blockType;
+
+ /// <summary>
+ /// Next block hash
+ /// </summary>
+ public ScryptHash256 hashNextBlock;
+ }
+
public class CBlockStore : IDisposable
{
private bool disposed = false;
private object LockObj = new object();
private SQLiteConnection dbConn = null;
+
+ private Dictionary<ScryptHash256, CChainNode> blockIndex = new Dictionary<ScryptHash256, CChainNode>();
/// <summary>
/// Init the block storage manager.
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
});