From 0b2aa4c74e07f82128f6d0964aa55f9047abb5de Mon Sep 17 00:00:00 2001 From: alliswell Date: Wed, 9 Oct 2019 15:19:31 +0800 Subject: [PATCH 01/22] reinit --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..dd73c5d --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# PlatON-Tests +This project is an automated test project of the PaltON-Go. see: https://github.com/PlatONnetwork/PlatON-Go + +### Run test: +windows环境变量,需要先把./utils/ethkey和./utils/pubkey目录分别添加至环境变量中。 + +在项目目录中执行以下命令 +```js +python run.py --node='./deploy/node/4_node.yml' --case='all' + +``` +查看使用方式 +```js +python run.py -h +``` + + +### Dir introduce: +- [case](docs/case_example.md) +- common:主要包含一些公共使用的方法 +- conf:用于全局测试配置 +- data:一些必要的测试依赖文件,或者是数据驱动用例的数据 +- [deploy](docs/deploy.md) +- docs:一些文档 +- utils:基础库 From 94a44be44dfd3f74e5e0d83380e27e9ca940eedf Mon Sep 17 00:00:00 2001 From: awake Date: Tue, 22 Oct 2019 10:15:58 +0800 Subject: [PATCH 02/22] update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 48fba10..73b0b43 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.0', + version='0.3.1', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From e677a4a8296eda69a580c1e74ed076a935db024f Mon Sep 17 00:00:00 2001 From: awake Date: Tue, 29 Oct 2019 20:30:43 +0800 Subject: [PATCH 03/22] fix:ppos bug --- client_sdk_python/ppos.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 111c033..8a32927 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -330,8 +330,8 @@ def createRestrictingPlan(self, account, plan, pri_key, transaction_cfg=None): account = account[2:] plan_list = [] for dict_ in plan: - # v = [dict_[k] for k in dict_] - plan_list.append(dict_.values()) + v = [dict_[k] for k in dict_] + # plan_list.append(dict_.values()) rlp_list = rlp.encode(plan_list) data = rlp.encode([rlp.encode(int(4000)), rlp.encode(bytes.fromhex(account)), rlp_list]) return send_obj_transaction(self, data, self.web3.restrictingAddress, pri_key, transaction_cfg) diff --git a/setup.py b/setup.py index 73b0b43..18deb8f 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.1', + version='0.3.4', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 6b1dbea36bc44a2718d145a7edab458dee3b355b Mon Sep 17 00:00:00 2001 From: awake Date: Wed, 30 Oct 2019 13:53:20 +0800 Subject: [PATCH 04/22] fix transaction cfg bug --- client_sdk_python/utils/transactions.py | 17 +++++++++-------- setup.py | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client_sdk_python/utils/transactions.py b/client_sdk_python/utils/transactions.py index 9467b0b..d743459 100644 --- a/client_sdk_python/utils/transactions.py +++ b/client_sdk_python/utils/transactions.py @@ -42,24 +42,25 @@ def call_obj(obj, from_address, to_address, data): def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): + transaction_dict = {} if transaction_cfg is None: transaction_cfg = {} if transaction_cfg.get("gasPrice", None) is None: - transaction_cfg["gasPrice"] = obj.web3.platon.gasPrice + transaction_dict["gasPrice"] = obj.web3.platon.gasPrice if transaction_cfg.get("nonce", None) is None: raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() from_address = obj.web3.toChecksumAddress(raw_from_address) - transaction_cfg["nonce"] = obj.web3.platon.getTransactionCount(from_address) + transaction_dict["nonce"] = obj.web3.platon.getTransactionCount(from_address) if transaction_cfg.get("gas", None) is None: transaction_data = {"to": to_address, "data": data} - transaction_cfg["gas"] = obj.web3.platon.estimateGas(transaction_data) - transaction_cfg["chainId"] = obj.web3.chainId - transaction_cfg["to"] = to_address - transaction_cfg["data"] = data + transaction_dict["gas"] = obj.web3.platon.estimateGas(transaction_data) + transaction_dict["chainId"] = obj.web3.chainId + transaction_dict["to"] = to_address + transaction_dict["data"] = data if transaction_cfg.get("value", 0) > 0: - transaction_cfg["value"] = int(transaction_cfg.get("value", 0)) + transaction_dict["value"] = int(transaction_cfg.get("value", 0)) signed_transaction_dict = obj.web3.platon.account.signTransaction( - transaction_cfg, pri_key + transaction_dict, pri_key ) signed_data = signed_transaction_dict.rawTransaction tx_hash = HexBytes(obj.web3.platon.sendRawTransaction(signed_data)).hex() diff --git a/setup.py b/setup.py index 18deb8f..1f24df2 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.4', + version='0.3.5', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 99eafa213d54311fcbd32f64298cbcd968a2efe8 Mon Sep 17 00:00:00 2001 From: awake Date: Wed, 30 Oct 2019 14:12:38 +0800 Subject: [PATCH 05/22] fix transaction cfg bug --- client_sdk_python/utils/transactions.py | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/client_sdk_python/utils/transactions.py b/client_sdk_python/utils/transactions.py index d743459..5d743c3 100644 --- a/client_sdk_python/utils/transactions.py +++ b/client_sdk_python/utils/transactions.py @@ -47,6 +47,8 @@ def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): transaction_cfg = {} if transaction_cfg.get("gasPrice", None) is None: transaction_dict["gasPrice"] = obj.web3.platon.gasPrice + else: + transaction_dict["gasPrice"] = transaction_cfg["gasPrice"] if transaction_cfg.get("nonce", None) is None: raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() from_address = obj.web3.toChecksumAddress(raw_from_address) @@ -54,6 +56,8 @@ def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): if transaction_cfg.get("gas", None) is None: transaction_data = {"to": to_address, "data": data} transaction_dict["gas"] = obj.web3.platon.estimateGas(transaction_data) + else: + transaction_dict["gas"] = transaction_cfg["gas"] transaction_dict["chainId"] = obj.web3.chainId transaction_dict["to"] = to_address transaction_dict["data"] = data diff --git a/setup.py b/setup.py index 1f24df2..752a9d6 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.5', + version='0.3.6', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 3b6ddaf9ba38b47b03fe10823d1f37c430ffda84 Mon Sep 17 00:00:00 2001 From: awake Date: Thu, 31 Oct 2019 11:13:23 +0800 Subject: [PATCH 06/22] fix createRestrictingPlan --- client_sdk_python/ppos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 8a32927..0bc4ecf 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -331,7 +331,7 @@ def createRestrictingPlan(self, account, plan, pri_key, transaction_cfg=None): plan_list = [] for dict_ in plan: v = [dict_[k] for k in dict_] - # plan_list.append(dict_.values()) + plan_list.append(v) rlp_list = rlp.encode(plan_list) data = rlp.encode([rlp.encode(int(4000)), rlp.encode(bytes.fromhex(account)), rlp_list]) return send_obj_transaction(self, data, self.web3.restrictingAddress, pri_key, transaction_cfg) From c6d109598cb12db73081259ebe9ee048fb85399e Mon Sep 17 00:00:00 2001 From: awake Date: Mon, 4 Nov 2019 17:35:52 +0800 Subject: [PATCH 07/22] update version=0.3.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 752a9d6..46dc886 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.6', + version='0.3.7', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 42f49f68fe673a0e7aa924113c8eefe13347b9b6 Mon Sep 17 00:00:00 2001 From: awake Date: Tue, 5 Nov 2019 16:21:35 +0800 Subject: [PATCH 08/22] add pip param --- Dockerfile | 2 +- README.md | 4 ++-- client_sdk_python/pip.py | 33 +++++++++++++++++++-------------- client_sdk_python/ppos.py | 2 +- setup.py | 2 +- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6fecbdd..eb87d36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /usr/src/app # Install Linux dependencies RUN apt-get update && apt-get install -y libssl-dev -COPY client_sdk_python ./web3/ +COPY client_sdk_python ./client_sdk_python/ COPY tests ./tests/ COPY ens ./ens/ diff --git a/README.md b/README.md index 120bf89..581e638 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ Read more in the [documentation on ReadTheDocs](http://web3py.readthedocs.io/). ```python -from web3 import Web3, HTTPProvider -from web3.eth import PlatON +from client_sdk_python import Web3, HTTPProvider +from client_sdk_python.eth import PlatON from hexbytes import HexBytes # get blockNumber diff --git a/client_sdk_python/pip.py b/client_sdk_python/pip.py index 121dfa9..559088c 100644 --- a/client_sdk_python/pip.py +++ b/client_sdk_python/pip.py @@ -66,16 +66,14 @@ def submitVersion(self, verifier, pip_id, new_version, end_voting_rounds, pri_ke rlp.encode(int(new_version)), rlp.encode(int(end_voting_rounds))]) return send_obj_transaction(self, data, self.web3.pipAddress, pri_key, transaction_cfg) - def submitParam(self, verifier, url, end_voting_block, param_name, current_value, new_value, - pri_key, transaction_cfg=None): + def submitParam(self, verifier, pip_id, module, name, new_value, pri_key, transaction_cfg=None): """ - todo fill - :param verifier: - :param url: - :param end_voting_block: - :param param_name: - :param current_value: - :param new_value: + Submit an param proposal + :param verifier: The certified submitting the proposal + :param pip_id: PIPID + :param module: parameter module + :param name: parameter name + :param new_value: New parameter value :param pri_key: Private key for transaction :param transaction_cfg: Transaction basic configuration type: dict @@ -87,8 +85,8 @@ def submitParam(self, verifier, url, end_voting_block, param_name, current_value :return: if is need analyze return transaction result dict if is not need analyze return transaction hash """ - data = rlp.encode([rlp.encode(int(2002)), rlp.encode(bytes.fromhex(verifier)), rlp.encode(url), rlp.encode(int(end_voting_block)), - rlp.encode(param_name), rlp.encode(str(current_value)), rlp.encode(str(new_value))]) + data = rlp.encode([rlp.encode(int(2002)), rlp.encode(bytes.fromhex(verifier)), rlp.encode(pip_id), rlp.encode(module), + rlp.encode(name), rlp.encode(new_value)]) return send_obj_transaction(self, data, self.web3.pipAddress, pri_key, transaction_cfg) def submitCancel(self, verifier, pip_id, end_voting_rounds, tobe_canceled_proposal_id, pri_key, transaction_cfg=None): @@ -232,9 +230,16 @@ def getActiveVersion(self, from_address=None): data = rlp.encode([rlp.encode(int(2103))]) return parse_data(call_obj(self, from_address, self.web3.pipAddress, data)) - # def getProgramVersion(self, from_address=None): - # data = rlp.encode([rlp.encode(int(2104))]) - # return parse_data(call_obj(self, from_address, self.web3.pipAddress, data)) + def getGovernParamValue(self, module, name, from_address=None): + """ + Query the current block height governance parameter value + :param module: Parameter module + :param name: parameter name + :param from_address: + :return: + """ + data = rlp.encode([rlp.encode(int(2104)), rlp.encode(module), rlp.encode(name)]) + return parse_data(call_obj(self, from_address, self.web3.pipAddress, data)) def listParam(self, from_address=None): """ diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 0bc4ecf..3a77dff 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -351,7 +351,7 @@ def getRestrictingInfo(self, account, from_address=None): receive = json.loads(str(raw_data, encoding="ISO-8859-1")) raw_data_dict = receive["Data"] if raw_data_dict != "": - data = json.loads(data) + data = json.loads(raw_data_dict) data["balance"] = int(data["balance"], 16) data["Pledge"] = int(data["Pledge"], 16) data["debt"] = int(data["debt"], 16) diff --git a/setup.py b/setup.py index 46dc886..90005b3 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.7', + version='0.3.9', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 4c775bc56d202e7886717dc37b4e90d7f46276bb Mon Sep 17 00:00:00 2001 From: awake Date: Thu, 7 Nov 2019 11:37:29 +0800 Subject: [PATCH 09/22] update ppos return msg --- client_sdk_python/pip.py | 9 +++-- client_sdk_python/ppos.py | 72 +++++++++++++++++++++++++-------------- setup.py | 2 +- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/client_sdk_python/pip.py b/client_sdk_python/pip.py index 559088c..2c5fb55 100644 --- a/client_sdk_python/pip.py +++ b/client_sdk_python/pip.py @@ -241,12 +241,15 @@ def getGovernParamValue(self, module, name, from_address=None): data = rlp.encode([rlp.encode(int(2104)), rlp.encode(module), rlp.encode(name)]) return parse_data(call_obj(self, from_address, self.web3.pipAddress, data)) - def listParam(self, from_address=None): + def listGovernParam(self, module=None, from_address=None): """ - todo fill + Query governance parameter list + :param module :param from_address: Used to call the rpc call method :return: todo fill """ - data = rlp.encode([rlp.encode(int(2105))]) + if module is None: + module = "" + data = rlp.encode([rlp.encode(int(2106)), rlp.encode(module)]) return parse_data(call_obj(self, from_address, self.web3.pipAddress, data)) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 3a77dff..5caa154 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -166,8 +166,12 @@ def getVerifierList(self, from_address=None): data = rlp.encode([rlp.encode(int(1100))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = parse_str(raw_data) - for i in parse['Data']: - i["Shares"] = int(i["Shares"], 16) + raw_data = parse["Ret"] + try: + for i in raw_data: + i["Shares"] = int(i["Shares"], 16) + except: + pass return parse def getValidatorList(self, from_address=None): @@ -180,8 +184,12 @@ def getValidatorList(self, from_address=None): data = rlp.encode([rlp.encode(int(1101))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = parse_str(raw_data) - for i in parse['Data']: - i["Shares"] = int(i["Shares"], 16) + raw_data = parse["Ret"] + try: + for i in raw_data: + i["Shares"] = int(i["Shares"], 16) + except: + pass return parse def getCandidateList(self, from_address=None): @@ -194,12 +202,16 @@ def getCandidateList(self, from_address=None): data = rlp.encode([rlp.encode(int(1102))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = parse_str(raw_data) - for i in parse['Data']: - i["Shares"] = int(i["Shares"], 16) - i["Released"] = int(i["Released"], 16) - i["ReleasedHes"] = int(i["ReleasedHes"], 16) - i["RestrictingPlan"] = int(i["RestrictingPlan"], 16) - i["RestrictingPlanHes"] = int(i["RestrictingPlanHes"], 16) + raw_data = parse["Ret"] + try: + for i in raw_data: + i["Shares"] = int(i["Shares"], 16) + i["Released"] = int(i["Released"], 16) + i["ReleasedHes"] = int(i["ReleasedHes"], 16) + i["RestrictingPlan"] = int(i["RestrictingPlan"], 16) + i["RestrictingPlanHes"] = int(i["RestrictingPlanHes"], 16) + except: + pass return parse def getRelatedListByDelAddr(self, del_addr, from_address=None): @@ -230,17 +242,19 @@ def getDelegateInfo(self, staking_blocknum, del_address, node_id, from_address=N del_address = del_address[2:] data = rlp.encode([rlp.encode(int(1104)), rlp.encode(staking_blocknum), rlp.encode(bytes.fromhex(del_address)), rlp.encode(bytes.fromhex(node_id))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) - parse = json.loads(str(raw_data, encoding="utf8")) - raw_data_dict = parse["Data"] - if raw_data_dict != "": + receive = json.loads(str(raw_data, encoding="utf8")) + raw_data_dict = receive["Ret"] + try: data = json.loads(raw_data_dict) data["Released"] = int(data["Released"], 16) data["ReleasedHes"] = int(data["ReleasedHes"], 16) data["RestrictingPlan"] = int(data["RestrictingPlan"], 16) data["RestrictingPlanHes"] = int(data["RestrictingPlanHes"], 16) data["Reduction"] = int(data["Reduction"], 16) - parse["Data"] = data - return parse + receive["Ret"] = data + except: + pass + return receive def getCandidateInfo(self, node_id, from_address=None): """ @@ -253,14 +267,18 @@ def getCandidateInfo(self, node_id, from_address=None): data = rlp.encode([rlp.encode(int(1105)), rlp.encode(bytes.fromhex(node_id))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = str(raw_data, encoding="utf8").replace('\\', '').replace('"{', '{').replace('}"', '}') - raw_data_dict = json.loads(parse) - if raw_data_dict["Data"] != "": - raw_data_dict["Data"]["Shares"] = int(raw_data_dict["Data"]["Shares"], 16) - raw_data_dict["Data"]["Released"] = int(raw_data_dict["Data"]["Released"], 16) - raw_data_dict["Data"]["ReleasedHes"] = int(raw_data_dict["Data"]["ReleasedHes"], 16) - raw_data_dict["Data"]["RestrictingPlan"] = int(raw_data_dict["Data"]["RestrictingPlan"], 16) - raw_data_dict["Data"]["RestrictingPlanHes"] = int(raw_data_dict["Data"]["RestrictingPlanHes"], 16) - return raw_data_dict + receive = json.loads(parse) + raw_data_dict = receive["Ret"] + try: + raw_data_dict["Shares"] = int(raw_data_dict["Shares"], 16) + raw_data_dict["Released"] = int(raw_data_dict["Released"], 16) + raw_data_dict["ReleasedHes"] = int(raw_data_dict["ReleasedHes"], 16) + raw_data_dict["RestrictingPlan"] = int(raw_data_dict["RestrictingPlan"], 16) + raw_data_dict["RestrictingPlanHes"] = int(raw_data_dict["RestrictingPlanHes"], 16) + receive["Ret"] = raw_data_dict + except: + pass + return receive def reportDuplicateSign(self, typ, data, pri_key, transaction_cfg=None): """ @@ -349,8 +367,8 @@ def getRestrictingInfo(self, account, from_address=None): data = rlp.encode([rlp.encode(int(4100)), rlp.encode(bytes.fromhex(account))]) raw_data = call_obj(self, from_address, self.web3.restrictingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) - raw_data_dict = receive["Data"] - if raw_data_dict != "": + raw_data_dict = receive["Ret"] + try: data = json.loads(raw_data_dict) data["balance"] = int(data["balance"], 16) data["Pledge"] = int(data["Pledge"], 16) @@ -358,5 +376,7 @@ def getRestrictingInfo(self, account, from_address=None): if data["plans"]: for i in data["plans"]: i["amount"] = int(i["amount"], 16) - receive["Data"] = data + receive["Ret"] = data + except: + pass return receive diff --git a/setup.py b/setup.py index 90005b3..63da687 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.3.9', + version='0.4.3', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From f9734ca01a286894ba4c048dffa823d6d89764e7 Mon Sep 17 00:00:00 2001 From: awake Date: Fri, 8 Nov 2019 13:55:55 +0800 Subject: [PATCH 10/22] update ppos return msg --- client_sdk_python/ppos.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 5caa154..7b04e7c 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -170,8 +170,7 @@ def getVerifierList(self, from_address=None): try: for i in raw_data: i["Shares"] = int(i["Shares"], 16) - except: - pass + except:... return parse def getValidatorList(self, from_address=None): @@ -188,8 +187,7 @@ def getValidatorList(self, from_address=None): try: for i in raw_data: i["Shares"] = int(i["Shares"], 16) - except: - pass + except:... return parse def getCandidateList(self, from_address=None): @@ -210,8 +208,7 @@ def getCandidateList(self, from_address=None): i["ReleasedHes"] = int(i["ReleasedHes"], 16) i["RestrictingPlan"] = int(i["RestrictingPlan"], 16) i["RestrictingPlanHes"] = int(i["RestrictingPlanHes"], 16) - except: - pass + except:... return parse def getRelatedListByDelAddr(self, del_addr, from_address=None): @@ -252,8 +249,7 @@ def getDelegateInfo(self, staking_blocknum, del_address, node_id, from_address=N data["RestrictingPlanHes"] = int(data["RestrictingPlanHes"], 16) data["Reduction"] = int(data["Reduction"], 16) receive["Ret"] = data - except: - pass + except:... return receive def getCandidateInfo(self, node_id, from_address=None): @@ -276,8 +272,7 @@ def getCandidateInfo(self, node_id, from_address=None): raw_data_dict["RestrictingPlan"] = int(raw_data_dict["RestrictingPlan"], 16) raw_data_dict["RestrictingPlanHes"] = int(raw_data_dict["RestrictingPlanHes"], 16) receive["Ret"] = raw_data_dict - except: - pass + except:... return receive def reportDuplicateSign(self, typ, data, pri_key, transaction_cfg=None): @@ -377,6 +372,5 @@ def getRestrictingInfo(self, account, from_address=None): for i in data["plans"]: i["amount"] = int(i["amount"], 16) receive["Ret"] = data - except: - pass + except:... return receive From 34cb73ac0e88d86615b2511a81e3fbf6ad2ad645 Mon Sep 17 00:00:00 2001 From: awake Date: Fri, 8 Nov 2019 13:56:13 +0800 Subject: [PATCH 11/22] update chainid set --- client_sdk_python/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client_sdk_python/main.py b/client_sdk_python/main.py index fa30e0f..4a00c42 100644 --- a/client_sdk_python/main.py +++ b/client_sdk_python/main.py @@ -137,13 +137,14 @@ def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, c self.chain_id = chain_id - def setChainId(self, chain_id): - self.chain_id = chain_id - @property def chainId(self): return self.chain_id + @chainId.setter + def chainId(self, chain_id): + self.chain_id = chain_id + @property def middleware_stack(self): return self.manager.middleware_stack From a30d90f6b7d3776f667485661ea2020f9a3e8534 Mon Sep 17 00:00:00 2001 From: awake Date: Fri, 15 Nov 2019 09:37:42 +0800 Subject: [PATCH 12/22] update chainid set --- client_sdk_python/debug.py | 8 ++------ client_sdk_python/ppos.py | 38 ++++++++++++++++++-------------------- setup.py | 2 +- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/client_sdk_python/debug.py b/client_sdk_python/debug.py index ed6cf1e..bfc51b8 100644 --- a/client_sdk_python/debug.py +++ b/client_sdk_python/debug.py @@ -1,14 +1,10 @@ from client_sdk_python.module import ( Module, ) +import json class Debug(Module): def economicConfig(self): - return self.web3.manager.request_blocking("debug_economicConfig", []) + return json.loads(self.web3.manager.request_blocking("debug_economicConfig", [])) - def getBuildMsg(self): - return self.web3.manager.request_blocking("debug_getBuildMsg", []) - - def getReceiveMsg(self): - return self.web3.manager.request_blocking("debug_getReceiveMsg", []) \ No newline at end of file diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 7b04e7c..66bf551 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -166,8 +166,8 @@ def getVerifierList(self, from_address=None): data = rlp.encode([rlp.encode(int(1100))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = parse_str(raw_data) - raw_data = parse["Ret"] try: + raw_data = parse["Ret"] for i in raw_data: i["Shares"] = int(i["Shares"], 16) except:... @@ -183,8 +183,8 @@ def getValidatorList(self, from_address=None): data = rlp.encode([rlp.encode(int(1101))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = parse_str(raw_data) - raw_data = parse["Ret"] try: + raw_data = parse["Ret"] for i in raw_data: i["Shares"] = int(i["Shares"], 16) except:... @@ -200,8 +200,8 @@ def getCandidateList(self, from_address=None): data = rlp.encode([rlp.encode(int(1102))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = parse_str(raw_data) - raw_data = parse["Ret"] try: + raw_data = parse["Ret"] for i in raw_data: i["Shares"] = int(i["Shares"], 16) i["Released"] = int(i["Released"], 16) @@ -240,15 +240,14 @@ def getDelegateInfo(self, staking_blocknum, del_address, node_id, from_address=N data = rlp.encode([rlp.encode(int(1104)), rlp.encode(staking_blocknum), rlp.encode(bytes.fromhex(del_address)), rlp.encode(bytes.fromhex(node_id))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) receive = json.loads(str(raw_data, encoding="utf8")) - raw_data_dict = receive["Ret"] try: - data = json.loads(raw_data_dict) - data["Released"] = int(data["Released"], 16) - data["ReleasedHes"] = int(data["ReleasedHes"], 16) - data["RestrictingPlan"] = int(data["RestrictingPlan"], 16) - data["RestrictingPlanHes"] = int(data["RestrictingPlanHes"], 16) - data["Reduction"] = int(data["Reduction"], 16) - receive["Ret"] = data + raw_data_dict = receive["Ret"] + raw_data_dict["Released"] = int(raw_data_dict["Released"], 16) + raw_data_dict["ReleasedHes"] = int(raw_data_dict["ReleasedHes"], 16) + raw_data_dict["RestrictingPlan"] = int(raw_data_dict["RestrictingPlan"], 16) + raw_data_dict["RestrictingPlanHes"] = int(raw_data_dict["RestrictingPlanHes"], 16) + # raw_data_dict["Reduction"] = int(raw_data_dict["Reduction"], 16) + receive["Ret"] = raw_data_dict except:... return receive @@ -264,8 +263,8 @@ def getCandidateInfo(self, node_id, from_address=None): raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) parse = str(raw_data, encoding="utf8").replace('\\', '').replace('"{', '{').replace('}"', '}') receive = json.loads(parse) - raw_data_dict = receive["Ret"] try: + raw_data_dict = receive["Ret"] raw_data_dict["Shares"] = int(raw_data_dict["Shares"], 16) raw_data_dict["Released"] = int(raw_data_dict["Released"], 16) raw_data_dict["ReleasedHes"] = int(raw_data_dict["ReleasedHes"], 16) @@ -362,15 +361,14 @@ def getRestrictingInfo(self, account, from_address=None): data = rlp.encode([rlp.encode(int(4100)), rlp.encode(bytes.fromhex(account))]) raw_data = call_obj(self, from_address, self.web3.restrictingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) - raw_data_dict = receive["Ret"] try: - data = json.loads(raw_data_dict) - data["balance"] = int(data["balance"], 16) - data["Pledge"] = int(data["Pledge"], 16) - data["debt"] = int(data["debt"], 16) - if data["plans"]: - for i in data["plans"]: + raw_data_dict = receive["Ret"] + raw_data_dict["balance"] = int(raw_data_dict["balance"], 16) + raw_data_dict["Pledge"] = int(raw_data_dict["Pledge"], 16) + raw_data_dict["debt"] = int(raw_data_dict["debt"], 16) + if raw_data_dict["plans"]: + for i in raw_data_dict["plans"]: i["amount"] = int(i["amount"], 16) - receive["Ret"] = data + receive["Ret"] = raw_data_dict except:... return receive diff --git a/setup.py b/setup.py index 63da687..8aaeed7 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.4.3', + version='0.4.7', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 210af29464b5818343eb4380a1b140b3cac40746 Mon Sep 17 00:00:00 2001 From: awake Date: Thu, 5 Dec 2019 15:53:47 +0800 Subject: [PATCH 13/22] add api --- client_sdk_python/ppos.py | 18 ++++++++++++++++++ setup.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 66bf551..4a13deb 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -372,3 +372,21 @@ def getRestrictingInfo(self, account, from_address=None): receive["Ret"] = raw_data_dict except:... return receive + + def getPackageReward(self, from_address=None): + data = rlp.encode([rlp.encode(int(1200))]) + raw_data = call_obj(self, from_address, self.web3.restrictingAddress,data) + receive = json.loads(str(raw_data, encoding="ISO-8859-1")) + return receive + + def getStakingReward(self, from_address=None): + data = rlp.encode([rlp.encode(int(1201))]) + raw_data = call_obj(self, from_address, self.web3.restrictingAddress,data) + receive = json.loads(str(raw_data, encoding="ISO-8859-1")) + return receive + + def getAvgPackTime(self, from_address=None): + data = rlp.encode([rlp.encode(int(1202))]) + raw_data = call_obj(self, from_address, self.web3.restrictingAddress,data) + receive = json.loads(str(raw_data, encoding="ISO-8859-1")) + return receive \ No newline at end of file diff --git a/setup.py b/setup.py index 8aaeed7..659d86d 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.4.7', + version='0.4.8', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper Merriam', From 8a3c03edfc002b62216eecfd4fcc0b6aab06d533 Mon Sep 17 00:00:00 2001 From: awake Date: Fri, 6 Dec 2019 11:49:18 +0800 Subject: [PATCH 14/22] add api --- client_sdk_python/ppos.py | 10 +++++++--- setup.py | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 4a13deb..34319e9 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -375,18 +375,22 @@ def getRestrictingInfo(self, account, from_address=None): def getPackageReward(self, from_address=None): data = rlp.encode([rlp.encode(int(1200))]) - raw_data = call_obj(self, from_address, self.web3.restrictingAddress,data) + raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) + ret = receive["Ret"] + receive["Ret"] = int(str(ret), 16) return receive def getStakingReward(self, from_address=None): data = rlp.encode([rlp.encode(int(1201))]) - raw_data = call_obj(self, from_address, self.web3.restrictingAddress,data) + raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) + ret = receive["Ret"] + receive["Ret"] = int(str(ret), 16) return receive def getAvgPackTime(self, from_address=None): data = rlp.encode([rlp.encode(int(1202))]) - raw_data = call_obj(self, from_address, self.web3.restrictingAddress,data) + raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) return receive \ No newline at end of file diff --git a/setup.py b/setup.py index 659d86d..eb920db 100644 --- a/setup.py +++ b/setup.py @@ -60,11 +60,11 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.4.8', + version='0.5.0', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', - author='Piper Merriam', - author_email='pipermerriam@gmail.com', + author='Piper awake', + author_email='hietel366435@gmail.com', url='https://github.com/PlatONnetwork/client-sdk-python', include_package_data=True, install_requires=[ From e8c1dd2bb0fffefa62ac2e31180d52d9f4e3a8b4 Mon Sep 17 00:00:00 2001 From: awake Date: Wed, 8 Jan 2020 15:57:19 +0800 Subject: [PATCH 15/22] add api --- client_sdk_python/main.py | 1 + client_sdk_python/ppos.py | 37 ++++++++++++++++++++++--- client_sdk_python/utils/transactions.py | 4 ++- setup.py | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/client_sdk_python/main.py b/client_sdk_python/main.py index 4a00c42..78cb014 100644 --- a/client_sdk_python/main.py +++ b/client_sdk_python/main.py @@ -123,6 +123,7 @@ class Web3: stakingAddress = "0x1000000000000000000000000000000000000002" penaltyAddress = "0x1000000000000000000000000000000000000004" pipAddress = "0x1000000000000000000000000000000000000005" + delegateRewardAddress = "0x1000000000000000000000000000000000000006" def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, chain_id=101): self.manager = RequestManager(self, providers, middlewares) diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 34319e9..7084faa 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -5,6 +5,7 @@ from client_sdk_python.module import ( Module, ) +from eth_utils.hexadecimal import remove_0x_prefix from client_sdk_python.utils.encoding import parse_str from client_sdk_python.utils.transactions import send_obj_transaction, call_obj @@ -15,7 +16,7 @@ class Ppos(Module): need_analyze = True def createStaking(self, typ, benifit_address, node_id, external_id, node_name, website, details, amount, - program_version, program_version_sign, bls_pubkey, bls_proof, pri_key, transaction_cfg=None): + program_version, program_version_sign, bls_pubkey, bls_proof, pri_key, reward_per, transaction_cfg=None): """ Initiate Staking :param typ: Indicates whether the account free amount or the account's lock amount is used for staking, 0: free amount; 1: lock amount @@ -31,6 +32,7 @@ def createStaking(self, typ, benifit_address, node_id, external_id, node_name, w :param bls_pubkey: Bls public key :param bls_proof: Proof of bls, obtained by pulling the proof interface, admin_getSchnorrNIZKProve :param pri_key: Private key for transaction + :param reward_per: Proportion of the reward share obtained from the commission, using BasePoint 1BP = 0.01% :param transaction_cfg: Transaction basic configuration type: dict example:cfg = { @@ -47,12 +49,13 @@ def createStaking(self, typ, benifit_address, node_id, external_id, node_name, w program_version_sign = program_version_sign[2:] data = HexBytes(rlp.encode([rlp.encode(int(1000)), rlp.encode(typ), rlp.encode(bytes.fromhex(benifit_address)), rlp.encode(bytes.fromhex(node_id)), rlp.encode(external_id), rlp.encode(node_name), - rlp.encode(website), rlp.encode(details), rlp.encode(amount), rlp.encode(program_version), + rlp.encode(website), rlp.encode(details), + rlp.encode(amount), rlp.encode(reward_per), rlp.encode(program_version), rlp.encode(bytes.fromhex(program_version_sign)), rlp.encode(bytes.fromhex(bls_pubkey)), rlp.encode(bytes.fromhex(bls_proof))])).hex() return send_obj_transaction(self, data, self.web3.stakingAddress, pri_key, transaction_cfg) - def editCandidate(self, benifit_address, node_id, external_id, node_name, website, details, pri_key, transaction_cfg=None): + def editCandidate(self, benifit_address, node_id, external_id, node_name, website, details, pri_key, reward_per, transaction_cfg=None): """ Modify staking information :param benifit_address: Income account for accepting block rewards and staking rewards @@ -62,6 +65,7 @@ def editCandidate(self, benifit_address, node_id, external_id, node_name, websit :param website: The third-party home page of the node (with a length limit indicating the home page of the node) :param details: Description of the node (with a length limit indicating the description of the node) :param pri_key: Private key for transaction + :param reward_per: Proportion of the reward share obtained from the commission, using BasePoint 1BP = 0.01% :param transaction_cfg: Transaction basic configuration type: dict example:cfg = { @@ -75,6 +79,7 @@ def editCandidate(self, benifit_address, node_id, external_id, node_name, websit if benifit_address[:2] == '0x': benifit_address = benifit_address[2:] data = HexBytes(rlp.encode([rlp.encode(int(1001)), rlp.encode(bytes.fromhex(benifit_address)), rlp.encode(bytes.fromhex(node_id)), + rlp.encode(reward_per), rlp.encode(external_id), rlp.encode(node_name), rlp.encode(website), rlp.encode(details)])).hex() return send_obj_transaction(self, data, self.web3.stakingAddress, pri_key, transaction_cfg) @@ -246,6 +251,7 @@ def getDelegateInfo(self, staking_blocknum, del_address, node_id, from_address=N raw_data_dict["ReleasedHes"] = int(raw_data_dict["ReleasedHes"], 16) raw_data_dict["RestrictingPlan"] = int(raw_data_dict["RestrictingPlan"], 16) raw_data_dict["RestrictingPlanHes"] = int(raw_data_dict["RestrictingPlanHes"], 16) + raw_data_dict["CumulativeIncome"] = int(raw_data_dict["CumulativeIncome"], 16) # raw_data_dict["Reduction"] = int(raw_data_dict["Reduction"], 16) receive["Ret"] = raw_data_dict except:... @@ -270,6 +276,9 @@ def getCandidateInfo(self, node_id, from_address=None): raw_data_dict["ReleasedHes"] = int(raw_data_dict["ReleasedHes"], 16) raw_data_dict["RestrictingPlan"] = int(raw_data_dict["RestrictingPlan"], 16) raw_data_dict["RestrictingPlanHes"] = int(raw_data_dict["RestrictingPlanHes"], 16) + raw_data_dict["DelegateRewardTotal"] = int(raw_data_dict["DelegateRewardTotal"], 16) + raw_data_dict["DelegateTotal"] = int(raw_data_dict["DelegateTotal"], 16) + raw_data_dict["DelegateTotalHes"] = int(raw_data_dict["DelegateTotalHes"], 16) receive["Ret"] = raw_data_dict except:... return receive @@ -393,4 +402,24 @@ def getAvgPackTime(self, from_address=None): data = rlp.encode([rlp.encode(int(1202))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) - return receive \ No newline at end of file + return receive + + def getDelegateReward(self, from_address, node_ids=[]): + node_id_bytes = [bytes.fromhex(node_id) for node_id in node_ids] + data = [rlp.encode(int(5100)), rlp.encode(bytes.fromhex(remove_0x_prefix(from_address))), rlp.encode(node_id_bytes)] + data = rlp.encode(data) + raw_data = call_obj(self, from_address, self.web3.delegateRewardAddress, data) + receive = json.loads(str(raw_data, encoding="ISO-8859-1")) + try: + raw_data_dict = receive["Ret"] + result = [] + for d in raw_data_dict: + d["reward"] = int(d["reward"], 16) + result.append(d) + receive["Ret"] = result + except:... + return receive + + def withdrawDelegateReward(self, pri_key, transaction_cfg=None): + data = rlp.encode([rlp.encode(int(5000))]) + return send_obj_transaction(self, data, self.web3.delegateRewardAddress, pri_key, transaction_cfg) \ No newline at end of file diff --git a/client_sdk_python/utils/transactions.py b/client_sdk_python/utils/transactions.py index 5d743c3..b1d0da4 100644 --- a/client_sdk_python/utils/transactions.py +++ b/client_sdk_python/utils/transactions.py @@ -54,7 +54,9 @@ def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): from_address = obj.web3.toChecksumAddress(raw_from_address) transaction_dict["nonce"] = obj.web3.platon.getTransactionCount(from_address) if transaction_cfg.get("gas", None) is None: - transaction_data = {"to": to_address, "data": data} + raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() + from_address = obj.web3.toChecksumAddress(raw_from_address) + transaction_data = {"to": to_address, "data": data, "from": from_address} transaction_dict["gas"] = obj.web3.platon.estimateGas(transaction_data) else: transaction_dict["gas"] = transaction_cfg["gas"] diff --git a/setup.py b/setup.py index eb920db..66768a5 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.5.0', + version='0.6.0', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper awake', From 1bea7fbe6412b5dd345ef399a415aa3c24b72f4b Mon Sep 17 00:00:00 2001 From: awake Date: Wed, 15 Jan 2020 17:28:20 +0800 Subject: [PATCH 16/22] add ecrecover function --- client_sdk_python/eth.py | 30 ++++++++++++++++++++++++++++++ setup.py | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/client_sdk_python/eth.py b/client_sdk_python/eth.py index 12cc823..8dde4dd 100644 --- a/client_sdk_python/eth.py +++ b/client_sdk_python/eth.py @@ -1,4 +1,7 @@ import json +import sha3 +import rlp +from eth_utils.hexadecimal import remove_0x_prefix from eth_account import ( Account, ) @@ -51,6 +54,9 @@ wait_for_transaction_receipt, ) +from eth_account.internal.signing import ( + to_standard_signature_bytes, +) class Eth(Module): account = Account() @@ -417,6 +423,30 @@ def analyzeReceiptByHash(self, tx_hash): def analyzeReceipt(self, transaction_receipt): return self.web3.analyzeReceipt(transaction_receipt) + def ecrecover(self, block_identifier): + block = self.getBlock(block_identifier) + extra = block.proofOfAuthorityData[0:32] + sign = block.proofOfAuthorityData[32:] + raw_data = [bytes.fromhex(remove_0x_prefix(block.parentHash.hex())), + bytes.fromhex(remove_0x_prefix(block.miner)), + bytes.fromhex(remove_0x_prefix(block.stateRoot.hex())), + bytes.fromhex(remove_0x_prefix(block.transactionsRoot.hex())), + bytes.fromhex(remove_0x_prefix(block.receiptsRoot.hex())), + bytes.fromhex(remove_0x_prefix(block.logsBloom.hex())), + block.number, + block.gasLimit, + block.gasUsed, + block.timestamp, + extra, + bytes.fromhex(remove_0x_prefix(block.nonce)) + ] + message_hash = sha3.keccak_256(rlp.encode(raw_data)).digest() + hash_bytes = HexBytes(message_hash) + signature_bytes = HexBytes(sign) + signature_bytes_standard = to_standard_signature_bytes(signature_bytes) + signature_obj = self.account._keys.Signature(signature_bytes=signature_bytes_standard) + return remove_0x_prefix(signature_obj.recover_public_key_from_msg_hash(hash_bytes).to_hex()) + class PlatON(Eth): pass diff --git a/setup.py b/setup.py index 66768a5..ae6b946 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.6.0', + version='0.6.2', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper awake', @@ -78,7 +78,7 @@ "eth-hash[pycryptodome]>=0.2.0,<1.0.0", "requests>=2.16.0,<3.0.0", "websockets>=6.0.0,<7.0.0", - "pypiwin32>=223;platform_system=='Windows'", 'rlp' + "pypiwin32>=223;platform_system=='Windows'", 'rlp', 'pysha3' ], setup_requires=['setuptools-markdown'], python_requires='>=3.6,<4', From 78c6d84855caea1343850a883fbd5404884783f6 Mon Sep 17 00:00:00 2001 From: awake006 Date: Mon, 23 Mar 2020 14:28:39 +0800 Subject: [PATCH 17/22] fix consensusStatus bug --- client_sdk_python/eth.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client_sdk_python/eth.py b/client_sdk_python/eth.py index 8dde4dd..9ed03cf 100644 --- a/client_sdk_python/eth.py +++ b/client_sdk_python/eth.py @@ -115,8 +115,7 @@ def evidences(self): @property def consensusStatus(self): - data = self.web3.manager.request_blocking("platon_consensusStatus", []) - return json.loads(data) + return self.web3.manager.request_blocking("platon_consensusStatus", []) def getPrepareQC(self, block_number): return self.web3.manager.request_blocking("platon_getPrepareQC", [block_number]) From 34393e417f74a65f04b643b26d8f9d2ccb0c886e Mon Sep 17 00:00:00 2001 From: awake006 Date: Fri, 17 Apr 2020 18:17:51 +0800 Subject: [PATCH 18/22] add debug func --- client_sdk_python/debug.py | 19 +++++++++++++++++++ client_sdk_python/utils/transactions.py | 2 ++ setup.py | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/client_sdk_python/debug.py b/client_sdk_python/debug.py index bfc51b8..33ccc1c 100644 --- a/client_sdk_python/debug.py +++ b/client_sdk_python/debug.py @@ -2,9 +2,28 @@ Module, ) import json +import rlp +from hexbytes import HexBytes +from client_sdk_python.utils.transactions import send_obj_transaction class Debug(Module): + + need_analyze = True + def economicConfig(self): return json.loads(self.web3.manager.request_blocking("debug_economicConfig", [])) + def setValidatorList(self, node_list, pri_key, transaction_cfg={"gas": 210000}): + data_list = [] + for node_id in node_list: + data_list.append(bytes.fromhex(node_id)) + data = HexBytes(rlp.encode([rlp.encode(int(1900)), rlp.encode(data_list)])).hex() + return send_obj_transaction(self, data, self.web3.stakingAddress, pri_key, transaction_cfg) + + def getWaitSlashingNodeList(self): + result = self.web3.manager.request_blocking("debug_getWaitSlashingNodeList", []) + if not result: + return [] + return json.loads(result) + diff --git a/client_sdk_python/utils/transactions.py b/client_sdk_python/utils/transactions.py index b1d0da4..0931334 100644 --- a/client_sdk_python/utils/transactions.py +++ b/client_sdk_python/utils/transactions.py @@ -53,6 +53,8 @@ def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() from_address = obj.web3.toChecksumAddress(raw_from_address) transaction_dict["nonce"] = obj.web3.platon.getTransactionCount(from_address) + else: + transaction_dict["nonce"] = transaction_cfg["nonce"] if transaction_cfg.get("gas", None) is None: raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() from_address = obj.web3.toChecksumAddress(raw_from_address) diff --git a/setup.py b/setup.py index ae6b946..32709f8 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.6.2', + version='0.6.6', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper awake', From 94754b1b691ed47e48d4610af1649a57156902b5 Mon Sep 17 00:00:00 2001 From: awake006 Date: Mon, 27 Apr 2020 15:06:27 +0800 Subject: [PATCH 19/22] add debug func --- client_sdk_python/__init__.py | 2 +- client_sdk_python/eth.py | 4 +-- client_sdk_python/main.py | 36 +++++++++++++++++++------ client_sdk_python/middleware/signing.py | 12 ++++----- client_sdk_python/utils/transactions.py | 14 +++++----- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/client_sdk_python/__init__.py b/client_sdk_python/__init__.py index 6cc61c4..9869999 100644 --- a/client_sdk_python/__init__.py +++ b/client_sdk_python/__init__.py @@ -4,7 +4,7 @@ if sys.version_info < (3, 5): raise EnvironmentError("Python 3.5 or above is required") -from eth_account import Account # noqa: E402 +from platon_account import Account # noqa: E402 from client_sdk_python.main import Web3 # noqa: E402 from client_sdk_python.providers.rpc import ( # noqa: E402 HTTPProvider, diff --git a/client_sdk_python/eth.py b/client_sdk_python/eth.py index 9ed03cf..29e9160 100644 --- a/client_sdk_python/eth.py +++ b/client_sdk_python/eth.py @@ -2,7 +2,7 @@ import sha3 import rlp from eth_utils.hexadecimal import remove_0x_prefix -from eth_account import ( +from platon_account import ( Account, ) from eth_utils import ( @@ -54,7 +54,7 @@ wait_for_transaction_receipt, ) -from eth_account.internal.signing import ( +from platon_account.internal.signing import ( to_standard_signature_bytes, ) diff --git a/client_sdk_python/main.py b/client_sdk_python/main.py index 78cb014..0a12590 100644 --- a/client_sdk_python/main.py +++ b/client_sdk_python/main.py @@ -87,6 +87,17 @@ def get_default_modules(): } +def default_address(mainnet, testnet): + return {"MAINNET": mainnet, "TESTNET": testnet} + + +restricting = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp7pn3ep","lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp3yp7hw") +staking = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzsjx8h7", "lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzlh5ge3") +penalty = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyva9ztf", "lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyrchd9x") +pipAddr = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq93t3hkm", "lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq97wrcc5") +delegateReward = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxlcypcy", "lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxsakwkt") + + class Web3: # Providers HTTPProvider = HTTPProvider @@ -118,14 +129,7 @@ class Web3: isChecksumAddress = staticmethod(is_checksum_address) toChecksumAddress = staticmethod(to_checksum_address) - # platon contract address - restrictingAddress = "0x1000000000000000000000000000000000000001" - stakingAddress = "0x1000000000000000000000000000000000000002" - penaltyAddress = "0x1000000000000000000000000000000000000004" - pipAddress = "0x1000000000000000000000000000000000000005" - delegateRewardAddress = "0x1000000000000000000000000000000000000006" - - def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, chain_id=101): + def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, chain_id=100): self.manager = RequestManager(self, providers, middlewares) if modules is None: @@ -134,6 +138,17 @@ def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, c for module_name, module_class in modules.items(): module_class.attach(self, module_name) + if chain_id == 100: + self.net = "mainnet" + else: + self.net = "testnet" + # platon contract address + self.restrictingAddress = restricting[self.net.upper()] + self.stakingAddress = staking[self.net.upper()] + self.penaltyAddress = penalty[self.net.upper()] + self.pipAddress = pipAddr[self.net.upper()] + self.delegateRewardAddress = delegateReward[self.net.upper()] + self.ens = ens self.chain_id = chain_id @@ -217,3 +232,8 @@ def ens(self): @ens.setter def ens(self, new_ens): self._ens = new_ens + + def pubkey_to_address(self, pubkey): + addr_dict = {"MAINNET": pubkey.to_bech32_address(), + "TESTNET": pubkey.to_bech32_test_address()} + return addr_dict[self.net.upper()] diff --git a/client_sdk_python/middleware/signing.py b/client_sdk_python/middleware/signing.py index 86d6c5e..48e9ef8 100644 --- a/client_sdk_python/middleware/signing.py +++ b/client_sdk_python/middleware/signing.py @@ -3,13 +3,13 @@ ) import operator -from eth_account import ( +from platon_account import ( Account, ) -from eth_account.local import ( +from platon_account.local import ( LocalAccount, ) -from eth_keys.datatypes import ( +from platon_keys.datatypes import ( PrivateKey, ) from eth_utils import ( @@ -63,7 +63,7 @@ def gen_normalized_accounts(val): def to_account(val): raise TypeError( "key must be one of the types: " - "eth_keys.datatype.PrivateKey, eth_account.local.LocalAccount, " + "platon_keys.datatype.PrivateKey, platon_account.local.LocalAccount, " "or raw private key as a hex string or byte string. " "Was of type {0}".format(type(val))) @@ -99,8 +99,8 @@ def construct_sign_and_send_raw_middleware(private_key_or_account): Keyword arguments: private_key_or_account -- A single private key or a tuple, list or set of private keys. Keys can be any of the following formats: - - An eth_account.LocalAccount object - - An eth_keys.PrivateKey object + - An platon_account.LocalAccount object + - An platon_keys.PrivateKey object - A raw private key as a hex string or byte string """ diff --git a/client_sdk_python/utils/transactions.py b/client_sdk_python/utils/transactions.py index 0931334..89652fb 100644 --- a/client_sdk_python/utils/transactions.py +++ b/client_sdk_python/utils/transactions.py @@ -11,7 +11,7 @@ from hexbytes import HexBytes -from eth_keys.datatypes import PrivateKey +from platon_keys.datatypes import PrivateKey VALID_TRANSACTION_PARAMS = [ 'from', @@ -34,10 +34,10 @@ def call_obj(obj, from_address, to_address, data): - to_address = obj.web3.toChecksumAddress(to_address) + # to_address = obj.web3.toChecksumAddress(to_address) if from_address is None: return obj.web3.platon.call({"to": to_address, "data": data}) - from_address = obj.web3.toChecksumAddress(from_address) + # from_address = obj.web3.toChecksumAddress(from_address) return obj.web3.platon.call({"from": from_address, "to": to_address, "data": data}) @@ -50,14 +50,12 @@ def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): else: transaction_dict["gasPrice"] = transaction_cfg["gasPrice"] if transaction_cfg.get("nonce", None) is None: - raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() - from_address = obj.web3.toChecksumAddress(raw_from_address) + from_address = obj.web3.pubkey_to_address(PrivateKey(bytes.fromhex(pri_key)).public_key) transaction_dict["nonce"] = obj.web3.platon.getTransactionCount(from_address) else: transaction_dict["nonce"] = transaction_cfg["nonce"] if transaction_cfg.get("gas", None) is None: - raw_from_address = PrivateKey(bytes.fromhex(pri_key)).public_key.to_address() - from_address = obj.web3.toChecksumAddress(raw_from_address) + from_address = obj.web3.pubkey_to_address(PrivateKey(bytes.fromhex(pri_key)).public_key) transaction_data = {"to": to_address, "data": data, "from": from_address} transaction_dict["gas"] = obj.web3.platon.estimateGas(transaction_data) else: @@ -181,7 +179,7 @@ def assert_valid_transaction_params(transaction_params): def prepare_replacement_transaction(web3, current_transaction, new_transaction): - if current_transaction['blockHash'] != HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000'): + if current_transaction['blockHash'] != HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000'): raise ValueError('Supplied transaction with hash {} has already been mined' .format(current_transaction['hash'])) From df19dc127a1103cf7d7984d22b2c7d22a6a305db Mon Sep 17 00:00:00 2001 From: awake006 Date: Wed, 6 May 2020 15:32:52 +0800 Subject: [PATCH 20/22] fix request bug --- client_sdk_python/main.py | 26 +++++++----- client_sdk_python/middleware/names.py | 2 +- client_sdk_python/middleware/pythonic.py | 6 ++- client_sdk_python/utils/validation.py | 51 ++++++++++++------------ 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/client_sdk_python/main.py b/client_sdk_python/main.py index 0a12590..0fff077 100644 --- a/client_sdk_python/main.py +++ b/client_sdk_python/main.py @@ -3,10 +3,10 @@ add_0x_prefix, from_wei, is_address, - is_checksum_address, + # is_checksum_address, keccak, remove_0x_prefix, - to_checksum_address, + # to_checksum_address, to_wei, ) @@ -98,6 +98,12 @@ def default_address(mainnet, testnet): delegateReward = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxlcypcy", "lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxsakwkt") +def to_checksum_address(val): + return val + +def is_checksum_address(val): + return True + class Web3: # Providers HTTPProvider = HTTPProvider @@ -139,15 +145,15 @@ def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, c module_class.attach(self, module_name) if chain_id == 100: - self.net = "mainnet" + self.net_type = "mainnet" else: - self.net = "testnet" + self.net_type = "testnet" # platon contract address - self.restrictingAddress = restricting[self.net.upper()] - self.stakingAddress = staking[self.net.upper()] - self.penaltyAddress = penalty[self.net.upper()] - self.pipAddress = pipAddr[self.net.upper()] - self.delegateRewardAddress = delegateReward[self.net.upper()] + self.restrictingAddress = restricting[self.net_type.upper()] + self.stakingAddress = staking[self.net_type.upper()] + self.penaltyAddress = penalty[self.net_type.upper()] + self.pipAddress = pipAddr[self.net_type.upper()] + self.delegateRewardAddress = delegateReward[self.net_type.upper()] self.ens = ens @@ -236,4 +242,4 @@ def ens(self, new_ens): def pubkey_to_address(self, pubkey): addr_dict = {"MAINNET": pubkey.to_bech32_address(), "TESTNET": pubkey.to_bech32_test_address()} - return addr_dict[self.net.upper()] + return addr_dict[self.net_type.upper()] diff --git a/client_sdk_python/middleware/names.py b/client_sdk_python/middleware/names.py index be88f94..52f5ebb 100644 --- a/client_sdk_python/middleware/names.py +++ b/client_sdk_python/middleware/names.py @@ -16,5 +16,5 @@ def name_to_address_middleware(w3): abi_ens_resolver(w3), ] return construct_formatting_middleware( - request_formatters=abi_request_formatters(normalizers, RPC_ABIS) + # request_formatters=abi_request_formatters(normalizers, RPC_ABIS) ) diff --git a/client_sdk_python/middleware/pythonic.py b/client_sdk_python/middleware/pythonic.py index 492c9f0..dba5348 100644 --- a/client_sdk_python/middleware/pythonic.py +++ b/client_sdk_python/middleware/pythonic.py @@ -10,7 +10,7 @@ is_string, remove_0x_prefix, text_if_str, - to_checksum_address, + # to_checksum_address, ) from hexbytes import ( HexBytes, @@ -63,6 +63,10 @@ def bytes_to_ascii(value): is_not_null = complement(is_null) +def to_checksum_address(val): + return val + + @curry def to_hexbytes(num_bytes, val, variable_length=False): if isinstance(val, (str, int, bytes)): diff --git a/client_sdk_python/utils/validation.py b/client_sdk_python/utils/validation.py index bc3f224..6c2a39b 100644 --- a/client_sdk_python/utils/validation.py +++ b/client_sdk_python/utils/validation.py @@ -143,31 +143,32 @@ def validate_address(value): """ Helper function for validating an address """ - if is_bytes(value): - if not is_binary_address(value): - raise InvalidAddress("Address must be 20 bytes when input type is bytes", value) - return - - if not isinstance(value, str): - raise TypeError('Address {} must be provided as a string'.format(value)) - if not is_hex_address(value): - raise InvalidAddress("Address must be 20 bytes, as a hex string with a 0x prefix", value) - if not is_checksum_address(value): - if value == value.lower(): - raise InvalidAddress( - "Web3.py only accepts checksum addresses. " - "The software that gave you this non-checksum address should be considered unsafe, " - "please file it as a bug on their platform. " - "Try using an ENS name instead. Or, if you must accept lower safety, " - "use Web3.toChecksumAddress(lower_case_address).", - value, - ) - else: - raise InvalidAddress( - "Address has an invalid EIP-55 checksum. " - "After looking up the address from the original source, try again.", - value, - ) + # if is_bytes(value): + # if not is_binary_address(value): + # raise InvalidAddress("Address must be 20 bytes when input type is bytes", value) + # return + # + # if not isinstance(value, str): + # raise TypeError('Address {} must be provided as a string'.format(value)) + # if not is_hex_address(value): + # raise InvalidAddress("Address must be 20 bytes, as a hex string with a 0x prefix", value) + # if not is_checksum_address(value): + # if value == value.lower(): + # raise InvalidAddress( + # "Web3.py only accepts checksum addresses. " + # "The software that gave you this non-checksum address should be considered unsafe, " + # "please file it as a bug on their platform. " + # "Try using an ENS name instead. Or, if you must accept lower safety, " + # "use Web3.toChecksumAddress(lower_case_address).", + # value, + # ) + # else: + # raise InvalidAddress( + # "Address has an invalid EIP-55 checksum. " + # "After looking up the address from the original source, try again.", + # value, + # ) + pass def has_one_val(*args, **kwargs): From 7f028d898ba85eeb6d61498a0b3c7c4442a4675f Mon Sep 17 00:00:00 2001 From: awake006 Date: Mon, 11 May 2020 17:16:30 +0800 Subject: [PATCH 21/22] fix net type error --- client_sdk_python/eth.py | 4 ++- client_sdk_python/main.py | 23 +++++++------ client_sdk_python/ppos.py | 46 ++++++++++++------------- client_sdk_python/utils/transactions.py | 2 +- setup.py | 4 +-- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/client_sdk_python/eth.py b/client_sdk_python/eth.py index 29e9160..f48735e 100644 --- a/client_sdk_python/eth.py +++ b/client_sdk_python/eth.py @@ -5,6 +5,7 @@ from platon_account import ( Account, ) +from platon_account.internal.transactions import bech32_address_bytes from eth_utils import ( apply_to_return_value, is_checksum_address, @@ -426,8 +427,9 @@ def ecrecover(self, block_identifier): block = self.getBlock(block_identifier) extra = block.proofOfAuthorityData[0:32] sign = block.proofOfAuthorityData[32:] + miner = bech32_address_bytes(remove_0x_prefix(block.miner)) raw_data = [bytes.fromhex(remove_0x_prefix(block.parentHash.hex())), - bytes.fromhex(remove_0x_prefix(block.miner)), + miner, bytes.fromhex(remove_0x_prefix(block.stateRoot.hex())), bytes.fromhex(remove_0x_prefix(block.transactionsRoot.hex())), bytes.fromhex(remove_0x_prefix(block.receiptsRoot.hex())), diff --git a/client_sdk_python/main.py b/client_sdk_python/main.py index 0fff077..8eadcb5 100644 --- a/client_sdk_python/main.py +++ b/client_sdk_python/main.py @@ -9,6 +9,7 @@ # to_checksum_address, to_wei, ) +from platon_keys.utils.address import MIANNETHRP, TESTNETHRP from ens import ENS @@ -88,7 +89,7 @@ def get_default_modules(): def default_address(mainnet, testnet): - return {"MAINNET": mainnet, "TESTNET": testnet} + return {MIANNETHRP: mainnet, TESTNETHRP: testnet} restricting = default_address("lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp7pn3ep","lax1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp3yp7hw") @@ -145,15 +146,15 @@ def __init__(self, providers=empty, middlewares=None, modules=None, ens=empty, c module_class.attach(self, module_name) if chain_id == 100: - self.net_type = "mainnet" + self.net_type = MIANNETHRP else: - self.net_type = "testnet" + self.net_type = TESTNETHRP # platon contract address - self.restrictingAddress = restricting[self.net_type.upper()] - self.stakingAddress = staking[self.net_type.upper()] - self.penaltyAddress = penalty[self.net_type.upper()] - self.pipAddress = pipAddr[self.net_type.upper()] - self.delegateRewardAddress = delegateReward[self.net_type.upper()] + self.restrictingAddress = restricting[self.net_type] + self.stakingAddress = staking[self.net_type] + self.penaltyAddress = penalty[self.net_type] + self.pipAddress = pipAddr[self.net_type] + self.delegateRewardAddress = delegateReward[self.net_type] self.ens = ens @@ -240,6 +241,6 @@ def ens(self, new_ens): self._ens = new_ens def pubkey_to_address(self, pubkey): - addr_dict = {"MAINNET": pubkey.to_bech32_address(), - "TESTNET": pubkey.to_bech32_test_address()} - return addr_dict[self.net_type.upper()] + addr_dict = {MIANNETHRP: pubkey.to_bech32_address(), + TESTNETHRP: pubkey.to_bech32_test_address()} + return addr_dict[self.net_type] diff --git a/client_sdk_python/ppos.py b/client_sdk_python/ppos.py index 7084faa..bd05497 100644 --- a/client_sdk_python/ppos.py +++ b/client_sdk_python/ppos.py @@ -8,6 +8,7 @@ from eth_utils.hexadecimal import remove_0x_prefix from client_sdk_python.utils.encoding import parse_str from client_sdk_python.utils.transactions import send_obj_transaction, call_obj +from platon_account.internal.transactions import bech32_address_bytes class Ppos(Module): @@ -43,11 +44,10 @@ def createStaking(self, typ, benifit_address, node_id, external_id, node_name, w :return: if is need analyze return transaction result dict if is not need analyze return transaction hash """ - if benifit_address[:2] == '0x': - benifit_address = benifit_address[2:] + benifit_address = bech32_address_bytes(benifit_address) if program_version_sign[:2] == '0x': program_version_sign = program_version_sign[2:] - data = HexBytes(rlp.encode([rlp.encode(int(1000)), rlp.encode(typ), rlp.encode(bytes.fromhex(benifit_address)), + data = HexBytes(rlp.encode([rlp.encode(int(1000)), rlp.encode(typ), rlp.encode(benifit_address), rlp.encode(bytes.fromhex(node_id)), rlp.encode(external_id), rlp.encode(node_name), rlp.encode(website), rlp.encode(details), rlp.encode(amount), rlp.encode(reward_per), rlp.encode(program_version), @@ -76,9 +76,10 @@ def editCandidate(self, benifit_address, node_id, external_id, node_name, websit :return: if is need analyze return transaction result dict if is not need analyze return transaction hash """ - if benifit_address[:2] == '0x': - benifit_address = benifit_address[2:] - data = HexBytes(rlp.encode([rlp.encode(int(1001)), rlp.encode(bytes.fromhex(benifit_address)), rlp.encode(bytes.fromhex(node_id)), + # if benifit_address[:2] == '0x': + # benifit_address = benifit_address[2:] + benifit_address = bech32_address_bytes(benifit_address) + data = HexBytes(rlp.encode([rlp.encode(int(1001)), rlp.encode(benifit_address), rlp.encode(bytes.fromhex(node_id)), rlp.encode(reward_per), rlp.encode(external_id), rlp.encode(node_name), rlp.encode(website), rlp.encode(details)])).hex() return send_obj_transaction(self, data, self.web3.stakingAddress, pri_key, transaction_cfg) @@ -224,9 +225,8 @@ def getRelatedListByDelAddr(self, del_addr, from_address=None): :return: todo fill """ - if del_addr[:2] == '0x': - del_addr = del_addr[2:] - data = rlp.encode([rlp.encode(int(1103)), rlp.encode(bytes.fromhex(del_addr))]) + del_addr = bech32_address_bytes(del_addr) + data = rlp.encode([rlp.encode(int(1103)), rlp.encode(del_addr)]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) return parse_str(raw_data) @@ -240,9 +240,8 @@ def getDelegateInfo(self, staking_blocknum, del_address, node_id, from_address=N :return: todo fill """ - if del_address[:2] == '0x': - del_address = del_address[2:] - data = rlp.encode([rlp.encode(int(1104)), rlp.encode(staking_blocknum), rlp.encode(bytes.fromhex(del_address)), rlp.encode(bytes.fromhex(node_id))]) + del_address = bech32_address_bytes(del_address) + data = rlp.encode([rlp.encode(int(1104)), rlp.encode(staking_blocknum), rlp.encode(del_address), rlp.encode(bytes.fromhex(node_id))]) raw_data = call_obj(self, from_address, self.web3.stakingAddress, data) receive = json.loads(str(raw_data, encoding="utf8")) try: @@ -302,7 +301,7 @@ def reportDuplicateSign(self, typ, data, pri_key, transaction_cfg=None): data = rlp.encode([rlp.encode(int(3000)), rlp.encode(typ), rlp.encode(data)]) return send_obj_transaction(self, data, self.web3.penaltyAddress, pri_key, transaction_cfg) - def checkDuplicateSign(self, typ, check_address, block_number, from_address=None): + def checkDuplicateSign(self, typ, node_id, block_number, from_address=None): """ Check if the node has been reported too much :param typ: Represents double sign type, 1:prepareBlock, 2: prepareVote, 3:viewChange @@ -312,9 +311,7 @@ def checkDuplicateSign(self, typ, check_address, block_number, from_address=None :return: todo fill """ - if check_address[:2] == '0x': - check_address = check_address[2:] - data = rlp.encode([rlp.encode(int(3001)), rlp.encode(int(typ)), rlp.encode(bytes.fromhex(check_address)), rlp.encode(block_number)]) + data = rlp.encode([rlp.encode(int(3001)), rlp.encode(int(typ)), rlp.encode(bytes.fromhex(node_id)), rlp.encode(block_number)]) raw_data = call_obj(self, from_address, self.web3.penaltyAddress, data) receive = str(raw_data, encoding="ISO-8859-1") if receive == "": @@ -347,14 +344,15 @@ def createRestrictingPlan(self, account, plan, pri_key, transaction_cfg=None): :return: if is need analyze return transaction result dict if is not need analyze return transaction hash """ - if account[:2] == '0x': - account = account[2:] + # if account[:2] == '0x': + # account = account[2:] + account = bech32_address_bytes(account) plan_list = [] for dict_ in plan: v = [dict_[k] for k in dict_] plan_list.append(v) rlp_list = rlp.encode(plan_list) - data = rlp.encode([rlp.encode(int(4000)), rlp.encode(bytes.fromhex(account)), rlp_list]) + data = rlp.encode([rlp.encode(int(4000)), rlp.encode(account), rlp_list]) return send_obj_transaction(self, data, self.web3.restrictingAddress, pri_key, transaction_cfg) def getRestrictingInfo(self, account, from_address=None): @@ -365,9 +363,10 @@ def getRestrictingInfo(self, account, from_address=None): :return: todo fill """ - if account[:2] == '0x': - account = account[2:] - data = rlp.encode([rlp.encode(int(4100)), rlp.encode(bytes.fromhex(account))]) + # if account[:2] == '0x': + # account = account[2:] + account = bech32_address_bytes(account) + data = rlp.encode([rlp.encode(int(4100)), rlp.encode(account)]) raw_data = call_obj(self, from_address, self.web3.restrictingAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) try: @@ -406,7 +405,8 @@ def getAvgPackTime(self, from_address=None): def getDelegateReward(self, from_address, node_ids=[]): node_id_bytes = [bytes.fromhex(node_id) for node_id in node_ids] - data = [rlp.encode(int(5100)), rlp.encode(bytes.fromhex(remove_0x_prefix(from_address))), rlp.encode(node_id_bytes)] + tmp_from_address = bech32_address_bytes(from_address) + data = [rlp.encode(int(5100)), rlp.encode(tmp_from_address), rlp.encode(node_id_bytes)] data = rlp.encode(data) raw_data = call_obj(self, from_address, self.web3.delegateRewardAddress, data) receive = json.loads(str(raw_data, encoding="ISO-8859-1")) diff --git a/client_sdk_python/utils/transactions.py b/client_sdk_python/utils/transactions.py index 89652fb..9a9506d 100644 --- a/client_sdk_python/utils/transactions.py +++ b/client_sdk_python/utils/transactions.py @@ -66,7 +66,7 @@ def send_obj_transaction(obj, data, to_address, pri_key, transaction_cfg: dict): if transaction_cfg.get("value", 0) > 0: transaction_dict["value"] = int(transaction_cfg.get("value", 0)) signed_transaction_dict = obj.web3.platon.account.signTransaction( - transaction_dict, pri_key + transaction_dict, pri_key, net_type=obj.web3.net_type ) signed_data = signed_transaction_dict.rawTransaction tx_hash = HexBytes(obj.web3.platon.sendRawTransaction(signed_data)).hex() diff --git a/setup.py b/setup.py index 32709f8..7c9c981 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.6.6', + version='0.6.9', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper awake', @@ -71,7 +71,7 @@ "toolz>=0.9.0,<1.0.0;implementation_name=='pypy'", "cytoolz>=0.9.0,<1.0.0;implementation_name=='cpython'", "eth-abi>=1.2.0,<2.0.0", - "eth-account>=0.2.1,<0.4.0", + "platon-account>=0.1.1", "eth-utils>=1.2.0,<2.0.0", "hexbytes>=0.1.0,<1.0.0", "lru-dict>=1.1.6,<2.0.0", From 664a0213f2a534e2da1a327c2a258b967c92ec9b Mon Sep 17 00:00:00 2001 From: awake006 Date: Sat, 20 Jun 2020 13:47:36 +0800 Subject: [PATCH 22/22] fix net type error --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 7c9c981..9dbf9da 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( name='client_sdk_python', # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='0.6.9', + version='0.7.0', description="""PlatON Client SDK python""", # long_description_markdown_filename='README.md', author='Piper awake', @@ -71,7 +71,7 @@ "toolz>=0.9.0,<1.0.0;implementation_name=='pypy'", "cytoolz>=0.9.0,<1.0.0;implementation_name=='cpython'", "eth-abi>=1.2.0,<2.0.0", - "platon-account>=0.1.1", + "platon-account>=0.1.2", "eth-utils>=1.2.0,<2.0.0", "hexbytes>=0.1.0,<1.0.0", "lru-dict>=1.1.6,<2.0.0",