{ "info": { "author": "Alistair O'Brien", "author_email": "alistair.o'brien@ellesmere.com", "bugtrack_url": null, "classifiers": [], "description": "# BPL lib\n\n> A simple Python package for the Blockpool Blockchain\n\nThis is an easy-to-use Python package for interacting with a Blockpool Blockchain. This package provided the majority of the functionality provided by [BPL-JS](https://github.com/blockpool-io/BPL-js)\n\n## Features\n\n### Address\n- [x] from_secret\n- [x] from_public_key\n- [ ] from_private_key\n- [x] validate\n\n### Network\n- [x] use\n- [x] use_custom\n- [x] get_begin_epoch\n- [x] get_version\n\n### Transaction Entity\n- [x] generate\n- [x] get_id\n- [x] get_hash\n- [x] sign\n- [x] second_sign\n- [x] to_bytes\n- [x] to_dict\n- [x] from_dict\n- [x] verify\n- [x] second_verify\n\n### Transaction Types\n- [x] Transfer Transaction\n- [x] Vote Transaction\n- [x] Second Signature Transaction\n- [x] Multi-Signature Transaction\n- [x] Delegate Transaction\n- [x] IPFS Transaction\n\n### Time\n- [x] get_time\n- [x] get_real_time\n- [x] get_slot_number\n- [x] get_slot_time\n\n## Installation\n\n```sh \npython -m pip install --no-cache-dir --index-url https://test.pypi.org/simple/ bpl-lib\n```\n\nNote: package has been uploaded to test.pypi. Some dependencies might not be able to be install (e.g. base58) due to this. If this occurs use:\n```sh\npip install base58\npip install ecdsa\n```\n\nThen \n```sh \npython -m pip install --no-cache-dir --index-url https://test.pypi.org/simple/ bpl-lib\n```\n\n\n## Usage\n\nThere are 6 main sub-packages in bpl-lib:\n\n- ``bpl_lib.address``\n- ``bpl_lib.crypto``\n- ``bpl_lib.helpers``\n- ``bpl_lib.network``\n- ``bpl_lib.time``\n- ``bpl_lib.transactions``\n\n***\n\n### Addresses\n\n#### Generating an Address\n\nThere are currently 2 methods for generating an address:\n- ``from_public_key``\n- ``from_secret``\n\nNote: Addresses are dependent on the ``version`` of the network, therefore to generate an address you must first select a network (see network section).\n##### from_public_key\n\nTo generate a unique Blockpool address from a given public key:\n```python\nfrom bpl_lib.address import Address\nfrom bpl_lib.network import Network\n\nNetwork.use(\"mainnet\")\npublic_key = \"03aacac6c98daaf3d433fe90e9295ce380916946f850bcdc6f6880ae6503ca1e40\"\naddress = Address.from_public_key(public_key)\n\nprint(address)\n```\n\nPrinting:\n\n```python\nb'AdzCBJt2F2Q2RYL7vnp96QhTeGdDZNZGeJ'\n```\n\n##### from_secret\n\nTo generate a unique Blockpool address from a given secret passphrase:\n```python\nfrom bpl_lib.address import Address\nfrom bpl_lib.network import Network\n\nNetwork.use(\"mainnet\")\naddress = Address.from_secret(\"secret passphrase\")\n\nprint(address)\n```\n\nPrinting:\n\n```python\nb'AdzCBJt2F2Q2RYL7vnp96QhTeGdDZNZGeJ'\n```\n\n#### Validation\n\nNote: Addresses are dependent on the ``version`` of the network, therefore to validate an address you must first select a network (see network section).\n\n```python\nfrom bpl_lib.address import Address\nfrom bpl_lib.network import Network\n\nNetwork.use(\"mainnet\")\naddress = \"AdzCBJt2F2Q2RYL7vnp96QhTeGdDZNZGeJ\"\nis_valid = Address.validate(address)\n\nprint(is_valid)\n```\n\nPrinting:\n\n```python\nTrue\n```\n\n***\n\n### Cryptography\n\n#### Generating Keys\n```python\nfrom bpl_lib.crypto import Keys\n\nkeys = Keys(\"secret passphrase\").to_dict()\n\nprint(keys)\n```\n\nPrinting:\n\n```python\n{\n \"public_key\": \"03aacac6c98daaf3d433fe90e9295ce380916946f850bcdc6f6880ae6503ca1e40\",\n \"private_key\": \"b6a2b12beb4179538bfb42423cce2e98ccdebcc684145ba977f2f80630eb278e\"\n}\n```\n\n#### Signatures\n ```python\nfrom bpl_lib.crypto import Signature, sha256\n\nmessage = sha256(\"message\".encode())\nsignature = Signature(\"secret passphrase\").sign(message)[\"signature\"]\n\nprint(signature)\n```\n\nPrinting:\n```python\n\"30440220622b8edf8fc5cf4522a13489a9b710b1bf94b6e37722d2278a0069ae3c67088b0220206e202dcad8e4ee2100716ce0d2c7d08a685f983c21dfbccdd6ecec50268b6f\"\n```\n\n#### Hashing\nThe ``crypto`` sub-package also provides common hashing algorithms such as:\n- ``sha1(bytes)``\n- ``sha256(bytes)``\n- ``ripemd160(bytes)``\n- ``hash160(bytes)``\n- ``hash256(bytes)``\n\n***\n\n### Helpers\nThe helpers package contains useful contains and classes:\n- ``TRANSACTION_TYPE`` - Enum Class containing all 6 transaction types\n- ``TRANSACTION_FEES`` - Transaction fees depending on `TRANSACTION_TYPE`\n- ``NETWORKS_DB`` - Networks database file location\n\n***\n\n### Network\nThe networks sub-package is an interface for network configurations. The networks sub-package makes use of a local SQLite database, which stores the network identifier, begin epoch time and network version. These setting / fields are require for calculations such as addresses and timestamps.\n\n#### Using a network\nThere are current 2 methods that allows a client to use a network:\n- ``use``\n- ``use_custom``\n\n##### use\nThe `use` method requires a network ``identifier`` and queries the local network database for the specified configuration. The method then stores the configuration in memory. \n\n```python\nfrom bpl_lib.network import Network\n\nNetwork.use(\"mainnet\")\n\nprint(Network.get_begin_epoch())\nprint(Network.get_version())\n```\n\nPrinting:\n\n```python\n\"2017-03-21 13:00:00\"\n23\n```\n\n##### use_custom\nThe `use_custom` method requires a network `identifier`, `begin_epoch` and `version`. The method first inserts this custom configuration into the local network database, this will allow you to make use of the custom configuration in other applications. After that the method stores the custom configuration in memory. \n\nNote: ``identifier`` is used as the primary key in the database, this implies that the identifier for the network must be unique. If the identifier is not unique a `BPLNetworkException` is raised.\n```python\nfrom datetime import datetime \n\nfrom bpl_lib.network import Network\n\nidentifier = \"test_use_custom_method\"\nbegin_epoch = datetime.strptime(\"2018-07-25 15:30:00\", \"%Y-%m-%d %H:%M:%S\")\nversion = 0x19\n\nNetwork.use_custom(identifier, begin_epoch, version)\n\nprint(Network.get_begin_epoch())\nprint(Network.get_version())\n```\n\nPrinting:\n\n```python\n\"2018-07-25 15:30:00\"\n25\n```\n\n#### Accessing the current configuration\nAfter loading a network configuration into memory, there are 2 settings that can be accessed via the `Network` interface:\n- `begin_epoch`\n- `version`\n\n##### Accessing begin_epoch\nTo access `begin_epoch` the `Network.get_begin_epoch` method must be used. \n```python\nfrom bpl_lib.network import Network\n\nNetwork.use(\"testnet\")\n\nprint(Network.get_begin_epoch())\n```\n\nPrinting:\n\n```python\n\"2017-03-21 13:00:00\"\n```\n\n##### Accessing version\nTo access `version` the `Network.get_version` method must be used.\n```python\nfrom bpl_lib.network import Network\n\nNetwork.use(\"testnet\")\n\nprint(Network.get_version())\n```\n\nPrinting:\n```python\n82\n```\n\n***\n\n### Time\nThe time sub-package contains 4 methods:\n- `get_time` - returns the timestamp for the blockchain\n- `get_real_time` - converts blockchain timestamp to datetime\n- `get_slot_number` - converts blockchain timestamp to slot number\n- `get_slot_time` - converts slot number to blockchain timestamp\n\n#### get_time\nThe `get_time` method converts a datetime object to a blockchain timestamp. The method has an optional argument `time`. If `time` is not provided then the current time will be used. (See code)\n```python\nfrom bpl_lib.time import Time\n\nprint(Time.get_time())\n```\n\nPrinting:\n\n```python\n42429391\n```\n\n#### get_real_time\nThe `get_real_time` method converts a blockchain timestamp into a datetime object. The method has an optional argument `timestamp`. If `timestamp` is not provided then the current timestamp will be used. (See code)\n```python\nfrom bpl_lib.time import Time\n\nprint(Time.get_real_time(42429391))\n```\n\nPrinting:\n\n```python\n\"2018-07-25 14:56:31\"\n```\n\n#### get_slot_number\nThe `get_slot_number` method converts a blockchain timestamp into a slot number. The method has an optional argument `timestamp`. If `timestamp` is not provided then the current timestamp will be used. (See code)\n```python\nfrom bpl_lib.time import Time\n\nprint(Time.get_slot_number())\n```\n\nPrinting:\n\n```python\n5303721\n```\n\n#### get_slot_time\nThe `get_slot_time` method converts a slot number into a blockchain timestamp. The method has an optional argument `slot_number`. If `slot_number` is not provided then the current slot number will be used. (See code)\n```python\nfrom bpl_lib.time import Time\n\nprint(Time.get_slot_time(5303721))\n```\n\nPrinting:\n\n```python\n42429768\n```\n\n***\n\n### Transactions\nEach transaction is built from the Transaction Entity (See Features). There are 2 currently possible ways of building a BPL transaction:\n - `Transaction.generate`\n - `Transaction.from_dict`\n\n#### Buidling a transaction using generate\n`Transaction.generate` automatically calculates the timestamp for the transaction, therefore a network must be selected before a transaction can be built. (See network)\n\n```python\nfrom bpl_lib.transactions.Transfer import Transfer\nfrom bpl_lib.network import Network\n\nNetwork.use(\"mainnet\")\ntransaction = Transfer.generate(\"BCU4rocsgw2GNihtnzAgFzRfx7XebZRpRi\", 1000, \"passphrase\")\n\nprint(transaction.to_dict())\n```\nPrinting:\n\n```python\n{ \n 'recipientId': 'BCU4rocsgw2GNihtnzAgFzRfx7XebZRpRi',\n 'senderPublicKey': '02e012f0a7cac12a74bdc17d844cbc9f637177b470019c32a53cef94c7a56e2ea9',\n 'type': \"\",\n 'id': '9bfa3aee9ed984f856c6268b0b03dd908d3541c4c94f614fdae5c66c587560b2',\n 'asset': {},\n 'venderField': None,\n 'fee': 10000000,\n 'signature': '3045022100faf1e2bb7388caf0ba4ca26d6bddf9ea39197365d369f63efe271ad183745a77022047865c97baa925369ee099594010f7e7912772febbb83bcb9512f9b2759ac97d',\n 'timestamp': 42430405,\n 'amount': 1000,\n 'signSignature': None\n}\n```\n\nTo see how each transaction is built see the documentation in the code. \n\n***\n\n## Security or Errors\n\nIf you discover a security vulnerability or error within this package, please email [me](mailto:alistair.o'brien@ellesmere.com) or message me on the [BPL discord](https://discordapp.com/invite/67HxSKq).\n\n***\n\n## Credits\n\n- [Alistair O'Brien](https://github.com/johnyob)\n\n", "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/DuneRoot/bpl-lib", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "bpl-lib", "package_url": "https://pypi.org/project/bpl-lib/", "platform": "", "project_url": "https://pypi.org/project/bpl-lib/", "project_urls": { "Homepage": "https://github.com/DuneRoot/bpl-lib" }, "release_url": "https://pypi.org/project/bpl-lib/0.1.0/", "requires_dist": [ "base58 (>=1.0.0)", "ecdsa" ], "requires_python": "", "summary": "A library for the Blockpool Blockchain.", "version": "0.1.0" }, "last_serial": 4168826, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "b0158ba614de50ee1e4bbfeea00ae989", "sha256": "221d21d9a1aaac05a8dba55370babf101efead4a8b04d50774ac83bafd2beb80" }, "downloads": -1, "filename": "bpl_lib-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b0158ba614de50ee1e4bbfeea00ae989", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20918, "upload_time": "2018-08-14T10:33:38", "url": "https://files.pythonhosted.org/packages/79/ef/3d8008d42f80fac42d93b96d9601d53b4c9ce3dc0c37bbdf1bf176455f14/bpl_lib-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c8777c817c83500ae112c2053b010f89", "sha256": "b2315b88f0180cbae29d718937b9155d4b419e30a6ce608a59b353b1b252589a" }, "downloads": -1, "filename": "bpl-lib-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c8777c817c83500ae112c2053b010f89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13349, "upload_time": "2018-08-14T10:33:41", "url": "https://files.pythonhosted.org/packages/e9/56/c51ab871cf8b1d581cb1a18a89885e16ee27deeb043d31ac8cfdadb6de1c/bpl-lib-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b0158ba614de50ee1e4bbfeea00ae989", "sha256": "221d21d9a1aaac05a8dba55370babf101efead4a8b04d50774ac83bafd2beb80" }, "downloads": -1, "filename": "bpl_lib-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b0158ba614de50ee1e4bbfeea00ae989", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20918, "upload_time": "2018-08-14T10:33:38", "url": "https://files.pythonhosted.org/packages/79/ef/3d8008d42f80fac42d93b96d9601d53b4c9ce3dc0c37bbdf1bf176455f14/bpl_lib-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c8777c817c83500ae112c2053b010f89", "sha256": "b2315b88f0180cbae29d718937b9155d4b419e30a6ce608a59b353b1b252589a" }, "downloads": -1, "filename": "bpl-lib-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c8777c817c83500ae112c2053b010f89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13349, "upload_time": "2018-08-14T10:33:41", "url": "https://files.pythonhosted.org/packages/e9/56/c51ab871cf8b1d581cb1a18a89885e16ee27deeb043d31ac8cfdadb6de1c/bpl-lib-0.1.0.tar.gz" } ] }