Пример #1
0
        public void Can_round_trip_with_transaction_objects()
        {
            _types.Value.TryAdd(0, typeof(Transaction));

            var transaction = new Transaction
            {
                Id = $"{Guid.NewGuid()}"
            };
            var blockObject = new BlockObject
            {
                Data = transaction
            };

            blockObject.Hash = blockObject.ToHashBytes(_hash.Value);

            var block = new Block
            {
                Nonce        = 1,
                PreviousHash = "rosebud".Sha256(),
                Timestamp    = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                Objects      = new List <BlockObject> {
                    blockObject
                }
            };

            block.MerkleRootHash = block.ComputeMerkleRoot(_hash.Value);
            block.Hash           = block.ToHashBytes(_hash.Value);

            block.RoundTripCheck(_hash.Value, _types.Value);
        }
Пример #2
0
        private Block CreateBlock()
        {
            var transaction = new Transaction
            {
                Id = $"{Guid.NewGuid()}"
            };
            var blockObject = new BlockObject
            {
                Data = transaction
            };

            blockObject.Hash = blockObject.ToHashBytes(HashProvider);

            var block = new Block
            {
                Nonce          = 1,
                PreviousHash   = "rosebud".Sha256(),
                MerkleRootHash = HashProvider.DoubleHash(blockObject.Hash),
                Timestamp      = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                Objects        = new List <BlockObject> {
                    blockObject
                }
            };

            block.MerkleRootHash = block.ComputeMerkleRoot(HashProvider);
            block.Hash           = block.ToHashBytes(HashProvider);
            return(block);
        }