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

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/stafiprotocol/go-substrate-rpc-client/pkg/scale"
     7  )
     8  
     9  type RSymbol string
    10  
    11  const (
    12  	RFIS   = RSymbol("RFIS")
    13  	RDOT   = RSymbol("RDOT")
    14  	RKSM   = RSymbol("RKSM")
    15  	RATOM  = RSymbol("RATOM")
    16  	RSOL   = RSymbol("RSOL")
    17  	RMATIC = RSymbol("RMATIC")
    18  	RBNB   = RSymbol("RBNB")
    19  	RETH   = RSymbol("RETH")
    20  )
    21  
    22  func (r *RSymbol) Decode(decoder scale.Decoder) error {
    23  	b, err := decoder.ReadOneByte()
    24  	if err != nil {
    25  		return err
    26  	}
    27  
    28  	switch b {
    29  	case 0:
    30  		*r = RFIS
    31  		// return fmt.Errorf("RSymbol decode error: %d", b)
    32  	case 1:
    33  		*r = RDOT
    34  	case 2:
    35  		*r = RKSM
    36  	case 3:
    37  		*r = RATOM
    38  	case 4:
    39  		*r = RSOL
    40  	case 5:
    41  		*r = RMATIC
    42  	case 6:
    43  		*r = RBNB
    44  	case 7:
    45  		*r = RETH
    46  	default:
    47  		return fmt.Errorf("RSymbol decode error: %d", b)
    48  	}
    49  
    50  	return nil
    51  }
    52  
    53  func (r RSymbol) Encode(encoder scale.Encoder) error {
    54  	switch r {
    55  	case RFIS:
    56  		return encoder.PushByte(0)
    57  		// return fmt.Errorf("RFIS not supported")
    58  	case RDOT:
    59  		return encoder.PushByte(1)
    60  	case RKSM:
    61  		return encoder.PushByte(2)
    62  	case RATOM:
    63  		return encoder.PushByte(3)
    64  	case RSOL:
    65  		return encoder.PushByte(4)
    66  	case RMATIC:
    67  		return encoder.PushByte(5)
    68  	case RBNB:
    69  		return encoder.PushByte(6)
    70  	case RETH:
    71  		return encoder.PushByte(7)
    72  	default:
    73  		return fmt.Errorf("RSymbol %s not supported", r)
    74  	}
    75  }
    76  
    77  // used in db of rtoken-info
    78  func (r RSymbol) ToRtokenType() int8 {
    79  	switch r {
    80  	case RFIS:
    81  		return (0)
    82  	case RDOT:
    83  		return (1)
    84  	case RKSM:
    85  		return (2)
    86  	case RATOM:
    87  		return (3)
    88  	case RSOL:
    89  		return (4)
    90  	case RMATIC:
    91  		return (5)
    92  	case RBNB:
    93  		return (6)
    94  	case RETH:
    95  		return (-1)
    96  	default:
    97  		return -2
    98  	}
    99  }
   100  
   101  func (r RSymbol) ToString() string {
   102  	return string(r)
   103  }