From 70e4a2a2d1a5e3cb3d762a9977346833e7e628f6 Mon Sep 17 00:00:00 2001 From: Joe Stewart Date: Thu, 7 Nov 2019 10:21:17 -0500 Subject: [PATCH 1/2] hide contract script in search output --- neo/Core/FunctionCode.py | 13 +++++++++---- neo/Core/State/ContractState.py | 5 ++--- neo/Prompt/Commands/Search.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/neo/Core/FunctionCode.py b/neo/Core/FunctionCode.py index 0f73135cb..de3a0d208 100644 --- a/neo/Core/FunctionCode.py +++ b/neo/Core/FunctionCode.py @@ -89,7 +89,7 @@ def Serialize(self, writer): writer.WriteVarBytes(self.ParameterList) writer.WriteByte(self.ReturnType) - def ToJson(self): + def ToJson(self, verbose=True): """ Convert object members to a dictionary that can be parsed as JSON. @@ -98,9 +98,14 @@ def ToJson(self): """ parameters = self.ParameterList.hex() paramlist = [ToName(ContractParameterType.FromString(parameters[i:i + 2]).value) for i in range(0, len(parameters), 2)] + if verbose: + return { + 'hash': self.ScriptHash().To0xString(), + 'script': self.Script.hex(), + 'parameters': paramlist, + 'returntype': ToName(self.ReturnType) if type(self.ReturnType) is int else ToName(int(self.ReturnType)) + } return { 'hash': self.ScriptHash().To0xString(), - 'script': self.Script.hex(), - 'parameters': paramlist, - 'returntype': ToName(self.ReturnType) if type(self.ReturnType) is int else ToName(int(self.ReturnType)) } + diff --git a/neo/Core/State/ContractState.py b/neo/Core/State/ContractState.py index 273a24521..2201cf00f 100644 --- a/neo/Core/State/ContractState.py +++ b/neo/Core/State/ContractState.py @@ -169,7 +169,7 @@ def DetermineIsNEP5(self): self._is_nep5 = True return self._is_nep5 - def ToJson(self): + def ToJson(self, verbose=True): """ Convert object members to a dictionary that can be parsed as JSON. @@ -185,7 +185,7 @@ def ToJson(self): jsn = {'version': self.StateVersion} - jsn_code = self.Code.ToJson() + jsn_code = self.Code.ToJson(verbose=verbose) jsn_contract = { 'name': name, @@ -199,7 +199,6 @@ def ToJson(self): 'payable': self.Payable } } - jsn.update(jsn_code) jsn.update(jsn_contract) diff --git a/neo/Prompt/Commands/Search.py b/neo/Prompt/Commands/Search.py index 6953f085a..68f195b2e 100644 --- a/neo/Prompt/Commands/Search.py +++ b/neo/Prompt/Commands/Search.py @@ -64,7 +64,7 @@ def execute(self, arguments): contracts = Blockchain.Default().SearchContracts(query=item) print("Found %s results for %s" % (len(contracts), item)) for contract in contracts: - print(json.dumps(contract.ToJson(), indent=4)) + print(json.dumps(contract.ToJson(verbose=False), indent=4)) return contracts else: print("run `%s %s help` to see supported queries" % (CommandSearch().command_desc().command, self.command_desc().command)) From d8dbff559645694955cca7acd56245cbc597898e Mon Sep 17 00:00:00 2001 From: Joe Stewart Date: Thu, 7 Nov 2019 10:43:55 -0500 Subject: [PATCH 2/2] changelog update and lint fix --- CHANGELOG.rst | 1 + neo/Core/FunctionCode.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e85dfce1e..89d6bd427 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,7 @@ All notable changes to this project are documented in this file. - Fix shutdown operations when initializing np-api-server and setting minpeers/maxpeers, opening a wallet, or changing databases - Minor improvement to network recovery logic when running out of good node addresses - Fix NEP-5 contract detection causing an EventHub exception due to wrong ApplicationEngine initialization +- Hide contract script in `search contract` output for easier reading of search results [0.9.1] 2019-09-16 ------------------ diff --git a/neo/Core/FunctionCode.py b/neo/Core/FunctionCode.py index de3a0d208..04eedd5c8 100644 --- a/neo/Core/FunctionCode.py +++ b/neo/Core/FunctionCode.py @@ -108,4 +108,3 @@ def ToJson(self, verbose=True): return { 'hash': self.ScriptHash().To0xString(), } -