github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/pkg/stafidecoder/metadata_model.go (about)

     1  package stafi_decoder
     2  
     3  import (
     4  	"errors"
     5  	"github.com/itering/scale.go/utiles"
     6  )
     7  
     8  type MetadataDecoder struct {
     9  	ScaleDecoder
    10  	Version       string         `json:"version"`
    11  	VersionNumber int            `json:"version_number"`
    12  	Metadata      MetadataStruct `json:"metadata"`
    13  	CodecTypes    []string       `json:"codec_types"`
    14  }
    15  
    16  func (m *MetadataDecoder) Init(data []byte) {
    17  	sData := ScaleBytes{Data: data}
    18  	m.ScaleDecoder.Init(sData, nil)
    19  }
    20  
    21  func (m *MetadataDecoder) Process() error {
    22  	magicBytes := m.NextBytes(4)
    23  	if string(magicBytes) == "meta" {
    24  		metadataVersion := utiles.U256(utiles.BytesToHex(m.Data.Data[m.Data.Offset : m.Data.Offset+1]))
    25  		m.Version = m.ProcessAndUpdateData("MetadataVersion").(string)
    26  		m.Metadata = m.ProcessAndUpdateData(m.Version).(MetadataStruct)
    27  		m.Metadata.MetadataVersion = int(metadataVersion.Int64())
    28  		m.CodecTypes = utiles.UniqueSlice(RuntimeCodecType)
    29  		return nil
    30  	}
    31  	return errors.New("not metadata")
    32  
    33  }