-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chain registry UI #6197
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
Draft
faddat
wants to merge
1
commit into
cosmos:master
Choose a base branch
from
faddat:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,063
−376
Draft
chain registry UI #6197
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Makefile for the Cosmos Chain Registry App | ||
|
||
.PHONY: build run clean lint test package-mac package-windows package-linux package-all | ||
|
||
# Build the application | ||
build: | ||
go build -o chain-registry-app ./cmd/chain-registry-app | ||
|
||
# Run the application | ||
run: build | ||
./chain-registry-app | ||
|
||
# Clean up build artifacts | ||
clean: | ||
rm -f chain-registry-app | ||
rm -rf fyne-cross | ||
|
||
# Run the linter | ||
lint: | ||
golangci-lint run ./... | ||
|
||
# Run tests | ||
test: | ||
go test ./... | ||
|
||
# Package for macOS | ||
package-mac: | ||
go install fyne.io/fyne/v2/cmd/fyne@latest | ||
fyne package -os darwin -icon icon.png -name "Cosmos Chain Registry" | ||
|
||
# Package for Windows | ||
package-windows: | ||
go install fyne.io/fyne/v2/cmd/fyne@latest | ||
fyne package -os windows -icon icon.png -name "Cosmos Chain Registry" | ||
|
||
# Package for Linux | ||
package-linux: | ||
go install fyne.io/fyne/v2/cmd/fyne@latest | ||
fyne package -os linux -icon icon.png -name "Cosmos Chain Registry" | ||
|
||
# Cross-platform packaging (requires Docker) | ||
package-all: | ||
go install github.com/fyne-io/fyne-cross@latest | ||
fyne-cross darwin -app-id "com.faddat.chain-registry" -icon icon.png | ||
fyne-cross windows -app-id "com.faddat.chain-registry" -icon icon.png | ||
fyne-cross linux -app-id "com.faddat.chain-registry" -icon icon.png |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module github.com/faddat/chain-registry | ||
|
||
go 1.24.1 | ||
|
||
require fyne.io/fyne/v2 v2.6.0 | ||
|
||
require ( | ||
fyne.io/systray v1.11.0 // indirect | ||
github.com/BurntSushi/toml v1.4.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fredbi/uri v1.1.0 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/fyne-io/gl-js v0.1.0 // indirect | ||
github.com/fyne-io/glfw-js v0.2.0 // indirect | ||
github.com/fyne-io/image v0.1.1 // indirect | ||
github.com/fyne-io/oksvg v0.1.0 // indirect | ||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect | ||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect | ||
github.com/go-text/render v0.2.0 // indirect | ||
github.com/go-text/typesetting v0.2.1 // indirect | ||
github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
github.com/hack-pad/go-indexeddb v0.3.2 // indirect | ||
github.com/hack-pad/safejs v0.1.0 // indirect | ||
github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08 // indirect | ||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect | ||
github.com/nicksnyder/go-i18n/v2 v2.5.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rymdport/portal v0.4.1 // indirect | ||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect | ||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect | ||
github.com/stretchr/testify v1.10.0 // indirect | ||
github.com/yuin/goldmark v1.7.8 // indirect | ||
golang.org/x/image v0.24.0 // indirect | ||
golang.org/x/net v0.35.0 // indirect | ||
golang.org/x/sys v0.30.0 // indirect | ||
golang.org/x/text v0.22.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
fyne.io/fyne/v2 v2.6.0 h1:Rywo9yKYN4qvNuvkRuLF+zxhJYWbIFM+m4N4KV4p1pQ= | ||
fyne.io/fyne/v2 v2.6.0/go.mod h1:YZt7SksjvrSNJCwbWFV32WON3mE1Sr7L41D29qMZ/lU= | ||
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg= | ||
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs= | ||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= | ||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= | ||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= | ||
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= | ||
github.com/fredbi/uri v1.1.0 h1:OqLpTXtyRg9ABReqvDGdJPqZUxs8cyBDOMXBbskCaB8= | ||
github.com/fredbi/uri v1.1.0/go.mod h1:aYTUoAXBOq7BLfVJ8GnKmfcuURosB1xyHDIfWeC/iW4= | ||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= | ||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= | ||
github.com/fyne-io/gl-js v0.1.0 h1:8luJzNs0ntEAJo+8x8kfUOXujUlP8gB3QMOxO2mUdpM= | ||
github.com/fyne-io/gl-js v0.1.0/go.mod h1:ZcepK8vmOYLu96JoxbCKJy2ybr+g1pTnaBDdl7c3ajI= | ||
github.com/fyne-io/glfw-js v0.2.0 h1:8GUZtN2aCoTPNqgRDxK5+kn9OURINhBEBc7M4O1KrmM= | ||
github.com/fyne-io/glfw-js v0.2.0/go.mod h1:Ri6te7rdZtBgBpxLW19uBpp3Dl6K9K/bRaYdJ22G8Jk= | ||
github.com/fyne-io/image v0.1.1 h1:WH0z4H7qfvNUw5l4p3bC1q70sa5+YWVt6HCj7y4VNyA= | ||
github.com/fyne-io/image v0.1.1/go.mod h1:xrfYBh6yspc+KjkgdZU/ifUC9sPA5Iv7WYUBzQKK7JM= | ||
github.com/fyne-io/oksvg v0.1.0 h1:7EUKk3HV3Y2E+qypp3nWqMXD7mum0hCw2KEGhI1fnBw= | ||
github.com/fyne-io/oksvg v0.1.0/go.mod h1:dJ9oEkPiWhnTFNCmRgEze+YNprJF7YRbpjgpWS4kzoI= | ||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA= | ||
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= | ||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= | ||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= | ||
github.com/go-text/render v0.2.0 h1:LBYoTmp5jYiJ4NPqDc2pz17MLmA3wHw1dZSVGcOdeAc= | ||
github.com/go-text/render v0.2.0/go.mod h1:CkiqfukRGKJA5vZZISkjSYrcdtgKQWRa2HIzvwNN5SU= | ||
github.com/go-text/typesetting v0.2.1 h1:x0jMOGyO3d1qFAPI0j4GSsh7M0Q3Ypjzr4+CEVg82V8= | ||
github.com/go-text/typesetting v0.2.1/go.mod h1:mTOxEwasOFpAMBjEQDhdWRckoLLeI/+qrQeBCTGEt6M= | ||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0= | ||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= | ||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= | ||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= | ||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= | ||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= | ||
github.com/hack-pad/go-indexeddb v0.3.2 h1:DTqeJJYc1usa45Q5r52t01KhvlSN02+Oq+tQbSBI91A= | ||
github.com/hack-pad/go-indexeddb v0.3.2/go.mod h1:QvfTevpDVlkfomY498LhstjwbPW6QC4VC/lxYb0Kom0= | ||
github.com/hack-pad/safejs v0.1.0 h1:qPS6vjreAqh2amUqj4WNG1zIw7qlRQJ9K10eDKMCnE8= | ||
github.com/hack-pad/safejs v0.1.0/go.mod h1:HdS+bKF1NrE72VoXZeWzxFOVQVUSqZJAG0xNCnb+Tio= | ||
github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08 h1:wMeVzrPO3mfHIWLZtDcSaGAe2I4PW9B/P5nMkRSwCAc= | ||
github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08/go.mod h1:ZDXo8KHryOWSIqnsb/CiDq7hQUYryCgdVnxbj8tDG7o= | ||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M= | ||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw= | ||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= | ||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= | ||
github.com/nicksnyder/go-i18n/v2 v2.5.1 h1:IxtPxYsR9Gp60cGXjfuR/llTqV8aYMsC472zD0D1vHk= | ||
github.com/nicksnyder/go-i18n/v2 v2.5.1/go.mod h1:DrhgsSDZxoAfvVrBVLXoxZn/pN5TXqaDbq7ju94viiQ= | ||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= | ||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= | ||
github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= | ||
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/rymdport/portal v0.4.1 h1:2dnZhjf5uEaeDjeF/yBIeeRo6pNI2QAKm7kq1w/kbnA= | ||
github.com/rymdport/portal v0.4.1/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4= | ||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE= | ||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= | ||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ= | ||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= | ||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic= | ||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= | ||
golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ= | ||
golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8= | ||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= | ||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= | ||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= | ||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= | ||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= | ||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
// Package chainregistry provides functionality to parse and work with Cosmos chain registry data | ||
package chainregistry | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// Chain represents the chain.json data structure | ||
type Chain struct { | ||
ChainName string `json:"chain_name"` | ||
Status string `json:"status"` | ||
NetworkType string `json:"network_type"` | ||
PrettyName string `json:"pretty_name"` | ||
ChainID string `json:"chain_id"` | ||
Bech32Prefix string `json:"bech32_prefix"` | ||
DaemonName string `json:"daemon_name"` | ||
NodeHome string `json:"node_home"` | ||
Codebase Codebase `json:"codebase"` | ||
Peers Peers `json:"peers"` | ||
APIs APIs `json:"apis"` | ||
Images []ChainImage `json:"images"` | ||
LogoURIs LogoURIs `json:"logo_URIs"` | ||
Description string `json:"description,omitempty"` | ||
} | ||
|
||
// Codebase represents the codebase section of the chain.json file | ||
type Codebase struct { | ||
GitRepo string `json:"git_repo"` | ||
RecommendedVersion string `json:"recommended_version"` | ||
CompatibleVersions []string `json:"compatible_versions"` | ||
Consensus CodebaseConsensus `json:"consensus,omitempty"` | ||
Cosmwasm *CodebaseCosmwasm `json:"cosmwasm,omitempty"` | ||
Binaries Binaries `json:"binaries,omitempty"` | ||
} | ||
|
||
// CodebaseConsensus represents the consensus section of the codebase | ||
type CodebaseConsensus struct { | ||
Type string `json:"type"` | ||
Version string `json:"version"` | ||
} | ||
|
||
// CodebaseCosmwasm represents the cosmwasm section of the codebase | ||
type CodebaseCosmwasm struct { | ||
Enabled bool `json:"enabled"` | ||
} | ||
|
||
// Binaries represents the binaries section of the codebase | ||
type Binaries struct { | ||
LinuxAmd64 string `json:"linux/amd64,omitempty"` | ||
LinuxArm64 string `json:"linux/arm64,omitempty"` | ||
DarwinAmd64 string `json:"darwin/amd64,omitempty"` | ||
DarwinArm64 string `json:"darwin/arm64,omitempty"` | ||
} | ||
|
||
// Peers represents the peers section of the chain.json file | ||
type Peers struct { | ||
Seeds []Peer `json:"seeds"` | ||
PersistentPeers []Peer `json:"persistent_peers"` | ||
} | ||
|
||
// Peer represents a peer endpoint | ||
type Peer struct { | ||
ID string `json:"id"` | ||
Address string `json:"address"` | ||
Provider string `json:"provider"` | ||
} | ||
|
||
// APIs represents the API endpoints for the chain | ||
type APIs struct { | ||
RPC []API `json:"rpc"` | ||
REST []API `json:"rest"` | ||
GRPC []API `json:"grpc"` | ||
} | ||
|
||
// API represents an API endpoint | ||
type API struct { | ||
Address string `json:"address"` | ||
Provider string `json:"provider"` | ||
} | ||
|
||
// ChainImage represents an image for the chain | ||
type ChainImage struct { | ||
PNG string `json:"png,omitempty"` | ||
SVG string `json:"svg,omitempty"` | ||
Theme ImageTheme `json:"theme,omitempty"` | ||
} | ||
|
||
// ImageTheme represents the theme for an image | ||
type ImageTheme struct { | ||
PrimaryColorHex string `json:"primary_color_hex"` | ||
} | ||
|
||
// LogoURIs represents logo URIs for the chain | ||
type LogoURIs struct { | ||
PNG string `json:"png,omitempty"` | ||
SVG string `json:"svg,omitempty"` | ||
} | ||
|
||
// Registry represents the chain registry | ||
type Registry struct { | ||
Chains map[string]*Chain | ||
} | ||
|
||
// NewRegistry creates a new instance of the chain registry | ||
func NewRegistry(registryPath string) (*Registry, error) { | ||
registry := &Registry{ | ||
Chains: make(map[string]*Chain), | ||
} | ||
|
||
// Walk through the registry path to find all chain.json files | ||
err := filepath.Walk(registryPath, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Skip directories and non-chain.json files | ||
if info.IsDir() || info.Name() != "chain.json" { | ||
return nil | ||
} | ||
|
||
// Skip test networks | ||
if filepath.Base(filepath.Dir(filepath.Dir(path))) == "testnets" { | ||
return nil | ||
} | ||
|
||
// Read and parse the chain.json file | ||
chain, err := parseChainJSON(path) | ||
if err != nil { | ||
fmt.Printf("Warning: Failed to parse chain.json at %s: %v\n", path, err) | ||
return nil | ||
} | ||
|
||
// Add the chain to the registry | ||
registry.Chains[chain.ChainName] = chain | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to walk registry path: %w", err) | ||
} | ||
|
||
return registry, nil | ||
} | ||
|
||
// parseChainJSON parses a chain.json file into a Chain struct | ||
func parseChainJSON(path string) (*Chain, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read chain.json: %w", err) | ||
} | ||
|
||
var chain Chain | ||
if err := json.Unmarshal(data, &chain); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal chain.json: %w", err) | ||
} | ||
|
||
return &chain, nil | ||
} | ||
|
||
// GetChain returns a chain by name | ||
func (r *Registry) GetChain(name string) (*Chain, bool) { | ||
chain, ok := r.Chains[name] | ||
return chain, ok | ||
} | ||
|
||
// GetLiveChains returns all chains with status "live" | ||
func (r *Registry) GetLiveChains() []*Chain { | ||
var chains []*Chain | ||
for _, chain := range r.Chains { | ||
if chain.Status == "live" && chain.NetworkType == "mainnet" { | ||
chains = append(chains, chain) | ||
} | ||
} | ||
return chains | ||
} | ||
|
||
// GetPrettyNames returns all chain pretty names | ||
func (r *Registry) GetPrettyNames() []string { | ||
var names []string | ||
for _, chain := range r.GetLiveChains() { | ||
names = append(names, chain.PrettyName) | ||
} | ||
return names | ||
} | ||
|
||
// GetChainByPrettyName returns a chain by its pretty name | ||
func (r *Registry) GetChainByPrettyName(prettyName string) (*Chain, bool) { | ||
for _, chain := range r.Chains { | ||
if chain.PrettyName == prettyName { | ||
return chain, true | ||
} | ||
} | ||
return nil, false | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi, there also exists "circle" boolean and "background_color_hex"