Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose chain-registry structs #4472

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions ignite/pkg/chainregistry/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package chainregistry

import (
"encoding/json"
"os"
)

// AssetList represents the assetlist.json file from the chain registry.
// https://raw.githubusercontent.com/cosmos/chain-registry/master/assetlist.schema.json
// https://github.com/cosmos/chain-registry?tab=readme-ov-file#assetlists
type AssetList struct {
ChainName string `json:"chain_name"`
Assets []Asset `json:"assets"`
}

type Asset struct {
Description string `json:"description"`
DenomUnits []DenomUnit `json:"denom_units"`
Base string `json:"base"`
Name string `json:"name"`
Display string `json:"display"`
Symbol string `json:"symbol"`
LogoURIs LogoURIs `json:"logo_URIs"`
CoingeckoID string `json:"coingecko_id,omitempty"`
Socials Socials `json:"socials,omitempty"`
TypeAsset string `json:"type_asset"`
}

type DenomUnit struct {
Denom string `json:"denom"`
Exponent int `json:"exponent"`
}

type LogoURIs struct {
Png string `json:"png"`
Svg string `json:"svg"`
}

type Socials struct {
Website string `json:"website"`
Twitter string `json:"twitter"`
}

// SaveJSON saves the assetlist.json to the given out directory.
func (c AssetList) SaveJSON(out string) error {
bz, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}

return os.WriteFile(out, bz, 0o600)
}
98 changes: 98 additions & 0 deletions ignite/pkg/chainregistry/chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package chainregistry

import (
"encoding/json"
"os"
)

// Chain represents the chain.json file from the chain registry.
// https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json
type Chain struct {
ChainName string `json:"chain_name"`
Status ChainStatus `json:"status"`
NetworkType NetworkType `json:"network_type"`
Website string `json:"website"`
PrettyName string `json:"pretty_name"`
ChainType ChainType `json:"chain_type"`
ChainID string `json:"chain_id"`
Bech32Prefix string `json:"bech32_prefix"`
DaemonName string `json:"daemon_name"`
NodeHome string `json:"node_home"`
KeyAlgos []KeyAlgos `json:"key_algos"`
Slip44 int `json:"slip44"`
Fees Fees `json:"fees"`
Staking Staking `json:"staking"`
Codebase Codebase `json:"codebase"`
Description string `json:"description"`
APIs APIs `json:"apis"`
}

type Staking struct {
StakingTokens []StakingToken `json:"staking_tokens"`
}

type StakingToken struct {
Denom string `json:"denom"`
}

type Codebase struct {
GitRepo string `json:"git_repo"`
Genesis CodebaseGenesis `json:"genesis"`
RecommendedVersion string `json:"recommended_version"`
CompatibleVersions []string `json:"compatible_versions"`
Consensus CodebaseInfo `json:"consensus"`
Sdk CodebaseInfo `json:"sdk"`
Ibc CodebaseInfo `json:"ibc,omitempty"`
Cosmwasm CodebaseInfoEnabled `json:"cosmwasm,omitempty"`
}

type CodebaseGenesis struct {
GenesisURL string `json:"genesis_url"`
}

type CodebaseInfo struct {
Type string `json:"type"`
Version string `json:"version"`
Repo string `json:"repo,omitempty"`
Tag string `json:"tag,omitempty"`
}

type CodebaseInfoEnabled struct {
Version string `json:"version,omitempty"`
Repo string `json:"repo,omitempty"`
Tag string `json:"tag,omitempty"`
Enabled bool `json:"enabled"`
}

type Fees struct {
FeeTokens []FeeToken `json:"fee_tokens"`
}

type FeeToken struct {
Denom string `json:"denom"`
FixedMinGasPrice float64 `json:"fixed_min_gas_price"`
LowGasPrice float64 `json:"low_gas_price"`
AverageGasPrice float64 `json:"average_gas_price"`
HighGasPrice float64 `json:"high_gas_price"`
}

type APIs struct {
RPC []APIProvider `json:"rpc"`
Rest []APIProvider `json:"rest"`
Grpc []APIProvider `json:"grpc"`
}

type APIProvider struct {
Address string `json:"address"`
Provider string `json:"provider"`
}

// SaveJSON saves the chainJSON to the given out directory.
func (c Chain) SaveJSON(out string) error {
bz, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}

return os.WriteFile(out, bz, 0o600)
}
50 changes: 50 additions & 0 deletions ignite/pkg/chainregistry/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package chainregistry

type NetworkType string

const (
// NetworkTypeMainnet is the mainnet network type.
NetworkTypeMainnet NetworkType = "mainnet"

// NetworkTypeTestnet is the testnet network type.
NetworkTypeTestnet NetworkType = "testnet"

// NetworkTypeDevnet is the devnet network type.
NetworkTypeDevnet NetworkType = "devnet"
)

type ChainType string

const (
// ChainTypeCosmos is the cosmos chain type.
ChainTypeCosmos ChainType = "cosmos"

// ChainTypeEip155 is the eip155 chain type.
ChainTypeEip155 ChainType = "eip155"
)

type ChainStatus string

const (
// ChainStatusActive is the live chain status.
ChainStatusActive ChainStatus = "live"

// ChainStatusUpcoming is the upcoming chain status.
ChainStatusUpcoming ChainStatus = "upcoming"

// ChainStatusKilled is the inactive chain status.
ChainStatusKilled ChainStatus = "killed"
)

type KeyAlgos string

const (
// KeyAlgoSecp256k1 is the secp256k1 key algorithm.
KeyAlgoSecp256k1 KeyAlgos = "secp256k1"

// KeyAlgosEthSecp256k1 is the secp256k1 key algorithm with ethereum compatibility.
KeyAlgosEthSecp256k1 KeyAlgos = "ethsecp256k1"

// KeyAlgoEd25519 is the ed25519 key algorithm.
KeyAlgoEd25519 KeyAlgos = "ed25519"
)
3 changes: 3 additions & 0 deletions ignite/pkg/chainregistry/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// package chainregistry is a package that contains the chain.json and assetlist.json structs from the chain registry.
// Useful when parsing or creating chain.json and assetlist.json files.
package chainregistry
Loading
Loading