token

package
v0.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

Token Metadata for Go

Usage

Import this repo directly into your own go repo

Maintain

To add a new token's metadata:
  1. add a new token_name: {address:token_address, coinGeckoId:token_coingecko_id, denom:token_denom, metaSource: [Alchemy/custom]} kv pair in token_meta.json
  2. run make gen
To add some new util functions
  1. develop your new util functions
  2. don't forget to run make build to make sure no error in compiling at least

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDenomToMetadataMap added in v0.0.19

func SetDenomToMetadataMap(metadataMap map[string]*Token)

Types

type AlchemyRequest added in v0.0.3

type AlchemyRequest struct {
	JsonRPC string `json:"jsonrpc"`
	ID      int    `json:"id"`

	Method string   `json:"method"`
	Params []string `json:"params"`
}

type Dict

type Dict map[string]*Token

type EthereumAddress

type EthereumAddress struct {
	common.Address
}

type Meta

type Meta struct {
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	Decimals int    `json:"decimals"`
}

Meta this struct is the same as the metadata in the resp of Alchemy

type MetaSource added in v0.0.7

type MetaSource string
const (
	MetaSourceAlchemy MetaSource = "alchemy" // query from Alchemy API
	MetaSourceCustom  MetaSource = "custom"  // defined in Customizers
)

type MetadataResponse added in v0.0.3

type MetadataResponse struct {
	JsonRPC string `json:"jsonrpc"`
	ID      int    `json:"id"`

	Error  *RPCError `json:"error"`
	Result *Meta     `json:"result"`
}

type RPCError added in v0.0.3

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Token

type Token struct {
	Address        string     `json:"address"`
	CoingeckoID    string     `json:"coinGeckoId"`
	Denom          string     `json:"denom,omitempty"`
	MetaSource     MetaSource `json:"metaSource"`
	Meta           *Meta      `json:"meta"`
	LastAccessTime time.Time  `json:"-"`
}

func GetTokenByAddress

func GetTokenByAddress(address string) *Token

GetTokenByAddress no case sensitivity, and it's safe to pass address with prefix "peggy" for unknown address, request metadata from alchemy This method rely on an internal cache, so it's safe to call it frequently

func GetTokenByDenom added in v0.0.7

func GetTokenByDenom(denom string) *Token

GetTokenByDenom no case sensitivity

func GetTokenBySymbol

func GetTokenBySymbol(symbol string) *Token

GetTokenBySymbol no case sensitivity, USD/usd/Usd are all fine

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL