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

Trying to decode EventRecords failed on testnet : field Indices_IndexAssigned: expected more bytes #317

Open
bugbuilder opened this issue Dec 20, 2022 · 1 comment

Comments

@bugbuilder
Copy link

When I tried to parse events records to get information about balance transfers its failed on tesnet (rococo and wested) but on mainnet works.

panic: unable to decode field 3 event #1 with EventID [3 0], field Indices_IndexAssigned: expected more bytes, but could not decode any more

There is a workaround or alternative to have the same code working on mainnet and testnet?

./main wss://rpc.polkadot.io <-- works
./main wss://rococo-rpc.polkadot.io <-- it doesn’t work
./main wss://westend-rpc.polkadot.io <-- it doesn’t work
package main

import (
	"os"

	gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4"
	"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)

func main() {
	rpc := os.Args[1]
	api, err := gsrpc.NewSubstrateAPI(rpc)
	checkErr(err)

	meta, err := api.RPC.State.GetMetadataLatest()
	checkErr(err)

	head, err := api.RPC.Chain.GetFinalizedHead()
	checkErr(err)

	key, err := types.CreateStorageKey(meta, "System", "Events", nil, nil)
	checkErr(err)

	raw, err := api.RPC.State.GetStorageRaw(key, head)
	checkErr(err)

	events := types.EventRecords{}
	err = types.EventRecordsRaw(*raw).DecodeEventRecords(meta, &events)
	checkErr(err)
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}
@cdamian
Copy link
Contributor

cdamian commented Dec 5, 2023

Hey @bugbuilder,

We added a way to dynamically decode events. You can find an example here - https://github.com/centrifuge/go-substrate-rpc-client/blob/master/registry/retriever/event_retriever_live_test.go#L76

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