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

DecodeEventRecords function throw an err for "Encoded array length is higher than allowed by the protocol (32-bit unsigned integer)" #372

Open
glant509 opened this issue Dec 27, 2023 · 0 comments

Comments

@glant509
Copy link

glant509 commented Dec 27, 2023

    types.EventRecordsRaw(*storageDataRaw).DecodeEventRecords(metadata, &events0) has a err for "Encoded array length is higher than allowed by the protocol (32-bit unsigned integer)"

   the err appear at codec.go, because the event System_ExtrinsicSuccess.DispatchInfo.Weight.RefTime is a uint64 format, but the sdk restricted to uint32, when it over uint32, there will be return this err.  in my test code, the blockNumber(number) is 12472776

my code detail is:

import (
"encoding/hex"
"encoding/json"
"fmt"
gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry/parser"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry/state"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/vedhavyas/go-subkey/v2"
"io/ioutil"
"net/http"
"strconv"
"strings"
)
func getEvents(number int, hash, url string) {
api, err := gsrpc.NewSubstrateAPI(url)
if err != nil {
panic("NewSubstrateAPI")
}

blockLatest, err := api.RPC.Chain.GetBlockLatest()
if err != nil {
	panic("api.RPC.Chain.GetBlockLatest()")
}

header := blockLatest.Block.Header
extrinsics := blockLatest.Block.Extrinsics

fmt.Println(header.Number, len(extrinsics))

blockHash, err := api.RPC.Chain.GetBlockHash(uint64(number))
if err != nil {
	panic("api.RPC.Chain.GetBlockHash(uint64(header.Number)")
}
fmt.Println("block_hash", hex.EncodeToString(blockHash[:]))

metadata, err := api.RPC.State.GetMetadata(blockHash)
if err != nil {
	panic("api.RPC.State.GetMetadata(blockHash)")
}

storageKey, err := types.CreateStorageKey(metadata, "System", "Events")
if err != nil {
	panic("types.CreateStorageKey")
}
storageDataRaw, err := api.RPC.State.GetStorageRaw(storageKey, blockHash)
if err != nil {
	panic("api.RPC.State.GetStorageRaw")
}

events0 := types.EventRecords{}
err = types.EventRecordsRaw(*storageDataRaw).DecodeEventRecords(metadata, &events0)
if err != nil {
	panic(err)
}

fmt.Println(events0)

}

call the func getEvents in a main func like this:

func main() {
getEvents(12472776, "hash", "https://docs-demo.dot-mainnet.quiknode.pro/")
}

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

1 participant