Beispiel #1
0
        private bool verify(Block block, int i)
        {
            Console.WriteLine("verifying block {0} in pos {1}", block, i);

            if (i == 0)
            {
                return(true);
            }


            //Compare prev hash.
            Block PrevBlock = BlockStore.BlockChain[i - 1];

            Console.WriteLine("debug - prev block should be {0}", BlockStore.BlockChain[i - 1]);
            Console.WriteLine("debug - got prev block {0}", PrevBlock);

            var preBlock = BlockStore.BlockChain[i - 1];

            Console.WriteLine("debug - var prev {0}", preBlock);

            String expectedPrevHashInput = JenpyBlockUtils.ComputedHash(PrevBlock);

            if (block.PrevHash != expectedPrevHashInput)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public Block(string Data)
        {
            this.Data = Data;
            int BlockStoreChainLastIdx = BlockStore.BlockChain.Count - 1;

            if (BlockStoreChainLastIdx >= 0)
            {
                this.PrevHash = BlockStore.BlockChain[BlockStoreChainLastIdx].Hash;
            }
            else
            {
                this.PrevHash = "genesis-no-prev-hash";
            }

            this.Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            this.Hash      = JenpyBlockUtils.ComputedHash(this);
        }