Exemplo n.º 1
0
 public StampPeer(Guid peerGuid)
 {
     PeerGuid      = peerGuid;
     _genesisBlock = new StampBlock(Guid.Empty, null, null, DateTime.Now);
     Blocks        = new Dictionary <string, StampBlock>()
     {
         { _genesisBlock.BlockHash, _genesisBlock }
     };
     LatestBlock = _genesisBlock;
 }
Exemplo n.º 2
0
        public void AddBlock(StampBlock block)
        {
            if (LatestBlock.BlockHash != block.PreviousHash)
            {
                throw new Exception("Invalid previous block hash");
            }
            var blockHash = block.BlockHash;

            if (CalculateBlockHash(block) != blockHash)
            {
                throw new Exception("Invalid new block hash");
            }
            if (Blocks.ContainsKey(blockHash))
            {
                throw new Exception("Duplicate block in chain");
            }
            Blocks.Add(blockHash, block);
            LatestBlock = block;
        }
Exemplo n.º 3
0
        private String CalculateBlockHash(StampBlock block)
        {
            var data = String.Concat(block.BlockGuid.ToString(), block.PreviousHash, block.CreatedAt.ToUniversalTime(), block.UserCode, block.StampAt.ToUniversalTime(), block.Note);

            return(CalculateHash(data));
        }