Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getinfo command in pyhton #340

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

MizukiSonoko
Copy link
Contributor

Hello commiters.

Currently I develop an apps about lightning network.
I faced a problem like this.

$ glcli getinfo
[2023-12-14 14:13:01,134 - INFO] Configuring client with user identity.
Traceback (most recent call last):
  File "/usr/local/var/pyenv/versions/3.11.3/bin/glcli", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/glcli/cli.py", line 354, in getinfo
    pbprint(res)
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/site-packages/glcli/cli.py", line 236, in pbprint
    print(json.dumps(dta))
          ^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/var/pyenv/versions/3.11.3/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable

After investigating the cause, I felt dict2jsondict was wrong.
input data contains binary string ( 'channel': b'') , but dict2jsondict dosn't convert it.

{
  'id': '0372....8707',
  'alias': 'UNITEDSCAN-v23.08gl1',
  'color': '0372c3',
  'version': 'v23.08gl1',
  'lightning_dir': '/tmp/testnet',
  'our_features': {
    'init': '08a0800a8269a2',
    'node': '88...a2',
    'invoice': '02..000',
    'channel': b''},
  'blockheight': 2542787,
  'network': 'testnet',
  'fees_collected_msat': {'msat': 0}
}

So I tried to fix it, but what do you think?

Regards

@cdecker
Copy link
Collaborator

cdecker commented Dec 14, 2023

This is great @MizukiSonoko, thanks for investigating this, and apologies for not catching this earlier 👍

ACK dc0bd4a

@cdecker cdecker enabled auto-merge (rebase) December 14, 2023 12:44
@cdecker cdecker merged commit 2dc5a94 into Blockstream:main Dec 14, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants