Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions neo/Core/Blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def GetAssetState(self, assetId):
def SearchAssetState(self, query):
pass

def ShowAllAssets(self, query):
pass

def GetHeaderHash(self, height):
pass

Expand Down
6 changes: 6 additions & 0 deletions neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ def GetAssetState(self, assetId):

return asset

def ShowAllAssets(self):

assets = DBCollection(self._db, DBPrefix.ST_Asset, AssetState)
keys = assets.Keys
return keys

def GetTransaction(self, hash):

if type(hash) is str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ def test_GetHeaderBy(self):
invalid_bc_height = self._blockchain.Height + 1
block = self._blockchain.GetHeaderBy(invalid_bc_height)
self.assertEqual(block, None)

def test_ShowAllAssets(self):
assets = Blockchain.Default().ShowAllAssets()
self.assertEqual(len(assets), 2)
75 changes: 75 additions & 0 deletions neo/Prompt/Commands/Search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from neo.Prompt.CommandBase import CommandBase, CommandDesc, ParameterDesc
from neo.Prompt.PromptData import PromptData
from neo.Prompt.Utils import get_arg
from neo.Core.Blockchain import Blockchain
from prompt_toolkit.shortcuts import print_formatted_text
from prompt_toolkit.formatted_text import FormattedText
from neo.logging import log_manager
import json


logger = log_manager.getLogger()


class CommandSearch(CommandBase):
def __init__(self):
super().__init__()

self.register_sub_command(CommandSearchAsset())
self.register_sub_command(CommandSearchContract())

def command_desc(self):
return CommandDesc('search', 'search the blockchain')

def execute(self, arguments):
item = get_arg(arguments)

if not item:
print("run `search help` to see supported queries")
return

try:
return self.execute_sub_command(item, arguments[1:])
except KeyError:
print(f"search: {item} is an invalid parameter")
return


class CommandSearchAsset(CommandBase):
def __init__(self):
super().__init__()

def execute(self, arguments):
item = get_arg(arguments)

results = Blockchain.Default().SearchAssetState(item)
print("Found %s results for %s" % (len(results), item))
for asset in results:
bjson = json.dumps(asset.ToJson(), indent=4)
tokens = [("class:number", bjson)]
print_formatted_text(FormattedText(tokens), style=PromptData.Prompt.token_style)
return results

def command_desc(self):
p1 = ParameterDesc('query', 'supports name, issuer, or admin searches')
return CommandDesc('asset', 'perform an asset search', [p1])


class CommandSearchContract(CommandBase):
def __init__(self):
super().__init__()

def execute(self, arguments):
item = get_arg(arguments)

contracts = Blockchain.Default().SearchContracts(query=item)
print("Found %s results for %s" % (len(contracts), item))
for contract in contracts:
bjson = json.dumps(contract.ToJson(), indent=4)
tokens = [("class:number", bjson)]
print_formatted_text(FormattedText(tokens), style=PromptData.Prompt.token_style)
return contracts

def command_desc(self):
p1 = ParameterDesc('query', 'supports name, author, description, or email searches')
return CommandDesc('contract', 'perform a contract search', [p1])
Loading