Exemple #1
0
        /// <summary>
        /// Adds a new transaction to the list of transactions
        /// </summary>
        /// <param name="sender">Address of the Sender</param>
        /// <param name="recipient">Address of the Recipient</param>
        /// <param name="amount">Amount</param>
        public long NewTransaction(string sender, string recipient, decimal amount)
        {
            CurrentTransactions.Add(new Transaction()
            {
                Sender    = sender,
                Recipient = recipient,
                Amount    = amount
            });

            return(LastBlock().Index + 1);
        }
Exemple #2
0
        /// <summary>
        /// Creates a new transaction to go into the next mined Block
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="recipient"></param>
        /// <param name="amout"></param>
        public int NewTransaction(string sender, string recipient, double amount)
        {
            var tran = new Transaction()
            {
                Sender    = sender,
                Recipient = recipient,
                Amount    = amount
            };

            CurrentTransactions.Add(tran);
            return(LastBlock.Index + 1);
        }
Exemple #3
0
        public int NewTransaction(string sender, string recipient, int amount)
        {
            CurrentTransactions.Add(
                new Transaction()
            {
                Sender    = sender,
                Recipient = recipient,
                Amount    = amount
            }
                );

            return(LastBlock.Index + 1);
        }
Exemple #4
0
        /// <summary>
        /// Creates a new Block and adds it to the chain
        /// </summary>
        /// <param name="proof"></param>
        /// <param name="previousHash"></param>
        public Block NewBlock(string proof, string previousHash)
        {
            Block block = new Block()
            {
                Index        = Chain.Count + 1,
                PreviousHash = previousHash,
                Proof        = proof,
                TimeStamp    = DateTime.Now,
                Transactions = CurrentTransactions.ToList()
            };

            //Reset the current list of transactions
            CurrentTransactions.Clear();

            Chain.Add(block);

            return(block);
        }
        /// <summary>
        ///  Creates a new block and appends it to the block chain
        /// </summary>
        /// <param name="proof">The proof given by the Proof of Work algorithm</param>
        /// <param name="previous_hash">(Optional)Hash of the previous block</param>
        /// <returns>New Block</returns>
        private Block NewBlock(long proof, string previous_hash = null)
        {
            //create the new block
            var newBlock = new Block
            {
                Index        = Chain.Count + 1,
                Timestamp    = DateTime.Now,
                Transactions = new List <Transaction>(CurrentTransactions),
                Proof        = proof,
                PreviousHash = previous_hash ?? Blockchain.Hash(LastBlock)
            };

            //reset the transactions
            CurrentTransactions.Clear();

            Chain.Add(newBlock);
            return(newBlock);
        }
 private void UpdateTransactions(string property)
 {
     CurrentTransactions.ForEach(t => NotifyPropertyChanged(t, property));
 }