From 63939144715120f13b67be25f256a1d21ab21424 Mon Sep 17 00:00:00 2001 From: Holger Nahrstaedt <holger@nahrstaedt.de> Date: Wed, 14 Feb 2018 15:00:01 +0100 Subject: [PATCH] First step of replacing Bitshares by Steem --- LICENSE.txt | 1 + Makefile | 2 +- README.md | 10 +-- bitshares/__init__.py | 21 ----- bitsharesbase/__init__.py | 12 --- bitsharesbase/chains.py | 22 ----- bitsharesbase/objecttypes.py | 19 ---- bitsharesbase/operationids.py | 60 ------------- requirements-test.txt | 6 +- setup.py | 28 +++--- steem/__init__.py | 21 +++++ {bitshares => steem}/account.py | 2 +- {bitshares => steem}/aes.py | 12 ++- {bitshares => steem}/amount.py | 0 {bitshares => steem}/asset.py | 0 {bitshares => steem}/block.py | 0 {bitshares => steem}/blockchain.py | 0 {bitshares => steem}/blockchainobject.py | 0 {bitshares => steem}/committee.py | 0 {bitshares => steem}/dex.py | 0 {bitshares => steem}/exceptions.py | 0 {bitshares => steem}/instance.py | 12 +-- {bitshares => steem}/market.py | 0 {bitshares => steem}/memo.py | 0 {bitshares => steem}/message.py | 0 {bitshares => steem}/notify.py | 0 {bitshares => steem}/price.py | 0 {bitshares => steem}/proposal.py | 0 bitshares/bitshares.py => steem/steem.py | 14 +-- {bitshares => steem}/storage.py | 0 {bitshares => steem}/transactionbuilder.py | 0 {bitshares => steem}/utils.py | 0 {bitshares => steem}/vesting.py | 0 {bitshares => steem}/wallet.py | 0 {bitshares => steem}/witness.py | 2 +- {bitshares => steem}/worker.py | 0 {bitsharesapi => steemapi}/__init__.py | 2 +- {bitsharesapi => steemapi}/exceptions.py | 0 .../steemnoderpc.py | 8 +- {bitsharesapi => steemapi}/websocket.py | 2 +- steembase/__init__.py | 12 +++ {bitsharesbase => steembase}/account.py | 16 ++-- .../asset_permissions.py | 0 {bitsharesbase => steembase}/bip38.py | 0 steembase/chains.py | 21 +++++ {bitsharesbase => steembase}/memo.py | 0 {bitsharesbase => steembase}/objects.py | 88 ++----------------- steembase/objecttypes.py | 21 +++++ steembase/operationids.py | 69 +++++++++++++++ {bitsharesbase => steembase}/operations.py | 2 +- .../signedtransactions.py | 4 +- {bitsharesbase => steembase}/transactions.py | 0 tests/.ropeproject/globalnames | 4 - tests/.ropeproject/history | 1 - tests/.ropeproject/objectdb | 1 - tests/test_account.py | 12 +-- tests/test_aes.py | 2 +- tests/test_amount.py | 8 +- tests/{test_bitshares.py => test_steem.py} | 0 tests/test_utils.py | 2 +- tests/test_wallet.py | 18 ++-- tox.ini | 2 +- 62 files changed, 238 insertions(+), 301 deletions(-) delete mode 100644 bitshares/__init__.py delete mode 100644 bitsharesbase/__init__.py delete mode 100644 bitsharesbase/chains.py delete mode 100644 bitsharesbase/objecttypes.py delete mode 100644 bitsharesbase/operationids.py create mode 100644 steem/__init__.py rename {bitshares => steem}/account.py (99%) rename {bitshares => steem}/aes.py (82%) rename {bitshares => steem}/amount.py (100%) rename {bitshares => steem}/asset.py (100%) rename {bitshares => steem}/block.py (100%) rename {bitshares => steem}/blockchain.py (100%) rename {bitshares => steem}/blockchainobject.py (100%) rename {bitshares => steem}/committee.py (100%) rename {bitshares => steem}/dex.py (100%) rename {bitshares => steem}/exceptions.py (100%) rename {bitshares => steem}/instance.py (68%) rename {bitshares => steem}/market.py (100%) rename {bitshares => steem}/memo.py (100%) rename {bitshares => steem}/message.py (100%) rename {bitshares => steem}/notify.py (100%) rename {bitshares => steem}/price.py (100%) rename {bitshares => steem}/proposal.py (100%) rename bitshares/bitshares.py => steem/steem.py (99%) rename {bitshares => steem}/storage.py (100%) rename {bitshares => steem}/transactionbuilder.py (100%) rename {bitshares => steem}/utils.py (100%) rename {bitshares => steem}/vesting.py (100%) rename {bitshares => steem}/wallet.py (100%) rename {bitshares => steem}/witness.py (97%) rename {bitshares => steem}/worker.py (100%) rename {bitsharesapi => steemapi}/__init__.py (67%) rename {bitsharesapi => steemapi}/exceptions.py (100%) rename bitsharesapi/bitsharesnoderpc.py => steemapi/steemnoderpc.py (92%) rename {bitsharesapi => steemapi}/websocket.py (99%) create mode 100644 steembase/__init__.py rename {bitsharesbase => steembase}/account.py (87%) rename {bitsharesbase => steembase}/asset_permissions.py (100%) rename {bitsharesbase => steembase}/bip38.py (100%) create mode 100644 steembase/chains.py rename {bitsharesbase => steembase}/memo.py (100%) rename {bitsharesbase => steembase}/objects.py (76%) create mode 100644 steembase/objecttypes.py create mode 100644 steembase/operationids.py rename {bitsharesbase => steembase}/operations.py (99%) rename {bitsharesbase => steembase}/signedtransactions.py (91%) rename {bitsharesbase => steembase}/transactions.py (100%) delete mode 100644 tests/.ropeproject/globalnames delete mode 100644 tests/.ropeproject/history delete mode 100644 tests/.ropeproject/objectdb rename tests/{test_bitshares.py => test_steem.py} (100%) diff --git a/LICENSE.txt b/LICENSE.txt index 17eb27b4..2f26102e 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2015 Fabian Schuh + 2018 Holger Nahrstaedt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index e8e49e20..ad8b946e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ clean-pyc: find . -name '*~' -exec rm -f {} + lint: - flake8 bitsharesapi/ bitsharesbase/ bitshares/ + flake8 steemapi/ steembase/ steem/ test: python3 setup.py test diff --git a/README.md b/README.md index 5b62257a..3e586668 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,21 @@ -# Python Library for BitShares +# Python Library for Steem --- -## Documentation -Visit the [pybitshares website](http://docs.pybitshares.com/en/latest/) for in depth documentation on this Python library. ## Installation ### Install with pip: ``` $ sudo apt-get install libffi-dev libssl-dev python-dev python3-dev python3-pip -$ pip3 install bitshares +$ pip3 install steemi ``` ### Manual installation: ``` -$ git clone https://github.com/xeroc/python-bitshares/ -$ cd python-bitshares +$ git clone https://github.com/holgern/pySteemi/ +$ cd pySteemi $ python3 setup.py install --user ``` diff --git a/bitshares/__init__.py b/bitshares/__init__.py deleted file mode 100644 index 915ef88d..00000000 --- a/bitshares/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -from .bitshares import BitShares - -__all__ = [ - "bitshares" - "aes", - "account", - "amount", - "asset", - "block", - "blockchain", - "dex", - "market", - "storage", - "price", - "utils", - "wallet", - "committee", - "vesting", - "proposal", - "message" -] diff --git a/bitsharesbase/__init__.py b/bitsharesbase/__init__.py deleted file mode 100644 index 254d7deb..00000000 --- a/bitsharesbase/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -__all__ = [ - 'account', - 'bip38', - 'chains', - 'memo', - 'objects', - 'objecttypes', - 'operationids', - 'operations', - 'signedtransactions', - 'transactions', -] diff --git a/bitsharesbase/chains.py b/bitsharesbase/chains.py deleted file mode 100644 index ad801664..00000000 --- a/bitsharesbase/chains.py +++ /dev/null @@ -1,22 +0,0 @@ -known_chains = { - "BTS": { - "chain_id": "4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8", - "core_symbol": "BTS", - "prefix": "BTS"}, - "GPH": { - "chain_id": "b8d1603965b3eb1acba27e62ff59f74efa3154d43a4188d381088ac7cdf35539", - "core_symbol": "CORE", - "prefix": "GPH"}, - "TEST": { - "chain_id": "39f5e2ede1f8bc1a3a54a7914414e3779e33193f1f5693510e73cb7a87617447", - "core_symbol": "TEST", - "prefix": "TEST"}, - "Obelisk": { - "chain_id": "1cfde7c388b9e8ac06462d68aadbd966b58f88797637d9af805b4560b0e9661e", - "core_symbol": "GOV", - "prefix": "FEW"}, - "Scnrfp": { - "chain_id": "a8a61755aaa9d2c19a5989490bbc4195f37f147be3db3dddcf0e06d373b397ce", - "core_symbol": "SCNRFP", - "prefix": "SCNRFP"} -} diff --git a/bitsharesbase/objecttypes.py b/bitsharesbase/objecttypes.py deleted file mode 100644 index cf6e63dd..00000000 --- a/bitsharesbase/objecttypes.py +++ /dev/null @@ -1,19 +0,0 @@ -#: Object types for object ids -object_type = {} -object_type["null"] = 0 -object_type["base"] = 1 -object_type["account"] = 2 -object_type["asset"] = 3 -object_type["force_settlement"] = 4 -object_type["committee_member"] = 5 -object_type["witness"] = 6 -object_type["limit_order"] = 7 -object_type["call_order"] = 8 -object_type["custom"] = 9 -object_type["proposal"] = 10 -object_type["operation_history"] = 11 -object_type["withdraw_permission"] = 12 -object_type["vesting_balance"] = 13 -object_type["worker"] = 14 -object_type["balance"] = 15 -object_type["OBJECT_TYPE_COUNT"] = 16 diff --git a/bitsharesbase/operationids.py b/bitsharesbase/operationids.py deleted file mode 100644 index 6494d626..00000000 --- a/bitsharesbase/operationids.py +++ /dev/null @@ -1,60 +0,0 @@ -#: Operation ids -ops = [ - "transfer", - "limit_order_create", - "limit_order_cancel", - "call_order_update", - "fill_order", - "account_create", - "account_update", - "account_whitelist", - "account_upgrade", - "account_transfer", - "asset_create", - "asset_update", - "asset_update_bitasset", - "asset_update_feed_producers", - "asset_issue", - "asset_reserve", - "asset_fund_fee_pool", - "asset_settle", - "asset_global_settle", - "asset_publish_feed", - "witness_create", - "witness_update", - "proposal_create", - "proposal_update", - "proposal_delete", - "withdraw_permission_create", - "withdraw_permission_update", - "withdraw_permission_claim", - "withdraw_permission_delete", - "committee_member_create", - "committee_member_update", - "committee_member_update_global_parameters", - "vesting_balance_create", - "vesting_balance_withdraw", - "worker_create", - "custom", - "assert", - "balance_claim", - "override_transfer", - "transfer_to_blind", - "blind_transfer", - "transfer_from_blind", - "asset_settle_cancel", - "asset_claim_fees", - "fba_distribute", - "bid_collateral", - "execute_bid", -] -operations = {o: ops.index(o) for o in ops} - - -def getOperationNameForId(i): - """ Convert an operation id into the corresponding string - """ - for key in operations: - if int(operations[key]) is int(i): - return key - return "Unknown Operation ID %d" % i diff --git a/requirements-test.txt b/requirements-test.txt index 093b555d..4aef5cd1 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,7 +1,7 @@ graphenelib -pycryptodome==3.4.6 -scrypt==0.7.1 -Events==0.2.2 +pycryptodomex>=3.4.6 +scrypt>=0.7.1 +Events>=0.2.2 pyyaml pytest pytest-mock diff --git a/setup.py b/setup.py index 775fe813..9e8e7005 100755 --- a/setup.py +++ b/setup.py @@ -11,24 +11,24 @@ except LookupError: ascii = codecs.lookup('ascii') codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs')) -VERSION = '0.1.11' +VERSION = '0.19.0' setup( - name='bitshares', + name='steemi', version=VERSION, - description='Python library for bitshares', + description='Unofficial Python library for STEEM', long_description=open('README.md').read(), - download_url='https://github.com/xeroc/python-bitshares/tarball/' + VERSION, - author='Fabian Schuh', - author_email='Fabian@chainsquad.com', - maintainer='Fabian Schuh', - maintainer_email='Fabian@chainsquad.com', - url='http://www.github.com/xeroc/python-bitshares', - keywords=['bitshares', 'library', 'api', 'rpc'], + download_url='https://github.com/holgern/pySteemi/tarball/' + VERSION, + author='Holger Nahrstaedt', + author_email='holger@nahrstaedt.de', + maintainer='Holger Nahrstaedt', + maintainer_email='holger@nahrstaedt.de', + url='http://www.github.com/holgern/pySteemi', + keywords=['steem', 'library', 'api', 'rpc'], packages=[ - "bitshares", - "bitsharesapi", - "bitsharesbase" + "steem", + "steemapi", + "steembase" ], classifiers=[ 'License :: OSI Approved :: MIT License', @@ -45,7 +45,7 @@ setup( "appdirs", "Events", "scrypt", - "pycryptodome", # for AES, installed through graphenelib already + "pycryptodomex", # for AES, installed through graphenelib already ], setup_requires=['pytest-runner'], tests_require=['pytest'], diff --git a/steem/__init__.py b/steem/__init__.py new file mode 100644 index 00000000..8667d245 --- /dev/null +++ b/steem/__init__.py @@ -0,0 +1,21 @@ +#from .steem import Steem + +__all__ = [ + #"steem", + "aes", + #"account", + #"amount", + #"asset", + #"block", + #"blockchain", + #"dex", + #"market", + #"storage", + #"price", + "utils", + #"wallet", + #"committee", + #"vesting", + #"proposal", + #"message" +] diff --git a/bitshares/account.py b/steem/account.py similarity index 99% rename from bitshares/account.py rename to steem/account.py index a5b85d3b..d20b0854 100644 --- a/bitshares/account.py +++ b/steem/account.py @@ -1,4 +1,4 @@ -from bitshares.instance import shared_bitshares_instance +from steem.instance import shared_steem_instance from .exceptions import AccountDoesNotExistsException from .blockchainobject import BlockchainObject diff --git a/bitshares/aes.py b/steem/aes.py similarity index 82% rename from bitshares/aes.py rename to steem/aes.py index e665a467..8d0539bf 100644 --- a/bitshares/aes.py +++ b/steem/aes.py @@ -1,8 +1,14 @@ -from Crypto import Random -from Crypto.Cipher import AES import hashlib import base64 - +try: + from Cryptodome import Random + from Cryptodome.Cipher import AES +except ImportError: + try: + from Crypto import Random + from Crypto.Cipher import AES + except ImportError: + raise ImportError("Missing dependency: pyCryptodome") class AESCipher(object): """ diff --git a/bitshares/amount.py b/steem/amount.py similarity index 100% rename from bitshares/amount.py rename to steem/amount.py diff --git a/bitshares/asset.py b/steem/asset.py similarity index 100% rename from bitshares/asset.py rename to steem/asset.py diff --git a/bitshares/block.py b/steem/block.py similarity index 100% rename from bitshares/block.py rename to steem/block.py diff --git a/bitshares/blockchain.py b/steem/blockchain.py similarity index 100% rename from bitshares/blockchain.py rename to steem/blockchain.py diff --git a/bitshares/blockchainobject.py b/steem/blockchainobject.py similarity index 100% rename from bitshares/blockchainobject.py rename to steem/blockchainobject.py diff --git a/bitshares/committee.py b/steem/committee.py similarity index 100% rename from bitshares/committee.py rename to steem/committee.py diff --git a/bitshares/dex.py b/steem/dex.py similarity index 100% rename from bitshares/dex.py rename to steem/dex.py diff --git a/bitshares/exceptions.py b/steem/exceptions.py similarity index 100% rename from bitshares/exceptions.py rename to steem/exceptions.py diff --git a/bitshares/instance.py b/steem/instance.py similarity index 68% rename from bitshares/instance.py rename to steem/instance.py index 72c85a7e..389e237c 100644 --- a/bitshares/instance.py +++ b/steem/instance.py @@ -1,29 +1,29 @@ -import bitshares as bts +import steem as stm class SharedInstance(): instance = None -def shared_bitshares_instance(): +def shared_steem_instance(): """ This method will initialize ``SharedInstance.instance`` and return it. The purpose of this method is to have offer single default bitshares instance that can be reused by multiple classes. """ if not SharedInstance.instance: clear_cache() - SharedInstance.instance = bts.BitShares() + SharedInstance.instance = stm.Steem() return SharedInstance.instance -def set_shared_bitshares_instance(bitshares_instance): - """ This method allows us to override default bitshares instance for all users of +def set_shared_steem_instance(steem_instance): + """ This method allows us to override default steem instance for all users of ``SharedInstance.instance``. :param bitshares.bitshares.BitShares bitshares_instance: BitShares instance """ clear_cache() - SharedInstance.instance = bitshares_instance + SharedInstance.instance = steem_instance def clear_cache(): diff --git a/bitshares/market.py b/steem/market.py similarity index 100% rename from bitshares/market.py rename to steem/market.py diff --git a/bitshares/memo.py b/steem/memo.py similarity index 100% rename from bitshares/memo.py rename to steem/memo.py diff --git a/bitshares/message.py b/steem/message.py similarity index 100% rename from bitshares/message.py rename to steem/message.py diff --git a/bitshares/notify.py b/steem/notify.py similarity index 100% rename from bitshares/notify.py rename to steem/notify.py diff --git a/bitshares/price.py b/steem/price.py similarity index 100% rename from bitshares/price.py rename to steem/price.py diff --git a/bitshares/proposal.py b/steem/proposal.py similarity index 100% rename from bitshares/proposal.py rename to steem/proposal.py diff --git a/bitshares/bitshares.py b/steem/steem.py similarity index 99% rename from bitshares/bitshares.py rename to steem/steem.py index b10737d2..d25945c3 100644 --- a/bitshares/bitshares.py +++ b/steem/steem.py @@ -2,9 +2,9 @@ import json import logging from datetime import datetime, timedelta -from bitsharesapi.bitsharesnoderpc import BitSharesNodeRPC -from bitsharesbase.account import PrivateKey, PublicKey -from bitsharesbase import transactions, operations +from steemapi.bitsharesnoderpc import SteemNodeRPC +from steembase.account import PrivateKey, PublicKey +from steembase import transactions, operations from .asset import Asset from .account import Account from .amount import Amount @@ -24,7 +24,7 @@ from .utils import formatTime, test_proposal_in_buffer log = logging.getLogger(__name__) -class BitShares(object): +class Steem(object): """ Connect to the BitShares network. :param str node: Node to connect to *(optional)* @@ -157,13 +157,13 @@ class BitShares(object): rpcuser="", rpcpassword="", **kwargs): - """ Connect to BitShares network (internal use only) + """ Connect to Steem network (internal use only) """ if not node: if "node" in config: node = config["node"] else: - raise ValueError("A BitShares node needs to be provided!") + raise ValueError("A Steem node needs to be provided!") if not rpcuser and "rpcuser" in config: rpcuser = config["rpcuser"] @@ -171,7 +171,7 @@ class BitShares(object): if not rpcpassword and "rpcpassword" in config: rpcpassword = config["rpcpassword"] - self.rpc = BitSharesNodeRPC(node, rpcuser, rpcpassword, **kwargs) + self.rpc = SteemNodeRPC(node, rpcuser, rpcpassword, **kwargs) @property def prefix(self): diff --git a/bitshares/storage.py b/steem/storage.py similarity index 100% rename from bitshares/storage.py rename to steem/storage.py diff --git a/bitshares/transactionbuilder.py b/steem/transactionbuilder.py similarity index 100% rename from bitshares/transactionbuilder.py rename to steem/transactionbuilder.py diff --git a/bitshares/utils.py b/steem/utils.py similarity index 100% rename from bitshares/utils.py rename to steem/utils.py diff --git a/bitshares/vesting.py b/steem/vesting.py similarity index 100% rename from bitshares/vesting.py rename to steem/vesting.py diff --git a/bitshares/wallet.py b/steem/wallet.py similarity index 100% rename from bitshares/wallet.py rename to steem/wallet.py diff --git a/bitshares/witness.py b/steem/witness.py similarity index 97% rename from bitshares/witness.py rename to steem/witness.py index bd437935..eba4ce4d 100644 --- a/bitshares/witness.py +++ b/steem/witness.py @@ -1,4 +1,4 @@ -from bitshares.instance import shared_bitshares_instance +from steem.instance import shared_steem_instance from .account import Account from .exceptions import WitnessDoesNotExistsException from .blockchainobject import BlockchainObject diff --git a/bitshares/worker.py b/steem/worker.py similarity index 100% rename from bitshares/worker.py rename to steem/worker.py diff --git a/bitsharesapi/__init__.py b/steemapi/__init__.py similarity index 67% rename from bitsharesapi/__init__.py rename to steemapi/__init__.py index f6829daa..c4af794c 100644 --- a/bitsharesapi/__init__.py +++ b/steemapi/__init__.py @@ -1,5 +1,5 @@ __all__ = [ - "bitsharesnoderpc", + "steemnoderpc", "exceptions", "websocket", ] diff --git a/bitsharesapi/exceptions.py b/steemapi/exceptions.py similarity index 100% rename from bitsharesapi/exceptions.py rename to steemapi/exceptions.py diff --git a/bitsharesapi/bitsharesnoderpc.py b/steemapi/steemnoderpc.py similarity index 92% rename from bitsharesapi/bitsharesnoderpc.py rename to steemapi/steemnoderpc.py index e1ae4e67..a846d2a7 100644 --- a/bitsharesapi/bitsharesnoderpc.py +++ b/steemapi/steemnoderpc.py @@ -7,7 +7,7 @@ import json import time from itertools import cycle from grapheneapi.graphenewsrpc import GrapheneWebsocketRPC -from bitsharesbase.chains import known_chains +from steembase.chains import known_chains from . import exceptions import logging log = logging.getLogger(__name__) @@ -17,10 +17,10 @@ class NumRetriesReached(Exception): pass -class BitSharesNodeRPC(GrapheneWebsocketRPC): +class SteemNodeRPC(GrapheneWebsocketRPC): def __init__(self, *args, **kwargs): - super(BitSharesNodeRPC, self).__init__(*args, **kwargs) + super(SteemNodeRPC, self).__init__(*args, **kwargs) self.chain_params = self.get_network() def register_apis(self): @@ -39,7 +39,7 @@ class BitSharesNodeRPC(GrapheneWebsocketRPC): """ try: # Forward call to GrapheneWebsocketRPC and catch+evaluate errors - return super(BitSharesNodeRPC, self).rpcexec(payload) + return super(SteemNodeRPC, self).rpcexec(payload) except exceptions.RPCError as e: msg = exceptions.decodeRPCErrorMsg(e).strip() if msg == "missing required active authority": diff --git a/bitsharesapi/websocket.py b/steemapi/websocket.py similarity index 99% rename from bitsharesapi/websocket.py rename to steemapi/websocket.py index a4b6067a..f2422728 100644 --- a/bitsharesapi/websocket.py +++ b/steemapi/websocket.py @@ -14,7 +14,7 @@ log = logging.getLogger(__name__) # logging.basicConfig(level=logging.DEBUG) -class BitSharesWebsocket(Events): +class SteemWebsocket(Events): """ Create a websocket connection and request push notifications :param str urls: Either a single Websocket URL, or a list of URLs diff --git a/steembase/__init__.py b/steembase/__init__.py new file mode 100644 index 00000000..a10fcf08 --- /dev/null +++ b/steembase/__init__.py @@ -0,0 +1,12 @@ +__all__ = [ + #'account', + 'bip38', + #'chains', + #'memo', + #'objects', + #'objecttypes', + #'operationids', + #'operations', + #'signedtransactions', + #'transactions', +] diff --git a/bitsharesbase/account.py b/steembase/account.py similarity index 87% rename from bitsharesbase/account.py rename to steembase/account.py index 850a6f3d..169b0df6 100644 --- a/bitsharesbase/account.py +++ b/steembase/account.py @@ -48,16 +48,16 @@ class Address(GPHAddress): :param str address: Base58 encoded address (defaults to ``None``) :param str pubkey: Base58 encoded pubkey (defaults to ``None``) - :param str prefix: Network prefix (defaults to ``BTS``) + :param str prefix: Network prefix (defaults to ``STM``) Example:: - Address("BTSFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi") + Address("GPHFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi") """ def __init__(self, *args, **kwargs): if "prefix" not in kwargs: - kwargs["prefix"] = "BTS" # make prefix BTS + kwargs["prefix"] = "STM" # make prefix STM super(Address, self).__init__(*args, **kwargs) @@ -65,11 +65,11 @@ class PublicKey(GPHPublicKey): """ This class deals with Public Keys and inherits ``Address``. :param str pk: Base58 encoded public key - :param str prefix: Network prefix (defaults to ``BTS``) + :param str prefix: Network prefix (defaults to ``STM``) Example::: - PublicKey("BTS6UtYWWs3rkZGV8JA86qrgkG6tyFksgECefKE1MiH4HkLD8PFGL") + PublicKey("GPH6UtYWWs3rkZGV8JA86qrgkG6tyFksgECefKE1MiH4HkLD8PFGL") .. note:: By default, graphene-based networks deal with **compressed** public keys. If an **uncompressed** key is required, the @@ -80,7 +80,7 @@ class PublicKey(GPHPublicKey): """ def __init__(self, *args, **kwargs): if "prefix" not in kwargs: - kwargs["prefix"] = "BTS" # make prefix BTS + kwargs["prefix"] = "STM" # make prefix STM super(PublicKey, self).__init__(*args, **kwargs) @@ -89,7 +89,7 @@ class PrivateKey(GPHPrivateKey): constructs two instances of ``PublicKey``: :param str wif: Base58check-encoded wif key - :param str prefix: Network prefix (defaults to ``BTS``) + :param str prefix: Network prefix (defaults to ``STM``) Example::: @@ -109,5 +109,5 @@ class PrivateKey(GPHPrivateKey): """ def __init__(self, *args, **kwargs): if "prefix" not in kwargs: - kwargs["prefix"] = "BTS" # make prefix BTS + kwargs["prefix"] = "STM" # make prefix STM super(PrivateKey, self).__init__(*args, **kwargs) diff --git a/bitsharesbase/asset_permissions.py b/steembase/asset_permissions.py similarity index 100% rename from bitsharesbase/asset_permissions.py rename to steembase/asset_permissions.py diff --git a/bitsharesbase/bip38.py b/steembase/bip38.py similarity index 100% rename from bitsharesbase/bip38.py rename to steembase/bip38.py diff --git a/steembase/chains.py b/steembase/chains.py new file mode 100644 index 00000000..2a4d62af --- /dev/null +++ b/steembase/chains.py @@ -0,0 +1,21 @@ +known_chains = { + "STEEM": { + "chain_id": "0" * int(256 / 4), + "prefix": "STM", + "steem_symbol": "STEEM", + "sbd_symbol": "SBD", + "vests_symbol": "VESTS", + }, + "TEST": { + "chain_id": + "9afbce9f2416520733bacb370315d32b6b2c43d6097576df1c1222859d91eecc", + "prefix": + "TST", + "steem_symbol": + "TESTS", + "sbd_symbol": + "TBD", + "vests_symbol": + "VESTS", + }, +} diff --git a/bitsharesbase/memo.py b/steembase/memo.py similarity index 100% rename from bitsharesbase/memo.py rename to steembase/memo.py diff --git a/bitsharesbase/objects.py b/steembase/objects.py similarity index 76% rename from bitsharesbase/objects.py rename to steembase/objects.py index 2e96d9ae..3bedd32c 100644 --- a/bitsharesbase/objects.py +++ b/steembase/objects.py @@ -13,8 +13,13 @@ from .objecttypes import object_type from .account import PublicKey from graphenebase.objects import Operation as GPHOperation from .operationids import operations -default_prefix = "BTS" +default_prefix = "STM" +asset_precision = { + "STEEM": 3, + "VESTS": 6, + "SBD": 3, +} def AssetId(asset): return ObjectId(asset, "asset") @@ -48,7 +53,7 @@ class Operation(GPHOperation): super(Operation, self).__init__(*args, **kwargs) def _getklass(self, name): - module = __import__("bitsharesbase.operations", fromlist=["operations"]) + module = __import__("steembase.operations", fromlist=["operations"]) class_ = getattr(module, name) return class_ @@ -80,7 +85,7 @@ class Asset(GrapheneObject): ])) -class Memo(GrapheneObject): +class Permission(GrapheneObject): def __init__(self, *args, **kwargs): if isArgsThisClass(self, args): self.data = args[0].data @@ -291,83 +296,6 @@ class SpecialAuthority(Static_variant): super().__init__(data, id) -class Extension(Array): - def __str__(self): - """ We overload the __str__ function because the json - representation is different for extensions - """ - return json.dumps(self.json) - - -class AccountCreateExtensions(Extension): - def __init__(self, *args, **kwargs): - # Extensions ################################# - class Null_ext(GrapheneObject): - def __init__(self, kwargs): - super().__init__(OrderedDict([])) - - class Owner_special_authority(SpecialAuthority): - def __init__(self, kwargs): - super().__init__(kwargs) - - class Active_special_authority(SpecialAuthority): - def __init__(self, kwargs): - super().__init__(kwargs) - class Buyback_options(GrapheneObject): - def __init__(self, kwargs): - if isArgsThisClass(self, args): - self.data = args[0].data - else: - if len(args) == 1 and len(kwargs) == 0: - kwargs = args[0] -# assert "1.3.0" in kwargs["markets"], "CORE asset must be in 'markets' to pay fees" - super().__init__(OrderedDict([ - ('asset_to_buy', ObjectId(kwargs["asset_to_buy"], "asset")), - ('asset_to_buy_issuer', ObjectId(kwargs["asset_to_buy_issuer"], "account")), - ('markets', Array([ - ObjectId(x, "asset") for x in kwargs["markets"] - ])), - ])) - # End of Extensions definition ################ - if isArgsThisClass(self, args): - self.data = args[0].data - else: - if len(args) == 1 and len(kwargs) == 0: - kwargs = args[0] - self.json = dict() - a = [] - sorted_options = [ - "null_ext", - "owner_special_authority", - "active_special_authority", - "buyback_options" - ] - sorting = sorted(kwargs.items(), key=lambda x: sorted_options.index(x[0])) - for key, value in sorting: - self.json.update({key: value}) - if key == "null_ext": - a.append(Static_variant( - Null_ext({key: value}), - sorted_options.index(key)) - ) - elif key == "owner_special_authority": - a.append(Static_variant( - Owner_special_authority(value), - sorted_options.index(key)) - ) - elif key == "active_special_authority": - a.append(Static_variant( - Active_special_authority(value), - sorted_options.index(key)) - ) - elif key == "buyback_options": - a.append(Static_variant( - Buyback_options(value), - sorted_options.index(key)) - ) - else: - raise NotImplementedError("Extension {} is unknown".format(key)) - super().__init__(a) diff --git a/steembase/objecttypes.py b/steembase/objecttypes.py new file mode 100644 index 00000000..a98db28a --- /dev/null +++ b/steembase/objecttypes.py @@ -0,0 +1,21 @@ +#: Object types for object ids +object_type = {} +object_type["dynamic_global_property"] = 0 +object_type["reserved0"] = 1 +object_type["account"] = 2 +object_type["witness"] = 3 +object_type["transaction"] = 4 +object_type["block_summary"] = 5 +object_type["chain_property"] = 6 +object_type["witness_schedule"] = 7 +object_type["comment"] = 8 +object_type["category"] = 9 +object_type["comment_vote"] = 10 +object_type["vote"] = 11 +object_type["witness_vote"] = 12 +object_type["limit_order"] = 13 +object_type["feed_history"] = 14 +object_type["convert_request"] = 15 +object_type["liquidity_reward_balance"] = 16 +object_type["operation"] = 17 +object_type["account_history"] = 18 diff --git a/steembase/operationids.py b/steembase/operationids.py new file mode 100644 index 00000000..2c57ea9b --- /dev/null +++ b/steembase/operationids.py @@ -0,0 +1,69 @@ +#: Operation ids +ops = [ + 'vote', + 'comment', + 'transfer', + 'transfer_to_vesting', + 'withdraw_vesting', + 'limit_order_create', + 'limit_order_cancel', + 'feed_publish', + 'convert', + 'account_create', + 'account_update', + 'witness_update', + 'account_witness_vote', + 'account_witness_proxy', + 'pow', + 'custom', + 'report_over_production', + 'delete_comment', + 'custom_json', + 'comment_options', + 'set_withdraw_vesting_route', + 'limit_order_create2', + 'challenge_authority', + 'prove_authority', + 'request_account_recovery', + 'recover_account', + 'change_recovery_account', + 'escrow_transfer', + 'escrow_dispute', + 'escrow_release', + 'pow2', + 'escrow_approve', + 'transfer_to_savings', + 'transfer_from_savings', + 'cancel_transfer_from_savings', + 'custom_binary', + 'decline_voting_rights', + 'reset_account', + 'set_reset_account', + 'claim_reward_balance', + 'delegate_vesting_shares', + 'account_create_with_delegation', + 'fill_convert_request', + 'author_reward', + 'curation_reward', + 'comment_reward', + 'liquidity_reward', + 'interest', + 'fill_vesting_withdraw', + 'fill_order', + 'shutdown_witness', + 'fill_transfer_from_savings', + 'hardfork', + 'comment_payout_update', + 'return_vesting_delegation', + 'comment_benefactor_reward', +] +operations = {o: ops.index(o) for o in ops} + + +def getOperationNameForId(i): + """ Convert an operation id into the corresponding string + """ + for key in operations: + if int(operations[key]) is int(i): + return key + return "Unknown Operation ID %d" % i diff --git a/bitsharesbase/operations.py b/steembase/operations.py similarity index 99% rename from bitsharesbase/operations.py rename to steembase/operations.py index 696dd276..720ceaee 100644 --- a/bitsharesbase/operations.py +++ b/steembase/operations.py @@ -26,7 +26,7 @@ from .objects import ( AccountCreateExtensions ) -default_prefix = "BTS" +default_prefix = "STM" def getOperationNameForId(i): diff --git a/bitsharesbase/signedtransactions.py b/steembase/signedtransactions.py similarity index 91% rename from bitsharesbase/signedtransactions.py rename to steembase/signedtransactions.py index f5657501..d58fc5ce 100644 --- a/bitsharesbase/signedtransactions.py +++ b/steembase/signedtransactions.py @@ -17,10 +17,10 @@ class Signed_Transaction(GrapheneSigned_Transaction): def __init__(self, *args, **kwargs): super(Signed_Transaction, self).__init__(*args, **kwargs) - def sign(self, wifkeys, chain="BTS"): + def sign(self, wifkeys, chain="STM"): return super(Signed_Transaction, self).sign(wifkeys, chain) - def verify(self, pubkeys=[], chain="BTS"): + def verify(self, pubkeys=[], chain="STM"): return super(Signed_Transaction, self).verify(pubkeys, chain) def getOperationKlass(self): diff --git a/bitsharesbase/transactions.py b/steembase/transactions.py similarity index 100% rename from bitsharesbase/transactions.py rename to steembase/transactions.py diff --git a/tests/.ropeproject/globalnames b/tests/.ropeproject/globalnames deleted file mode 100644 index 08fd0f76..00000000 --- a/tests/.ropeproject/globalnames +++ /dev/null @@ -1,4 +0,0 @@ -€}q(Ubitsharesbase.operations]q(Udefault_prefixqUAsset_fund_fee_poolqUTransferqUAsset_publish_feedqUBid_collateralqUgetOperationNameForIdqUAccount_updateq U Asset_reserveq -U Worker_createqUAccount_upgradeqUAsset_update_feed_producersq UProposal_updateqUAccount_createqUVesting_balance_withdrawqUCall_order_updateqULimit_order_cancelqUAccount_whitelistqUWitness_updateqU -Op_wrapperqUOverride_transferqUProposal_createqUAsset_updateqULimit_order_createqeUpeerplays.committee]qU CommitteeqaUtest_amount]qU TestcasesqaUtest_txbuffers]q(UwifqheUbitshares.transactionbuilder]q (Ulogq!UProposalBuilderq"UTransactionBuilderq#eUbitshares.bitshares]q$(h!U BitSharesq%eUbitshares.exceptions]q&(UNoWalletExceptionq'UBlockDoesNotExistsExceptionq(UAssetDoesNotExistsExceptionq)UInsufficientAuthorityErrorq*U%CommitteeMemberDoesNotExistsExceptionq+UMissingKeyErrorq,UWorkerDoesNotExistsExceptionq-UProposalDoesNotExistExceptionq.UInvalidAssetExceptionq/UWitnessDoesNotExistsExceptionq0UWalletExistsq1UWrongMasterPasswordExceptionq2UInvalidWifErrorq3U$VestingBalanceDoesNotExistsExceptionq4UObjectNotInProposalBufferq5UAccountDoesNotExistsExceptionq6UAccountExistsExceptionq7eUtest_proposals]q8(hheUbitshares.price]q9(U PriceFeedq:UUpdateCallOrderq;UOrderq<UFilledOrderq=UPriceq>eUbitsharesbase.objects]q?(hh>h:UAccountOptionsq@UWorker_initializerqAUMemoqBU -PermissionqCUAssetqDU AccountIdqEUAccountCreateExtensionsqFUAssetIdqGUSpecialAuthorityqHU ExtensionqIU OperationqJUAssetOptionsqKUObjectIdqLeUbitshares.account]qM(UAccountqNU AccountUpdateqOeUtest_objectcache]qPhaUtest_bitshares]qQ(hhU core_unitqReUtest_wallet]qS(hheUpeerplays.witness]qT(U WitnessesqUUWitnessqVeu. \ No newline at end of file diff --git a/tests/.ropeproject/history b/tests/.ropeproject/history deleted file mode 100644 index fcd9c963..00000000 --- a/tests/.ropeproject/history +++ /dev/null @@ -1 +0,0 @@ -€]q(]q]qe. \ No newline at end of file diff --git a/tests/.ropeproject/objectdb b/tests/.ropeproject/objectdb deleted file mode 100644 index 29c40cda..00000000 --- a/tests/.ropeproject/objectdb +++ /dev/null @@ -1 +0,0 @@ -€}q. \ No newline at end of file diff --git a/tests/test_account.py b/tests/test_account.py index 6dfe2aa8..1a3f12c3 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -1,12 +1,12 @@ import unittest import mock from pprint import pprint -from bitshares import BitShares -from bitshares.account import Account -from bitshares.amount import Amount -from bitshares.asset import Asset -from bitshares.instance import set_shared_bitshares_instance -from bitsharesbase.operationids import getOperationNameForId +from steem import Steem +from steem.account import Account +from steem.amount import Amount +from steem.asset import Asset +from steem.instance import set_shared_bitshares_instance +from steembase.operationids import getOperationNameForId wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" diff --git a/tests/test_aes.py b/tests/test_aes.py index e2ad8e19..fc2a0b5f 100644 --- a/tests/test_aes.py +++ b/tests/test_aes.py @@ -3,7 +3,7 @@ import random import unittest import base64 from pprint import pprint -from bitshares.aes import AESCipher +from steem.aes import AESCipher class Testcases(unittest.TestCase): diff --git a/tests/test_amount.py b/tests/test_amount.py index e255a95a..bf6985d5 100644 --- a/tests/test_amount.py +++ b/tests/test_amount.py @@ -1,8 +1,8 @@ import unittest -from bitshares import BitShares -from bitshares.amount import Amount -from bitshares.asset import Asset -from bitshares.instance import set_shared_bitshares_instance, SharedInstance +from steem import Steem +from steem.amount import Amount +from steem.asset import Asset +from steem.instance import set_shared_steem_instance, SharedInstance class Testcases(unittest.TestCase): diff --git a/tests/test_bitshares.py b/tests/test_steem.py similarity index 100% rename from tests/test_bitshares.py rename to tests/test_steem.py diff --git a/tests/test_utils.py b/tests/test_utils.py index 1629bda9..425bfb8c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,4 @@ -from bitshares.utils import assets_from_string +from steem.utils import assets_from_string def test_assets_from_string(): diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 07c46402..ebe3b5f6 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -1,12 +1,12 @@ import unittest import mock from pprint import pprint -from bitshares import BitShares -from bitshares.account import Account -from bitshares.amount import Amount -from bitshares.asset import Asset -from bitshares.instance import set_shared_bitshares_instance -from bitsharesbase.operationids import getOperationNameForId +from steem import Steem +from steem.account import Account +from steem.amount import Amount +from steem.asset import Asset +from steem.instance import set_shared_steem_instance +from steem.operationids import getOperationNameForId wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" @@ -16,12 +16,12 @@ class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.bts = BitShares( + self.stm = Steem( nobroadcast=True, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif] ) - self.bts.set_default_account("init0") - set_shared_bitshares_instance(self.bts) + self.stm.set_default_account("init0") + set_shared_steem_instance(self.stm) diff --git a/tox.ini b/tox.ini index 49ea0896..d49d40b0 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ commands= deps= flake8 commands= - flake8 --ignore=E501,F401 bitsharesapi bitsharesbase examples + flake8 --ignore=E501,F401 steemapi steembase examples [testenv:docs] basepython= -- GitLab