2

大家好,我正在努力通过py-substrate-interface提交外部文件,但由于某种原因,我在遵循此处提到的示例时不断收到错误消息。我的代码如下:

    def send_funds(self, destination, amount):
        self.log.info("Sending {} DOT to {} ...".format(amount, destination.strip()))
        substrate = self.create_substrate_instance(self.node_ws_port[0])

        keypair = Keypair.create_from_mnemonic('level payment mom grape proof display cause engage erupt rain hair arm')
        print(keypair)

        call = substrate.compose_call(
            call_module='Balances',
            call_function='transfer',
            call_params={
                'dest': destination,
                'value': ceil(amount * DOT)
            }
        )

        try:
            extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
        except Exception as e:
            print(e)

        try:
            receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
            self.log.info("Extrinsic '{}' sent and included in block '{}'".format(receipt.extrinsic_hash, receipt.block_hash))
            self.log.info("{} DOT sent to address: {}".format(amount, destination))
        except SubstrateRequestException as e:
            self.log.error("Failed to send: {}".format(e))

我在这里试了一下,除了块:

        try:
            extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
        except Exception as e:
            print(e)

运行此代码块时出现以下错误:

No more bytes available (offset: 80 / length: 72)

我该如何解决这个问题。

4

2 回答 2

4

大多数时候 aRemainingScaleBytesNotEmptyException被提出,它与类型注册表相关。在 Substrate 运行时(如 Kusama、Polkadot 等)中定义了特定类型,这些类型(尚未)暴露在元数据中,因此库必须包含对这些类型的原语的分解。

故障排除的一些提示:

于 2021-04-13T08:36:14.663 回答
1

好吧,在深入挖掘后发现问题与奇偶级编解码器中的编码有关,您需要根据运行时调整网络配置。所以我改变了:

    def create_substrate_instance(self, wsport):
        return SubstrateInterface(
                    url=self.rpc_url + wsport,
                    ss58_format=42,
                    type_registry_preset='kusama',
                )

至:

    def create_substrate_instance(self, wsport):
        return SubstrateInterface(
                    url=self.rpc_url + wsport,
                    ss58_format=42,
                    type_registry_preset='substrate-node-template',
                )

它奏效了。

于 2021-04-13T02:14:17.853 回答