github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/pkg/stafidecoder/v10.go (about) 1 package stafi_decoder 2 3 import ( 4 "encoding/json" 5 6 "github.com/huandu/xstrings" 7 "github.com/itering/scale.go/utiles" 8 ) 9 10 type MetadataV10Decoder struct { 11 ScaleDecoder 12 } 13 14 func (m *MetadataV10Decoder) Init(data ScaleBytes, option *ScaleDecoderOption) { 15 m.ScaleDecoder.Init(data, option) 16 } 17 18 func (m *MetadataV10Decoder) Process() { 19 result := MetadataStruct{ 20 Metadata: MetadataTag{ 21 Modules: nil, 22 }, 23 } 24 MetadataV10ModuleCall := m.ProcessAndUpdateData("Vec<MetadataV8Module>").([]interface{}) 25 callModuleIndex := 0 26 eventModuleIndex := 0 27 result.CallIndex = make(map[string]CallIndex) 28 result.EventIndex = make(map[string]EventIndex) 29 bm, _ := json.Marshal(MetadataV10ModuleCall) 30 var modulesType []MetadataModules 31 _ = json.Unmarshal(bm, &modulesType) 32 for k, module := range modulesType { 33 if module.Calls != nil { 34 for callIndex, call := range module.Calls { 35 modulesType[k].Calls[callIndex].Lookup = xstrings.RightJustify(utiles.IntToHex(callModuleIndex), 2, "0") + xstrings.RightJustify(utiles.IntToHex(callIndex), 2, "0") 36 result.CallIndex[modulesType[k].Calls[callIndex].Lookup] = CallIndex{Module: module, Call: call} 37 38 } 39 callModuleIndex++ 40 } 41 if module.Events != nil { 42 for eventIndex, event := range module.Events { 43 modulesType[k].Events[eventIndex].Lookup = xstrings.RightJustify(utiles.IntToHex(eventModuleIndex), 2, "0") + xstrings.RightJustify(utiles.IntToHex(eventIndex), 2, "0") 44 result.EventIndex[modulesType[k].Events[eventIndex].Lookup] = EventIndex{Module: module, Call: event} 45 } 46 eventModuleIndex++ 47 } 48 } 49 50 result.Metadata.Modules = modulesType 51 m.Value = result 52 }