public void EncodeDecodeTransaction()
        {
            TransactionEncoder encoder = new TransactionEncoder();
            var sender   = new Address();
            var receiver = new Address();

            Transaction transaction = new Transaction(sender, receiver, new BigInteger(100));

            var result = encoder.Decode(encoder.Encode(transaction));

            Assert.IsNotNull(result);

            Assert.IsNotNull(result.Receiver);
            Assert.AreEqual(receiver, result.Receiver);

            Assert.IsNotNull(result.Sender);
            Assert.AreEqual(sender, result.Sender);

            Assert.AreEqual(new BigInteger(100), result.Value);
        }
Beispiel #2
0
        public Block(ulong number, BlockHash parentHash, IEnumerable <Transaction> transactions)
        {
            if (number == 0 && parentHash != null)
            {
                throw new InvalidOperationException("Genesis block should have no parent");
            }

            this.transactions = new List <Transaction>(transactions);
            this.header       = new BlockHeader(number, parentHash, this.CalculateHash(transactionEncoder.Encode(this.transactions)));
        }