Skip to content

Commit

Permalink
add error msg parse
Browse files Browse the repository at this point in the history
  • Loading branch information
coderkentzhang committed Mar 22, 2024
1 parent 2721d2b commit d30177c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions client/datatype_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,7 @@ def format_abi_args(self, fn_name :str, fn_args):
inputabi = abidata["inputs"]
args = format_args_by_function_abi(fn_args, inputabi)
return (contract_abi, args)

def parse_error_msg(output):

This comment has been minimized.

Copy link
@ezhkovskii

ezhkovskii Mar 29, 2024

output is an instance of a class DatatypeParser.
You need to add the self parameter or the staticmethod decorator

outputbody = output[10:] #去掉0x[func_sig]共10个字符
return decode_single("(string)", decode_hex(outputbody))
13 changes: 9 additions & 4 deletions console_utils/cmd_bcos3_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,16 @@ def sendtx(self, inputparams):
print(f"Transaction result >> \n{result}")
status =result['status']
print(f"Transaction Status >> {status}")
output = result['output']
if not TransactionStatus.isOK(status):
#不成功的打印错误
print("! transaction ERROR",TransactionStatus.get_error_message(status))
output = result['output']
output = abiparser.parse_output(fn_name, output)
print(f"Transaction Output >> {output}")
errmsg = DatatypeParser.parse_error_msg(output)
print("! Error Message: ",errmsg)
else:
#成功的打印output
output = abiparser.parse_output(fn_name, output)
print(f"Transaction Output >> {output}")
if "logEntries" in result:
logs = abiparser.parse_event_logs(result["logEntries"])
print("transaction receipt events >>")
Expand Down Expand Up @@ -245,4 +250,4 @@ def abi(self,inputparams):
sig = abi_to_signature(event)
print(f"{n} ) : {sig}")
if detail == 1:
print(f"abi:{event}")
print(f"abi:{event}")
6 changes: 6 additions & 0 deletions tests/testcodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ def testarray():
"73202c63616e27742063726561746520616761696e00"
result = decode_single("(int256,string,uint256,address,string)", decode_hex(data))
print(result)

errorMsg = "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000e6e616d65206e6f74206d61746368000000000000000000000000000000000000"
errorMsg = errorMsg[10:]
print(errorMsg)
result = decode_single("(string)",decode_hex(errorMsg))
print("error result" ,result)
2 changes: 1 addition & 1 deletion utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def make_post_request(endpoint_uri, method, params, data, *args, **kwargs):
session = _get_session(endpoint_uri, method, params, kwargs)
response = session.post(endpoint_uri, data=data, *args, **kwargs)
response.raise_for_status()
#Ôö¼ÓһЩ¼æÈÝÐÔÂß¼­
#增加一些兼容性逻辑
if hasattr(response,"cb_context"):
return response.cb_context
if hasattr(response, "context"):
Expand Down

0 comments on commit d30177c

Please sign in to comment.