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

Get account info with predefined generic call #145

Closed
stolpa4 opened this issue Oct 19, 2021 · 5 comments
Closed

Get account info with predefined generic call #145

stolpa4 opened this issue Oct 19, 2021 · 5 comments

Comments

@stolpa4
Copy link

stolpa4 commented Oct 19, 2021

Let's assume that I have an instance of GenericCall (balances.Transfer), obtained by some other means (e.g. via a different SubstrateInterface instance).

Now I want to use it to get the payment info. The overall code looks similar to this:

call = ... # get an instance of GenericCall
addr_from = ... # some address, represented as str

s = SubstrateInterface('wss://westend-rpc.polkadot.io')
print(s.get_payment_info(call=call, keypair=Keypair(ss58_address=addr_from)))

The code throws the following exception:

File "example.py", line 7, in <module>
    print(s.get_payment_info(call=call, keypair=Keypair(ss58_address=addr_from)))
  File ".../venv/lib/python3.8/site-packages/substrateinterface/base.py", line 1689, in get_payment_info
    extrinsic = self.create_signed_extrinsic(
  File ".../venv/lib/python3.8/site-packages/substrateinterface/base.py", line 1559, in create_signed_extrinsic
    extrinsic.encode({
  File ".../venv/lib/python3.8/site-packages/scalecodec/base.py", line 698, in encode
    self.data = self.process_encode(self.value_serialized)
  File ".../venv/lib/python3.8/site-packages/scalecodec/types.py", line 2400, in process_encode
    data += extrinsic.encode(value)
  File ".../venv/lib/python3.8/site-packages/scalecodec/base.py", line 698, in encode
    self.data = self.process_encode(self.value_serialized)
  File ".../venv/lib/python3.8/site-packages/scalecodec/types.py", line 491, in process_encode
    data += element_obj.encode(value[key])
  File ".../venv/lib/python3.8/site-packages/scalecodec/base.py", line 698, in encode
    self.data = self.process_encode(self.value_serialized)
  File ".../venv/lib/python3.8/site-packages/scalecodec/types.py", line 1381, in process_encode
    if self.metadata.portable_registry:
AttributeError: 'NoneType' object has no attribute 'portable_registry'

As far as I see, this is a kind of dynamic initialization, which fails to work, when I call get_payment_info method first.

Is it a bug? If no, how can I work this around?

The use case is pretty simple. I see, that I can't use SubstrateInterface in a concurrent way because this class has a state (see #82 (comment) ). So I maintain a pool of SubstrateInterface instances with pre-defined lock for each to allow this abstraction work in a parallel way.

@arjanz
Copy link
Member

arjanz commented Oct 20, 2021

This was because of a missing passthrough of metadata in GenericCall (polkascan/py-scale-codec@b497d5f)

A fix is release in https://github.com/polkascan/py-scale-codec/releases/tag/v1.0.12

@stolpa4 stolpa4 closed this as completed Oct 20, 2021
@stolpa4
Copy link
Author

stolpa4 commented Oct 20, 2021

Sorry, but I'm afraid that this release does not fix the issue described. Scalecodec v1.0.12 does produce the same exact traceback

@stolpa4 stolpa4 reopened this Oct 20, 2021
@arjanz
Copy link
Member

arjanz commented Oct 21, 2021

I guess you didn't create the call using SubstrateInterface.compose_call()? This does some necessary initialisation in order to use a GenericCall instance for that runtime:

s = SubstrateInterface('wss://westend-rpc.polkadot.io')
keypair = Keypair.create_from_uri('//Alice')

call = s.compose_call(
    call_module='Balances',
    call_function='transfer',
    call_params={
        'dest': '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
        'value': 1 * 10**15
    }
)

print(s.get_payment_info(call=call, keypair=keypair))

@arjanz
Copy link
Member

arjanz commented Oct 21, 2021

@stolpa4
Copy link
Author

stolpa4 commented Oct 21, 2021

Ok, obviously it's not a bug. I just have been misled by the interface, which does not enforce me to call one method after another.
So, closing this.

@stolpa4 stolpa4 closed this as completed Oct 21, 2021
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

No branches or pull requests

2 participants