Skip to content

Commit

Permalink
tuples wip, hidden command
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 16, 2025
1 parent 9f16e04 commit 637be3b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
43 changes: 43 additions & 0 deletions src/dipdup/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NOTE: All imports except the basic ones are very lazy in this module. Let's keep it that way.
import asyncio
import atexit
from collections import defaultdict
import logging
import sys
import traceback
Expand Down Expand Up @@ -978,6 +979,48 @@ async def self_env(ctx: click.Context) -> None:
env.refresh()
env.print()

@cli.group(hidden=True)
@click.pass_context
@_cli_wrapper
async def abi(ctx: click.Context) -> None:
pass

@abi.command(name='lookup', hidden=True)
@click.pass_context
@click.argument('query', type=str)
@_cli_wrapper
async def abi_lookup(ctx: click.Context, query: str) -> None:
import subprocess

from dipdup.package import DipDupPackage

config: DipDupConfig = ctx.obj.config
package = DipDupPackage(config.package_path)
package.initialize()

abi_paths = (
package.abi,
package.abi_local,
)
# NOTE: save output instead of printing it
res = subprocess.run(
('grep', '-n', '-r', query, *abi_paths),
capture_output=True,
check=True,
)
out = res.stdout.decode()
lines = out.splitlines()
grouped_lines = defaultdict(list)
for line in lines:
path, lineno, content = line.split(':', 2)
grouped_lines[path].append(f'{lineno:>6}: {content}')

for path, lines in grouped_lines.items():
echo('')
echo(path)
for line in sorted(lines):
echo('- ' + line)
echo('')

@cli.group()
@click.pass_context
Expand Down
5 changes: 5 additions & 0 deletions src/dipdup/codegen/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def scale_type_to_jsonschema(
schema['type'] = 'boolean'
elif type_string in ['String', 'str']:
schema['type'] = 'string'
# FIXME: We need to parse weird values like `Tuple:staging_xcm:v4:location:Locationstaging_xcm:v4:location:Location`; mind the missing delimeters
elif type_string.startswith('Tuple:'):
# inner_types = type_string[6:]
raise NotImplementedError

elif type_string.startswith('Vec<'):
inner_type = type_string[4:-1]
schema['type'] = 'array'
Expand Down
14 changes: 4 additions & 10 deletions src/dipdup/runtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ def decode_event_args(
from scalecodec.base import ScaleBytes

spec_obj = self.get_spec_version(spec_version)
event_abi = spec_obj.get_event_abi(
qualname=name,
)
event_abi = spec_obj.get_event_abi(name)

# FIXME: Do we need original type names?
# arg_types = event_abi.get('args_type_name') or event_abi['args']
arg_types = event_abi['args']
Expand All @@ -183,19 +182,14 @@ def decode_event_args(
payload[key] = int(value)
continue

# FIXME: Unwrap correctly
if isinstance(value, dict) and '__kind' in value:
payload[key] = value['__kind']
continue

# NOTE: Scale decoder expects vec length at the beginning
# NOTE: Scale decoder expects vec length at the beginning; Subsquid strips it
if type_.startswith('Vec<'):
value_len = len(value[2:]) * 2
value = f'0x{value_len:02x}{value[2:]}'

scale_obj = self.runtime_config.create_scale_object(
type_string=type_,
data=ScaleBytes(value),
data=ScaleBytes(value) if isinstance(value, str) else value,
)

payload[key] = scale_obj.process()
Expand Down

0 comments on commit 637be3b

Please sign in to comment.