All Projects → phishman3579 → Bitcoin

phishman3579 / Bitcoin

Licence: apache-2.0
An example Bitcoin implementation which can be used to learn about Bitcoin/Blockchain. This implementations is for educational use only!

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Bitcoin

Dex Protocols
A list of protocols for decentralized exchange
Stars: ✭ 109 (-5.22%)
Mutual labels:  blockchain
Bitcoin payable
A rails bitcoin payment processing gem
Stars: ✭ 111 (-3.48%)
Mutual labels:  blockchain
Udacity
➿ 💡 My Udacity projects that I have made to improve my skills and complete my nanodegree. Please don't use it to copy the projects. Submit the PR if you want something to be added to this repository.
Stars: ✭ 113 (-1.74%)
Mutual labels:  blockchain
Flow Go
A fast, secure, and developer-friendly blockchain built to support the next generation of games, apps, and the digital assets that power them.
Stars: ✭ 108 (-6.09%)
Mutual labels:  blockchain
Vscode Azure Blockchain Ethereum
Blockchain extension for VS Code
Stars: ✭ 111 (-3.48%)
Mutual labels:  blockchain
Catapult Server
Catapult server
Stars: ✭ 111 (-3.48%)
Mutual labels:  blockchain
Flow Go Sdk
Tools for building Go applications on Flow 🌊
Stars: ✭ 109 (-5.22%)
Mutual labels:  blockchain
Rust Abci
A rust implementation of the ABCI protocol for tendermint core
Stars: ✭ 115 (+0%)
Mutual labels:  blockchain
Blockapi
A general framework for blockchain analytics
Stars: ✭ 111 (-3.48%)
Mutual labels:  blockchain
Taquito
A library for building dApps on the Tezos Blockchain - JavaScript / TypeScript
Stars: ✭ 113 (-1.74%)
Mutual labels:  blockchain
Backend Ico Dashboard
Free & open-source dashboard for your next ICO, crowdsale or tokensale
Stars: ✭ 110 (-4.35%)
Mutual labels:  blockchain
Composer Sample Applications
⚠️ ⚠️ ⚠️ Hyperledger Composer has been deprecated ⚠️ ⚠️ ⚠️
Stars: ✭ 110 (-4.35%)
Mutual labels:  blockchain
Eth Cli
CLI swiss army knife for Ethereum developers
Stars: ✭ 109 (-5.22%)
Mutual labels:  blockchain
Awesome Iota
A community driven list of useful IOTA blogs, articles, videos and tools.
Stars: ✭ 109 (-5.22%)
Mutual labels:  blockchain
Nasa.js
星云链 DApp 客户端开发框架,轻量,易用 | Lightweight and friendly util library for DApp development on Nebulas Blockchain.
Stars: ✭ 115 (+0%)
Mutual labels:  blockchain
Polkadot Secure Validator
Polkadot Validator Secure Setup
Stars: ✭ 108 (-6.09%)
Mutual labels:  blockchain
Hydro Scaffold Dex
A Decentralized Exchange Scaffold - launch a DEX in minutes
Stars: ✭ 112 (-2.61%)
Mutual labels:  blockchain
Coursera Cryptocurrency
Assignments from the Coursera course "Bitcoin and Cryptocurrency Technologies"
Stars: ✭ 115 (+0%)
Mutual labels:  blockchain
Oasis Core
Performant and Confidentiality-Preserving Smart Contracts + Blockchains
Stars: ✭ 113 (-1.74%)
Mutual labels:  blockchain
Desktop
The official Musicoin Desktop Wallet Application
Stars: ✭ 112 (-2.61%)
Mutual labels:  blockchain

Bitcoin

An example Bitcoin implementation which can be used to learn about Bitcoin/Blockchain. This implementations is for educational use only.

Overview.

Wallet

The Wallet is how peers interact with the Bitcoin peer-to-peer network. The Wallet generates a public key and a private key which it uses to sign each Transaction. The pulic key is the send-to address used by the Bitcoin network. Each Wallet has the ability to send coins from your account to another account and it also has the ability to confirm Transactions (except it's own) which it receives from the Bitcoin peer-to-peer network.

    Wallet {
      sendCoin(entity, value); // Creates a new Transaction
      handleTransaction(Transaction); // Receives a unconfirmed Transaction
      handleConfirmation(Transaction); // Receives a confirmed Transaction and adds to blockchain
    }

Transaction

Transactions are just a collection of input transactions, output transactions, a value, and a signature.

    Transaction {
        byte[] header;
        Transaction[] inputs;
        Transaction[] outputs;
        long value;
        byte[] signature;
    }

See the Transaction Class for reference.

The Wallet also has a number of Transaction rules:

  • Once a Transaction has been used as an input, it cannot be used again.
  • All inputs on a Transaction have to be completely consumed on a transaction.

Note: To send a Bitcoin transaction, you have to already own a Bitcoin. Getting an initial Bitcoin is usually done by trading something for a number of Bitcoins. One caveat of, having to own a Bitcoin to make a transaction, is the first transaction. The first transaction is called the genesis transaction, it is the only transaction which does not need input transactions.

An example Transaction

If Justin wants to send 6 coins to George:

Ledger:

Justin's unused Transactions George's unused Transaction
Transaction #1 : 5 Coins
Transaction #2 : 3 Coins
Transaction #3 : 7 Coins
    Aggregate Transaction #4 {
      byte[]        header      "6 coins for George and 2 coins to Justin"
      Transaction[] input       { Transaction #1, Transaction #2 }
      Transaction[] output      { Transaction #5, Transaction #6 }
      int           value       0
      byte[]        signature   "Justin's signature based on the Header"
    }

Note: The 'value' on the Aggregate Transaction (#4) is a reward for anyone who confirms the Transaction. The higher the reward, the better chance the Transaction will be processed quicker.

    Transaction #5 {
      byte[]        header      "2 coins to Justin"
      Transaction[] input       { Transaction #1, Transaction #2 }
      Transaction[] output      { }
      int           value       2
      byte[]        signature   "Justin's signature based on the Header"
    }

    Transaction #6 {
      byte[]        header      "6 coins for George"
      Transaction[] input       { Transaction #1, Transaction #2 }
      Transaction[] output      { }
      int           value       6
      byte[]        signature   "Justin's signature based on the Header"
    }

The Aggregate Transaction (#4) will remove Transaction #1 and #2 from Justin's unused Transactions. Since the total of all inputs is 8 coins, which is 2 more than what Justin wants to send to George, the output will contain a Transaction which sends 2 coins back to Justin.

The Wallet will use it's private key to sign the Header of the Aggregate Transactions (#4) and it will also sign each of the output Transactions (#5 & #6). It will then send Transaction #4 to the Bitcoin network for confirmation.

Each peer on the Bitcoin network will receive the Transaction and try to confirm it.

To confirm a Transaction, a Peer will:

  • Check the Signature of Transaction against the public key of the sender.

If it passes:

  • Send the confirmed Transaction to the Bitcoin network.

Block

The confirmed Transaction (#4) is added to a pool of confirmed Transactions. Peers (also called Miners) will gather confirmed Transactions from the pool and put them into a Block. A Block contains a number of confirmed Transactions, the Miner's signature, and a couple of other fields used for "Proof of work" processing.

    Block {
      Transaction[]     transactions
      int               nonce
      int               zeros
      byte[]            previousHash
      byte[]            nextHash
      byte[]            signature
    }

See the Block Class for reference.

Miners will create a single 'block hash' from all the confirmed Transactions in the Block. They will then go through the process of "Proof of work". The goal of the "Proof of work" is to create a hash which begins with a random number of zeros (see the 'zeros' field). "Proof of work" is designed to be processor intensive which adds randomness to the time it takes to process a Block. A Miner will take the 'block hash' and append a random integer (called a 'nonce') to it. It will then create a new hash from 'block hash + nonce' and see if it satisfies the "Proof of work", this process will repeat until it finds a 'nonce' which satisfies the "Proof of work"

See the Proof of work for reference.

Once a Miner finds a 'nonce' which satisfies the "Proof of work", it will:

  • Create another hash (see 'nextHash') using the Blockchain's current hash (see 'previousHash') and the 'block hash'
  • Send the Block to the Bitcoin network.
    Block #1 {
      Transaction[]     transactions    { Transaction #4 }
      int               nonce           453;
      int               zeros           3;
      byte[]            previousHash    "Blockchain hash #1";
      byte[]            nextHash        "Blockchain hash #2";
      byte[]            signature       "Miner's signature";
    }

Peers on the Bitcoin network will receive the Block and start confirming it.

To confirm the Block, A Peer will:

  • Make sure the 'nonce' satisfies the "Proof of work"
  • Check the Block's signature
  • Check the signature of each Trasaction in the Block.

If everything passes:

  • Add the block to it's Blockchain.
  • Send the confirmed Block to the Bitcoin network

Blockchain

The Blockchain is a simple structure which contains a list of confirmed Blocks, a list of Transactions in chronological order, a list of unused Transactions, and the current hash.

Note: all transactions in the same block are said to have happened at the same time.

    Blockchain {
        List<Block>         blockchain
        List<Transactions>  transactions
        List<Transaction>   unused
        byte[]              currentHash
    }

See the Blockchain for reference.

When the Peer adds the Block to the Blockchain, the Blockchain will:

  • Check to see if the 'previousHash' from the Block matches it's 'currentHash',
  • Check to see if the input Transactions from all the Transactions in the Block are 'unused'

If everything passes:

  • The Block is added to the 'blockChain'
  • The Transaction is added to the 'transactions' list
  • All 'input' transactions are removed from the 'unused' list
  • All the 'output' transactions are added to the 'unused' list
  • The 'currentHash' is updated to 'nextHash' from the current Block.
    Blockchain {
        List<Block>         blockchain      { Block #0 }
        List<Transactions>  transactions    { Transaction #0 }
        List<Transaction>   unused          { Transaction #1, Transaction #2, Transaction #3 }
        byte[]              currentHash     "Blockchain hash #1"
    }

Updated Blockchain.

    Blockchain {
        List<Block>         blockchain      { Block #0, Block #1 };
        List<Transactions>  transactions    { Transaction #0, Transaction #4 }
        List<Transaction>   unused          { Transaction #3, Transaction #5, Transaction #6 }
        byte[]              currentHash     "Blockchain hash #2"
    }

Ledger:

Justin's unused Transactions George's unused Transaction
Transaction #3 : 7 Coins Transaction #6 : 6 Coins
Transaction #5 : 2 Coins

Based off of 1 and 2

Also see the original paper

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].