Code Monkey home page Code Monkey logo

blockchain's Introduction

Description Today, the most common application of blockchains is cryptocurrencies. A cryptocurrency’s blockchain contains a list of transactions: everyone can see the transactions but no one is able to change them. In addition, no one can send a transaction as another person; this is possible using digital signatures. You have actually implemented all of this functionality in the previous stages.

A miner who creates a new block should be awarded some virtual money, for example, 100 virtual coins. This can be remembered in the blockchain if the block stores information about the miner who created this block. Of course, this message also should be proved, so the miner adds this information to the blockchain before starting a search for a magic number.

After that, a miner can spend these 100 virtual coins by giving them to someone else. In the real world, he can buy things and pay for them using these virtual coins instead of real money. These virtual coins go to the company that sells the things, and the company can pay salaries with these virtual coins. The circulation of these coins starts here and suddenly the virtual coins become more popular than real money!

To check how many coins a person has, you need to check all of his transactions and all of the transactions to him, assuming that the person started with zero virtual coins. The transaction should be rejected when the person tries to spend more money than he has at the moment. Create a special method that returns how many coins the person has.

In this stage, you need to implement transactions like this instead of text messages like in the previous stage. For testing reasons you can assume that everyone starts with 100 virtual coins, not 0. But as described above, all the money of the blockchain is initially awards for creating blocks of the blockchain.

Example In the output example, VC stands for Virtual Coins. To be tested successfully, program should output information about first fifteen blocks of the blockchain. Blocks should be separated by an empty line.

Block: Created by: miner9 miner9 gets 100 VC Id: 1 Timestamp: 1539866031047 Magic number: 76384756 Hash of the previous block: 0 Hash of the block: 1d12cbbb5bfa278734285d261051f5484807120032cf6adcca5b9a3dbf0e7bb3 Block data: No transactions Block was generating for 0 seconds N was increased to 1

Block: Created by: miner7 miner7 gets 100 VC Id: 2 Timestamp: 1539866031062 Magic number: 92347234 Hash of the previous block: 1d12cbbb5bfa278734285d261051f5484807120032cf6adcca5b9a3dbf0e7bb3 Hash of the block: 04a6735424357bf9af5a1467f8335e9427af714c0fb138595226d53beca5a05e Block data: miner9 sent 30 VC to miner1 miner9 sent 30 VC to miner2 miner9 sent 30 VC to Nick Block was generating for 0 seconds N was increased to 2

Block: Created by: miner1 miner1 gets 100 VC Id: 3 Timestamp: 1539866031063 Magic number: 42374628 Hash of the previous block: 04a6735424357bf9af5a1467f8335e9427af714c0fb138595226d53beca5a05e Hash of the block: 0061924d48d5ce30e97cfc4297f3a40bc94dfac6af42d7bf366d236007c0b9d3 Block data: miner9 sent 10 VC to Bob miner7 sent 10 VC to Alice Nick sent 1 VC to ShoesShop Nick sent 2 VC to FastFood Nick sent 15 VC to CarShop miner7 sent 90 VC to CarShop Block was generating for 0 seconds N was increased to 3

Block: Created by miner2 miner2 gets 100 VC Id: 4 Timestamp: 1539866256729 Magic number: 45382978 Hash of the previous block: 0061924d48d5ce30e97cfc4297f3a40bc94dfac6af42d7bf366d236007c0b9d3 Hash of the block: 000856a20d767fbbc38e0569354400c1750381100984a09a5d8b1cdf09b0bab6 Block data: CarShop sent 10 VC to Worker1 CarShop sent 10 VC to Worker2 CarShop sent 10 VC to Worker3 CarShop sent 30 VC to Director1 CarShop sent 45 VC to CarPartsShop Bob sent 5 VC to GamingShop Alice sent 5 VC to BeautyShop Block was generating for 5 seconds N was increased to 4

... (another 10 blocks, so the output contains 15 blocks)

blockchain's People

Contributors

evardanyan avatar edg4rv avatar

Watchers

 avatar

Forkers

evardanyan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.