Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            _chain.Add(textBox1.Text, "Leski");

            listBox1.Items.AddRange(_chain.Blocks.ToArray());
        }
Ejemplo n.º 2
0
        private void addBlockBtn_Click(object sender, EventArgs e)
        {
            outputDataListBox.Items.Clear();

            _chain.Add(inputDataBox.Text, "Admin");

            outputDataListBox.Items.AddRange(_chain.Blocks.ToArray());
        }
Ejemplo n.º 3
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            listBox.Items.Clear();
            _chain.Add(textBox.Text, "User");
            textBox.Clear();

            listBox.Items.AddRange(_chain.Blocks.ToArray());
        }
Ejemplo n.º 4
0
        public Block AddBlock(DateTime timestamp)
        {
            Block latestBlock = GetLatestBlock();
            Block block       = new Block(latestBlock.Index + 1, timestamp, latestBlock.Hash, PendingTransactions);

            block.Mine(_lead);
            Chain.Add(block);
            PendingTransactions = new List <Transaction>();
            return(block);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="difficulty">The mining difficulty set by the program and kept in the blockchain.</param>
        public Blockchain(int difficulty)
        {
            // Set the difficulty
            Difficulty = difficulty;

            // Generate the initial block.
            var genesisBlock = CreateGenesisBlock();

            // Add the initial block to the chain.
            Chain.Add(genesisBlock);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a new block to the chain.
        /// </summary>
        /// <param name="data">The block data to be added to the chain.</param>
        public void AddBlock(BlockData data)
        {
            // Get the last block in the chain.
            var lastBlock = GetLastBlock();

            // Create a new block with the data and the parent hash.
            var block = new Block(data, lastBlock.Hash);

            // Generate a new block from the difficulty setting and data provided.
            block.MineBlock(Difficulty);

            // Add the new block to the chain.
            Chain.Add(block);
        }
Ejemplo n.º 7
0
        public void add(Block block)
        {
            if (Chain.Count > 0)
            {
                block.PrevBlockHash = Chain.Last().Pow;
                block.BlockNumber   = (Chain.Count + 1).ToString();
            }
            else
            {
                block.PrevBlockHash = EMPTY_HASH;
                block.BlockNumber   = "1";
            }

            block.Difficulty = DEFAULT_DIFFICALTY;
            block.recalculate();
            Chain.Add(block);
        }