All Projects → Carlos-Zen → Blockchain Python

Carlos-Zen / Blockchain Python

A blockchain implementation in Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Blockchain Python

Blockchain Java
A simplified blockchain implementation in Java
Stars: ✭ 160 (-31.33%)
Mutual labels:  blockchain, bitcoin, blockchain-technology
Udacity Blockchain Developer Nanodegree
The road so far on Udacity Blockchain Developer Nanodegree
Stars: ✭ 53 (-77.25%)
Mutual labels:  blockchain, bitcoin, blockchain-technology
Xdag
XDAG (Dagger Coin) Official Main Repository. XDAG is a novel DAG based cryptocurrency.
Stars: ✭ 297 (+27.47%)
Mutual labels:  blockchain, bitcoin, blockchain-technology
Dotcoin
A simple and integrity blockchain implementation in Golang
Stars: ✭ 89 (-61.8%)
Mutual labels:  blockchain, bitcoin, block
My First Bitcoin Miner
For the curious minds who want to understand how Bitcoin Blockchain works!
Stars: ✭ 110 (-52.79%)
Mutual labels:  blockchain, bitcoin, blockchain-technology
Diadata
DIAdata.org platform
Stars: ✭ 103 (-55.79%)
Mutual labels:  blockchain, bitcoin, blockchain-technology
Blockchaintechnology
Blockchain Frontier Technology Tracking
Stars: ✭ 88 (-62.23%)
Mutual labels:  blockchain, bitcoin, blockchain-technology
Chainabstractionlayer
Blockchain abstraction layer
Stars: ✭ 131 (-43.78%)
Mutual labels:  rpc, blockchain, bitcoin
Bitcoin Transaction Explorer
Simple and pure block explorer you can run on top of a full node
Stars: ✭ 165 (-29.18%)
Mutual labels:  blockchain, bitcoin, block
Gitmoney
A platform designed to help people work from anywhere and get paid bitcoin.
Stars: ✭ 187 (-19.74%)
Mutual labels:  blockchain, bitcoin
Node
The core of Po.et
Stars: ✭ 192 (-17.6%)
Mutual labels:  blockchain, bitcoin
Bitcoin On Nodejs
《Node.js区块链开发》,注:新版代码已开源!请star支持哦-^-:
Stars: ✭ 2,321 (+896.14%)
Mutual labels:  blockchain, bitcoin
Ecdsa Private Key Recovery
A simple library to recover the private key of ECDSA and DSA signatures sharing the same nonce k and therefore having identical signature parameter r
Stars: ✭ 186 (-20.17%)
Mutual labels:  blockchain, bitcoin
Ultimateicocalendar
The ICO calendar to end all ICO calendars
Stars: ✭ 183 (-21.46%)
Mutual labels:  blockchain, blockchain-technology
Factomd
Factom Daemon
Stars: ✭ 197 (-15.45%)
Mutual labels:  blockchain, bitcoin
Blockchainwallet Crypto
比特币、以太坊公私钥生成以及签名,长时间不维护可移步 https://github.com/QuincySx/ChainWallet
Stars: ✭ 183 (-21.46%)
Mutual labels:  blockchain, bitcoin
Adamant Im
ADAMANT Decentralized Messenger. Progressive Web Application (PWA)
Stars: ✭ 202 (-13.3%)
Mutual labels:  blockchain, bitcoin
Bitcoin S
Bitcoin Implementation in Scala
Stars: ✭ 206 (-11.59%)
Mutual labels:  blockchain, bitcoin
Blockvotes
An e-voting system based on blockchain using ring signature
Stars: ✭ 182 (-21.89%)
Mutual labels:  blockchain, bitcoin
Golden Wallet React Native
Golden - Best Wallet Ever
Stars: ✭ 201 (-13.73%)
Mutual labels:  blockchain, bitcoin

中文说明

Blockchain-python

A blockchain implementation in Python only for study.

The Blockchain-python implements simple blockchain and transactions. Currently, the implementation already has mining, transaction, communication between nodes, and file persistence of blocks and transactions.
The communication between nodes is via rpc based on http, rather than p2p network. Because the implementation of P2p is more complicated, it is too complicated to understand the framework of blockchain.
The verification based on cryptography has not yet been realized, and the verification of blocks between nodes and the verification of transactions have not yet been realized.

Installation

  1. Make sure Python 3.6+ is installed.
  2. Git Clone
$ git clone https://github.com/Carlos-Zen/blockchain.git
$ cd blockchain

Usage

  • Create Account
$ python console account create
  • Run the miner
$ python console miner start 3008
  • Transaction transfer.
$ python console tx transfer from_address to_address amount
  • Transaction list.
$ python console tx list
  • Blockchain shows.
$ python console blockchain list

Node Network

Copy the code resource to a new directory.While the miner before was running then:

$ cd {another_blockchain_directory}
$ python console node add 3008 
$ python console node run 3009

When a new block mined , block and transactions will broadcast to other nodes.

All command

Use like this:

$ python console [module] [action] params...

Such as:

$ python console tx list
Module Action Params Desc
account create NONEED Create new account
account get NONEED Show all account
account current NONEED The miner reward account
miner start ip:port/port Such as 3008 or 127.0.0.1:3008
node run ip:port/port Such as 3008 or 127.0.0.1:3008
node list NONEED Show all node that will broadcast to
node add ip:port Add a node that will broadcast to
tx transfer from_address to_address amount Transfer coin from from_address to to_address
tx list NONEED Show all transactions

Introduce

About block

The blockchain is a data structure that is linked sequentially from back to forward by blocks containing transaction information. SHA256 cryptographic hashing is performed on each block header to generate a hash value. A bitcoin block is as follows:

{
 "size":43560,
 "version":2,

 "previousblockhash":"00000000000000027e7ba6fe7bad39faf3b5a83daed765f05f7d1b71a1632249",
 "merkleroot":"5e049f4030e0ab2debb92378f53c0a6e09548aea083f3ab25e1d94ea1155e29d",
 "time":1388185038,
 "difficulty":1180923195.25802612,
 "nonce":4215469401,
 "tx":["257e7497fb8bc68421eb2c7b699dbab234831600e7352f0d9e6522c7cf3f6c77",
  #[...many more transactions omitted...]
  "05cfd38f6ae6aa83674cc99e4d75a1458c165b7ab84725eda41d018a09176634"
 ]
}

A blockchain is a linked list structure of blocks. The essence of mining is a new block, based on existing information such as parent block hash, timestamp, transaction merkle hash, plus a nonce (number from 0)
A sha256 representation string is generated after the connection. If the preceding digits start with several zeroes, the number of zeros is the difficulty of mining, and half is dynamically adjusted based on the remaining number and the generation speed of the previous block, such as:

00000000000000027e7ba6fe7bad39faf3b5a83daed765f05f7d1b71a1632249

Successful mining, block generation

About Blockchain-python block

Blockchain-python simplified block structure, a blockchain-python block data is as follows:

{
	"index": 7,
	"timestamp": 1528972070,
	"tx": [
        "b959b3d2099ca304c67087edbf05b79d1f2501b1f407df5e51a1a8c22bb3334d",
        "613e4af7266e01ea338d30681ef606bad26e4cdfa4ec7a6f431e22420c8291fd",
        "be7095a764cb241606a67c9064bc8dbc2da2370d49459bd492473ea5ce304cb3"
    ],
	"previous_block": "00003e17e04d9c9d2c2f5629de20bda58f59af36417a7e50eb77a74a028b026a",
	"nouce": 11063,
	"hash": "00006805c75d0db1685616d9ea5730f6203eda744a16fcc78ef1f3c244083ea4"
}

The calculation of block hash is roughly the same as that of Bitcoin. Our difficulty setting is relatively low, so the hash in front of this block has only 4 zeros.
This is for easier mining to understand the principle and generally can be produced in a few seconds. One block. In addition, Bitcoin's tx field represents the root node hash of the merkle tree that consists of the transaction hash.
For simplicity, we put it directly into the array of transaction hash.

About miner

The sha256 used by the mining algorithm, Bitcoin's algorithm is based on the block header +Nouce (a number) as a string. Simple blockchain simplifies the header information, but the mechanism and Bitcoin are constant. The blockchain is stored locally in the file in json format. The generation of a block is related to the transaction information, so the block information is also stored when the block is stored. There will be rewards for mining, and the reward will be recorded as the first transaction in the blockchain.

  • Rewards for mining are rewarded by the generated block itself
  • The miner also gets the amount entered for all transactions in the block - the amount of money that was exported
  • There will be some sorting rules for the transactions to be certified, sorting according to the block age, transaction fee, transaction amount, etc.

We simplified the implementation and only implemented rewards. The reward will be awarded to the current account. If the current account does not exist, please generate an account through the following command line:

$ python console account create

About network

The blockchain network is a P2P (Peer-to-Peer, end-to-end) network. We use Python's own RPC mechanism for simplification.

  • Different nodes can be connected by adding node operations
  • Unicom's nodes will automatically spread new transaction information
  • The new node will synchronize all the data of other node's blockchain while ensuring the maximum chain
  • Digging out new blocks will notify other nodes to synchronize

About transaction

Bitcoin uses the UTXO model and does not directly exist in the concept of “balance”. The balance needs to be obtained by traversing the entire transaction history. We also implement this mechanism. A transaction is a combination of some input and output. In our transaction, we accept multiple inputs and generate multiple outputs.

  • The calculation of the balance is made through the unconsumed verified transaction output - the output of the consumer transaction, which is commonly known as UTXO
  • Transactions not placed in new block will be broadcast to all nodes waiting to be verified
  • After waiting for the miner to dig into a new block, the trade will be saved as transaction information in the transaction database.

The correctness check of the transaction is under development.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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].