github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/rpc/state/get_consts.go (about)

     1  package state
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/stafiprotocol/go-substrate-rpc-client/types"
     6  )
     7  
     8  const (
     9  	metaV10 = 10
    10  	metaV11 = 11
    11  	metaV12 = 12
    12  	metaV13 = 13
    13  )
    14  
    15  func (s *State) GetConst(prefix, name string, res interface{}) error {
    16  	meta, err := s.GetMetadataLatest()
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	return s.GetConstWithMetadata(meta, prefix, name, res)
    22  }
    23  
    24  func (s *State) GetConstWithMetadata(meta *types.Metadata, prefix, name string, res interface{}) error {
    25  	switch meta.Version {
    26  	case metaV13:
    27  		return meta.AsMetadataV13.GetConst(prefix, name, res)
    28  	case metaV12:
    29  		return meta.AsMetadataV12.GetConst(prefix, name, res)
    30  	case metaV11:
    31  		return meta.AsMetadataV11.GetConst(prefix, name, res)
    32  	case metaV10:
    33  		return meta.AsMetadataV10.GetConst(prefix, name, res)
    34  	default:
    35  		return fmt.Errorf("unsupported metadata version")
    36  	}
    37  }