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

decoding extrinsic panics. #405

Open
georlav opened this issue Oct 17, 2024 · 5 comments
Open

decoding extrinsic panics. #405

georlav opened this issue Oct 17, 2024 · 5 comments

Comments

@georlav
Copy link

georlav commented Oct 17, 2024

Every time I try to use codec.Decode or codec.DecodeFromHex on an extrinsic I previously created using the codec, the codec panics. I can broadcast these extrinsics without any issues, so they are valid.

In the following example, I'm using codec.DecodeFromHex for simplicity, but the same problem occurs if I use codec.Decode or even if I try to use the Marshaler.

encodedExt  = "0x450284005cd06e12b185738b6c25feb5ce37d522ef887faed480ccd4bf970fff094b3a5c01e4cdece2479208010bd5dbfc0851261a16bc9c7d3e63d69a3d148f31bd9a3f6ed0ae5d36ea1905dfcb64e98f8ff09e5576da86428ab27947a9c27ab05ca4628c00740000003208a6e9010000a01dd0d5a5e69b7f8f569e2fedb722c13254d7d5775a3474878e1d0190f35807d1cf"

var ext extrinsic.Extrinsic
err := codec.DecodeFromHex(encodedExt, &ext)
if err != nil {
    log.Fatal(err)
}

However, I receive the following panic:

panic: reflect: call of reflect.Value.Type on zero Value

The extrinsic can be decoded successfully using this tool: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fasset-hub-westend-rpc.dwellir.com#/extrinsics/decode

I am using the latest master branch.

@AstaFrode
Copy link

@georlav Hello, have you solved this problem? I also have this problem.

@georlav
Copy link
Author

georlav commented Jan 13, 2025

@georlav Hello, have you solved this problem? I also have this problem.

No, I haven’t spent much time on it. As a temporary workaround, I had created a small function that mimics SubmitAndWatchExtrinsic but accepts the extrinsic bytes versus extrinsic.Extrinsic, bypassing the encoding step.

@AstaFrode
Copy link

@georlav Hello, have you solved this problem? I also have this problem.

No, I haven’t spent much time on it. As a temporary workaround, I had created a small function that mimics SubmitAndWatchExtrinsic but accepts the encoded extrinsic versus extrinsic.Extrinsic, bypassing the encoding step.

Hi, could you share your solution with me? I'd be very grateful.

@georlav
Copy link
Author

georlav commented Jan 13, 2025

@georlav Hello, have you solved this problem? I also have this problem.

No, I haven’t spent much time on it. As a temporary workaround, I had created a small function that mimics SubmitAndWatchExtrinsic but accepts the encoded extrinsic versus extrinsic.Extrinsic, bypassing the encoding step.

Hi, could you share your solution with me? I'd be very grateful.

Here is a draft example of how you can use the client and submit the extrinsic bytes

         var (
		encodedExtrinsicBytes = []byte{} // Signed extrinsic bytes
		c                                      = make(chan types.ExtrinsicStatus)
		hexEncodedExtrinsic    = fmt.Sprintf("%#x", encodedExtrinsicBytes)
	)

	api, err := gsrpc.NewSubstrateAPI("wss://wnd-rpc.stakeworld.io/westmint")
	if err != nil {
		log.Fatal("initializing Polkadot substrate API")
	}
	client := api.Client

	sub, err := client.Subscribe(
		context.TODO(), "author", "submitAndWatchExtrinsic", "unwatchExtrinsic", "extrinsicUpdate", c, hexEncodedExtrinsic,
	)
	if err != nil {
		log.Fatal("subscribing to extrinsic updates", err)
	}
	defer sub.Unsubscribe()

	for {
		status, ok := <-c
		if !ok {
			log.Fatal("subscription closed")
		}
		if status.IsFinalized {
			log.Printf("Extrinsic got published %s", status.AsInBlock.Hex())
			break
		}
	}

@AstaFrode
Copy link

@georlav Oh, I thought you had solved the problem of parsing string extrinsic temporarily. Thank you anyway.

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