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

How to build event types using metadata? #264

Open
csknk opened this issue Jun 6, 2022 · 1 comment
Open

How to build event types using metadata? #264

csknk opened this issue Jun 6, 2022 · 1 comment

Comments

@csknk
Copy link

csknk commented Jun 6, 2022

Is it possible to retrieve data types for events from metadata?

The objective is to extend the types.EventRecords type for the given chain (in my case, Polkadot) to prevent unkown type errors when decoding events.

I'm attempting to list out the data types for events, and I'm unsure how si1Lookup works.

Sample code:

func TestGetEventsFromMeta(t *testing.T) {
	c, err := NewConnection("http://localhost:9934")
	assert.NoError(t, err)
	meta, err := c.getLatestMetadata()
	assert.NoError(t, err)

	for _, mod := range meta.AsMetadataV14.Pallets {
		if !mod.HasEvents {
			continue
		}
		if typ, ok := meta.AsMetadataV14.EfficientLookup[mod.Events.Type.Int64()]; ok {
			if len(typ.Def.Variant.Variants) > 0 {
				for _, vars := range typ.Def.Variant.Variants {
					fmt.Printf("%s\t%s\n", mod.Name, vars.Name)
					for _, field := range vars.Fields {

						// How to decode field data here? <---------------------------------------------------
						fmt.Printf("%#v\n", meta.AsMetadataV14.Lookup.Types[field.Type.Int64()])

					}
				}
			}
		}
	}
}

Related to issue #220

@cdamian
Copy link
Contributor

cdamian commented Dec 5, 2023

Hey @csknk,

Please refer to - #251 (comment)

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