{ "info": { "author": "Rishi kant", "author_email": "rshkntshrm@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# Blockchain\n---\nWiki: A blockchain is a continuously growing list of records, called blocks, which are linked and secured using cryptography\n\nNote: It is NOT secure neither a real blockchain and you should NOT use this for anything else than educational purposes.\n\n### Features:\n```\n==> Blockchain Client\n\n* Wallet generation using public key cryptography\n\n* Can create a new transaction & submit it to network\n\n==> Blockchain Network\n\n* Transactions with RSA encryption\n\n* Coin mining\n\n* Proof of work(Hash algo: sha256)\n\n* Coin incentive\n\n* Node resolve conflict\n\n```\n### Install:\n```\npip install blockchainpy\n```\n\n### Examples:\n\n## Create wallet\n\n==> It's a key-pair of `privat_key` & `address`. Address is public address to recieve coin. Private-key is use to send coins to some address.\n\n```\nIn [1]: from blockchain.client import create_wallet\n\nIn [2]: alice_wallet = create_wallet()\n\nIn [3]: bob_wallet = create_wallet()\n\nIn [4]: print alice_wallet\n{'private_key': u'3082025b02010002818100a14e2c39b663192c1f191b97e0448da2e4a49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c199008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f35409020301000102818059f5c50872c595d65b899f2ff6ad84e861e7c05f598a4b75f737e6b8e1df9cf183dff292db850d27b0a7274de8f551308056fc0fb74bb22ef6e2238c17f1239af2ca25a20dc7b78de01df3681dcf452b8b3e549c0bb4079b510cf7d7df4c9ae18f3d96b786e3b194c3c95e53dd4aaf95b4540c1dd2d4e9367ab6836890aaf201024100c9906133f3a7c42326f742469fb29ebf358c0e3a2049f517f519db7063dd9a3d0183e42974c242d0c73992d10fa9ee6c2846f03d4f6d0a6548f82e66867d3629024100ccde6a2152f3a216b3a56a9e062a714c7e31f9620716578840d415bd0da22e2526486840bb12165e9320e6f49e786c159034b90d665e7b71eaac14b5ec642ae10240212de7124a357f8fd9c631deb6430ce6a4c5dd41ac370065652f5073fbbc6abb481891e25119f92dacddc95128a6ec5c5974f3eee3b82b51e8e5119e46dd2da102407ef59ec3c40a63fab99ddb72ced3629f4add6174d47b8e074c55a29b2465cb3f0e7874d3189b5eed813434ac87c08d0ad7f134750f69a20ab8a9a7b40e290d4102402a9aeaeb5d1a10c191dac5ccf12a91f1dfa8db5b01adf110f52fc35991c569cb42d6bab579b8a15b99da88fdfb0f1c78b581834535e94541b02260ea697eab0e', 'address': u'30819f300d06092a864886f70d010101050003818d0030818902818100a14e2c39b663192c1f191b97e0448da2e4a49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c199008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f354090203010001'}\n\n```\n\n## Check balance\n\n==> Amount of coins that particular address have.\n\n```\nIn [5]: from blockchain.network import check_balance\n\nIn [6]: print check_balance(alice_wallet['address'])\nNone\n\nIn [7]: print check_balance(bob_wallet['address'])\nNone\n\n```\n\n## Genesis block/transaction\n==> A genesis block is the first block of a block chain. The genesis block is almost always hardcoded into the software of the applications that utilize its block chain. It is a special case in that it does not reference a previous block.\\\n==> In our case, Genesis transaction will send 50 coin to given address.\\\n\n```\nIn [9]: create_genesis_transaction(alice_wallet['address'])\nOut[9]: \n{'block_number': 1,\n 'nonce': \"I'm special. I didn't go through mining process\",\n 'previous_hash': '00000',\n 'timestamp': 1529315091.63091,\n 'transactions': [OrderedDict([('sender_address', 'Author'),\n ('recipient_address',\n u'30819f300d06092a864886f70d010101050003818d0030818902818100a14e2c39b663192c1f191b97e0448da2e4a49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c199008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f354090203010001'),\n ('value', 50)])]}\n\nIn [10]: print check_balance(alice_wallet['address'])\n50\n```\n\n## Create new transaction\n==> One can create a transaction using blockchain client and submit it blockchain network. Miner will pick the transaction and add to blockchain if it is valid.\n==> Send 10 coin from Alice-wallet to Bob-wallet\n\n```\nIn [11]: from blockchain.client import\n\nIn [12]: txn=create_transaction(alice_wallet['address'], alice_wallet['private_key'], bob_wallet['address'], 10)\n ...:\n ...: sign = txn.get('signature')\n ...:\n ...: sender = txn.get('transaction').get('sender_address')\n ...:\n ...: reciver = txn.get('transaction').get('recipient_address')\n ...:\n ...: value = txn.get('transaction').get('value')\n ...:\n\nIn [13]: print txn\n{'transaction': OrderedDict([('sender_address',\nu'30819f300d06092a864886f70d010101050003818d0030818902818100a14e2c39b663192c1f191b97e0448da2e4a49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c199008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f354090203010001'),\n('recipient_address',\nu'30819f300d06092a864886f70d010101050003818d0030818902818100bed5a04c1ab5855f2329527d674a07a4ecd07ffbb1e662f319fb8eea04794eb4991340d1bae42c7adf75405007c355573b7629a16d211e39ba1d63cf8f17655ab92c95eb95d15b2e6730266e79c1b4e2e3a39978237ca09b7e35e87e41ae610f3442a557a91b85679534fe6cf768db4cee34324a3edf768801fe2411b01fee470203010001'),\n('value', 10)]), 'signature':\nu'78eba5404647d3e6ed9d34c6040226ab2924b03dcc2ee7706c5030d85b0cc7984cfa1572d63b461d8e2ad74b896d7966788a5ecda092428b3559655ee157bbef0361d4f69f9ff3748f8c9e455fa3dbf9a2e9916214d6485784e6c7a3b085ef36e674ec701763dfecf42795f590c28eb5e64cf1fca73bbba2c0f3cb5e6cb7aa77'}\n\n```\n\n## Mining\n==> One of the miner will pick the transaction & add it block if it is valid. In our case, we will have to manually submit the transaction to the network.\\\n==> To mine a block, miners need to find an extremely rare solution to a cryptographic puzzle. If a mined block is accepted by the blockchain, the miner receive a reward in coins which is an additional incentive to transaction fees. \\\n==> The mining process is also referred to as Proof of Work (PoW), and it's the main mechanism that enables the blockchain to be trustless and secure.\\\n\n```\nIn [14]: from blockchain.network import new_transaction\n\nIn [15]: new_transaction(sender, reciver, value, sign)\n\nIn [15]: new_transaction(sender, reciver, value, sign)\nOut[15]: {'message': 'Transaction will be added to Block 3'}\n\nIn [16]: from blockchain.network import mine\n\nIn [17]: mine()\nOut[17]: \n{'block_number': 3,\n 'message': 'New Block Forged',\n 'nonce': 104,\n 'previous_hash': 'feb69b361108c517144464d04a7dcb30a7f109ea48d74f0985f9efe97666bf9f',\n 'transactions': [OrderedDict([('sender_address',\n u'30819f300d06092a864886f70d010101050003818d0030818902818100a14e2c39b663192c1f191b97e0448da2e4a49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c199008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f354090203010001'),\n ('recipient_address',\n u'30819f300d06092a864886f70d010101050003818d0030818902818100bed5a04c1ab5855f2329527d674a07a4ecd07ffbb1e662f319fb8eea04794eb4991340d1bae42c7adf75405007c355573b7629a16d211e39ba1d63cf8f17655ab92c95eb95d15b2e6730266e79c1b4e2e3a39978237ca09b7e35e87e41ae610f3442a557a91b85679534fe6cf768db4cee34324a3edf768801fe2411b01fee470203010001'),\n ('value', 10)]),\n OrderedDict([('sender_address', 'THE BLOCKCHAIN'),\n ('recipient_address', '98ed1fd7b9c64327ba8bcc2f76631ddd'),\n ('value', 1)])]}\n```\n\n## Full chain\n\n==> Since blockchain is public ledger, one can check complete blockchain & can verify his/her transaction in chain\n```\nIn [18]: from blockchain.network import full_chain\n\nIn [19]: full_chain()\nOut[19]:\n{'chain': [{'block_number': 1,\n 'nonce': 0,\n 'previous_hash': '00',\n 'timestamp': 1529314632.98755,\n 'transactions': []},\n {'block_number': 1,\n 'nonce': \"I'm special. I didn't go through mining process\",\n 'previous_hash': '00000',\n 'timestamp': 1529315091.63091,\n 'transactions': [OrderedDict([('sender_address', 'Author'),\n ('recipient_address',\n u'30819f300d06092a864886f70d010101050003818d0030818902818100a14e2c39b663192c1f191b97e0448da2e4a\n49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c1\n99008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f3540902030\n10001'),\n ('value', 50)])]},\n {'block_number': 3,\n 'nonce': 104,\n 'previous_hash': 'feb69b361108c517144464d04a7dcb30a7f109ea48d74f0985f9efe97666bf9f',\n 'timestamp': 1529316112.395494,\n 'transactions': [OrderedDict([('sender_address',\n u'30819f300d06092a864886f70d010101050003818d0030818902818100a14e2c39b663192c1f191b97e0448da2e4a\n49599f318903af71e2c5b0061b68555fa86a37661fa66e391ba226f1b91b64cad657af93adbdd0b011150d6796b8512497ab79f92513d24c199008136b8d9ae8430559fead5ee00ba70afa4c5c4de56cdba1ef22c84f327be218047e7f9355c7d4a13bfa248703a141000b2f354090203010001'),\n ('recipient_address',\n u'30819f300d06092a864886f70d010101050003818d0030818902818100bed5a04c1ab5855f2329527d674a07a4ecd\n07ffbb1e662f319fb8eea04794eb4991340d1bae42c7adf75405007c355573b7629a16d211e39ba1d63cf8f17655ab92c95eb95d15b2e6730\n266e79c1b4e2e3a39978237ca09b7e35e87e41ae610f3442a557a91b85679534fe6cf768db4cee34324a3edf768801fe2411b01fee4702030\n10001'),\n ('value', 10)]),\n OrderedDict([('sender_address', 'THE BLOCKCHAIN'),\n ('recipient_address', '98ed1fd7b9c64327ba8bcc2f76631ddd'),\n ('value', 1)])]}],\n 'length': 3}\n```\n\n## Updated wallet balaces\n```\nIn [20]: print check_balance(alice_wallet['address'])\n40\n\nIn [21]: print check_balance(bob_wallet['address'])\n10\n```\n\n### ToDo:\n```\n* Balance verification should be done in mining step. Right now, it's in new-transaction method\n* Balance should get update after mining step.\n```\n\n### License\n\nSee the [LICENSE](LICENSE) file for license rights and limitations (MIT).", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/rishikant42/blockchain", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "blockchainpy", "package_url": "https://pypi.org/project/blockchainpy/", "platform": "", "project_url": "https://pypi.org/project/blockchainpy/", "project_urls": { "Homepage": "https://github.com/rishikant42/blockchain" }, "release_url": "https://pypi.org/project/blockchainpy/0.0.4/", "requires_dist": null, "requires_python": "", "summary": "A blockchain implementation in Python", "version": "0.0.4" }, "last_serial": 3972918, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "977f4cff645be417c3345a4b02d64d2f", "sha256": "d2c8f8ba3d93c85ba290c91e7492fe4fd3f1e1f47b41e89a38b48fe0fcd5d3e6" }, "downloads": -1, "filename": "blockchainpy-0.0.1.tar.gz", "has_sig": false, "md5_digest": "977f4cff645be417c3345a4b02d64d2f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1284, "upload_time": "2018-06-14T18:34:29", "url": "https://files.pythonhosted.org/packages/3c/55/dcac95d1b75ff552e05ef0f2b09d95d328c01b61f0a87b8c476e5a301045/blockchainpy-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "799921ead93cbd042e42dee416f5373c", "sha256": "62db1b19a58d1b48776cc7de3c69a912b8c7b48610be1d3af89adfd4410b58bc" }, "downloads": -1, "filename": "blockchainpy-0.0.2.tar.gz", "has_sig": false, "md5_digest": "799921ead93cbd042e42dee416f5373c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3544, "upload_time": "2018-06-15T07:22:31", "url": "https://files.pythonhosted.org/packages/22/e8/99b9567491f3b1d5d6adf6bea960a8e2dc7abb785ac12b74d3181acbb00f/blockchainpy-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "e736dc626ff082df757f669833e480e8", "sha256": "6c2542c2ce9e263ebad5fdef6bddae70533f36faf85035e5cc6c31932078b698" }, "downloads": -1, "filename": "blockchainpy-0.0.3.tar.gz", "has_sig": false, "md5_digest": "e736dc626ff082df757f669833e480e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6535, "upload_time": "2018-06-17T19:33:52", "url": "https://files.pythonhosted.org/packages/1f/7f/603d3fca0bf2347db10a030274c9efef29e03f36c8fe3dbb202e43a6b1bb/blockchainpy-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "6b53410724f57ec5689e7c1266409a59", "sha256": "8d0fc3ebe41ba3bc5ea3b5d5cf145536edfd3fa5b9186069f258409009e67065" }, "downloads": -1, "filename": "blockchainpy-0.0.4.tar.gz", "has_sig": false, "md5_digest": "6b53410724f57ec5689e7c1266409a59", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8518, "upload_time": "2018-06-18T10:22:16", "url": "https://files.pythonhosted.org/packages/80/ad/a5372b32ee9481e118dee5c32c05b38ff51314422a46726cc10086f4618a/blockchainpy-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6b53410724f57ec5689e7c1266409a59", "sha256": "8d0fc3ebe41ba3bc5ea3b5d5cf145536edfd3fa5b9186069f258409009e67065" }, "downloads": -1, "filename": "blockchainpy-0.0.4.tar.gz", "has_sig": false, "md5_digest": "6b53410724f57ec5689e7c1266409a59", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8518, "upload_time": "2018-06-18T10:22:16", "url": "https://files.pythonhosted.org/packages/80/ad/a5372b32ee9481e118dee5c32c05b38ff51314422a46726cc10086f4618a/blockchainpy-0.0.4.tar.gz" } ] }