Skip to content

Much of the implementation details and inspiration have been taken from Savjee Coin. This could be treated as a distributed version of Savjee Coin.

Notifications You must be signed in to change notification settings

debdeepB/Bitcoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bitcoin

This is an implementation of a small subset of the Bitcoin protocol in Elixir. Much of the implementation details and inspiration have been taken from Savjee Coin. This could be treated as a distributed version of Savjee Coin.

For those of you who want to understand what Blockchain is all about I'd recommend you read this blogpost and then come back to this to understand how it could be applied in a distributed setting.

Much thanks to Savjee for making Blockchain super easy to understand!

Setup

Get the dependencies. "poison" is used for encoding maps to json.

mix deps.get

To run all tests run:

mix test

Blockchain Features

Distributed functionality

Each peer has it's own copy of blockchain. Each peer can mine and transact bitcoins. Whenever a peer mines a block, it adds it to it's blockchain and broadcasts it to the rest of the peers. All the other peers validates the incoming block and if it is valid then they add it to their respective blockchains. Peers can mine and transact bitcoins simulataneously. The blockchain increases dynamically and remains valid through out it's lifecycle.

Crypto

Every Peer would have it's own public and private key. While signing a transaction, the peer signs it with it's private key and while verifying a transaction it is done with the public key given in the from_address field in the transaction. The erlang crypto library is used for signing and verification and hashing and the elliptic curve secp256k1 is used as is given in the bitcoin documentation.

Mine Bitcoins

A peer can mine bitcoins. The difficulty threshold is kept at 2 leading 0's but can be increased to any arbitary number. A mining reward is given to the peer who mines a block succesfully.

Implement Wallets

Wallets are implemented and peers in the network can check their balance.

Transact Bitcoins

Peers can perform transactions after digitally signing them and send bitcoins to each other. Everything gets recorded in the transaction ledger (PendingTransactions)which gets mined when a peer mines a new block.

Installation

If available in Hex, the package can be installed by adding bitcoin to your list of dependencies in mix.exs:

def deps do
  [
    {:bitcoin, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/bitcoin.

About

Much of the implementation details and inspiration have been taken from Savjee Coin. This could be treated as a distributed version of Savjee Coin.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages