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 0f73135cb..04eedd5c8 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,13 @@ 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))