polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
239 stars 111 forks source link

Is there a way to apply custom signedExtensions #364

Closed sweatpotato13 closed 7 months ago

sweatpotato13 commented 7 months ago

For example, in npm library @polkadot/api support custom type and signedExtensions like this

new ApiPromise({
      provider,
      types: {
          ...
      },
      signedExtensions: {
          ...
      }
    });

Is there a way to change signedExtensions

arjanz commented 7 months ago

Unfortunately not (easily) at the moment. To give pointer where signed_extensions are defined:

https://github.com/polkascan/py-scale-codec/blob/7528c52d24dc2908bb6cb26ecd891972dc67ec7a/scalecodec/types.py#L2334-L2343

And here they are used to build extrinsic payload and generate extrinsic signature payload:

https://github.com/polkascan/py-substrate-interface/blob/4d224f04b8cde0a019fe2ae48cbc4b756a83ebc5/substrateinterface/base.py#L1461-L1517

https://github.com/polkascan/py-scale-codec/blob/7528c52d24dc2908bb6cb26ecd891972dc67ec7a/scalecodec/types.py#L3035-L3054

I am working on version 2 of scale-codec and substrate-interface which is a huge overhaul and more customazible, but for now your best bet is to override the function definition at runtime of GenericMetadataVersioned.get_signed_extensions()

For example:

class CustomMetadataVersioned(GenericMetadataVersioned):
    def get_signed_extensions(self):
        return {}

GenericMetadataVersioned.get_signed_extensions = CustomMetadataVersioned.get_signed_extensions

substrate = SubstrateInterface(
    url="ws://127.0.0.1:9944"
)
# etc
sweatpotato13 commented 7 months ago

So, it is possible to modify the code now.

Thank you for answer.