question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get account info with predefined generic call

See original GitHub issue

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 https://github.com/polkascan/py-substrate-interface/issues/82#issuecomment-937803341 ). So I maintain a pool of SubstrateInterface instances with pre-defined lock for each to allow this abstraction work in a parallel way.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arjanzcommented, Oct 20, 2021
0reactions
stolpa4commented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Calling generic method with a type argument known only ...
The basic answer is as before: Find the "open" generic method with Type.GetMethod; Make it generic using MakeGenericMethod; Invoke it with Invoke. Here's...
Read more >
How To Use Generics in TypeScript - DigitalOcean
Default Type Parameters. Creating your generic fetchApi function like you are doing, the calling code always has to provide the type parameter.
Read more >
Documentation - Generics - TypeScript
This Type allows us to capture the type the user provides (e.g. number ) ... Once we've written the generic identity function, we...
Read more >
Default values for generic parameters · Issue #49158 - GitHub
Parameters with generic types should be able to accept default values as long as they fit within the specified scope of the generic...
Read more >
Understanding TypeScript Generics - Smashing Magazine
In C#'s type system, all types, be they predefined or user-defined and be they reference types or value types, inherit either directly or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found