Skip to content

Commit

Permalink
update: support latest Source-Registry. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherbrumm authored Dec 27, 2023
1 parent 99cbe04 commit 4f0141d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 50 deletions.
21 changes: 17 additions & 4 deletions cmd/ksync/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var infoCmd = &cobra.Command{
// Sort SourceRegistry
sortFunc := func(keys []string) {
sort.Slice(keys, func(i, j int) bool {
return sourceRegistry.Entries[keys[i]].Source.ChainID < sourceRegistry.Entries[keys[j]].Source.ChainID
return sourceRegistry.Entries[keys[i]].SourceID < sourceRegistry.Entries[keys[j]].SourceID
})
}
keys := make([]string, 0, len(sourceRegistry.Entries))
Expand All @@ -59,19 +59,32 @@ var infoCmd = &cobra.Command{
for _, key := range keys {
entry := sourceRegistry.Entries[key]

var title string

if chainId == utils.ChainIdMainnet {
if (entry.Kyve.StatePoolID == nil) && (entry.Kyve.BlockPoolID == nil) {
if entry.Networks.Kyve != nil {
if entry.Networks.Kyve.Integrations.KSYNC == nil {
continue
}
title = entry.Networks.Kyve.SourceMetadata.Title
} else {
continue
}
} else if chainId == utils.ChainIdKaon {
if (entry.Kaon.StatePoolID == nil) && (entry.Kaon.BlockPoolID == nil) {
if entry.Networks.Kaon != nil {
if entry.Networks.Kaon.Integrations.KSYNC == nil {
continue
}
title = entry.Networks.Kaon.SourceMetadata.Title
} else {
continue
}
}

blockSync, stateSync, heightSync := sources.FormatOutput(&entry, chainId)
t.AppendRows([]table.Row{
{
entry.Source.Title,
title,
blockSync,
stateSync,
heightSync,
Expand Down
56 changes: 30 additions & 26 deletions sources/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,41 @@ const (

func LoadLatestPoolData(sourceRegistry types.SourceRegistry) (*types.SourceRegistry, error) {
for _, entry := range sourceRegistry.Entries {
if entry.Kyve.BlockPoolID != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointMainnet, int64(*entry.Kyve.BlockPoolID))
if err != nil {
return nil, err
if entry.Networks.Kyve != nil {
if entry.Networks.Kyve.Integrations.KSYNC.BlockSyncPool != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointMainnet, int64(*entry.Networks.Kyve.Integrations.KSYNC.BlockSyncPool))
if err != nil {
return nil, err
}
entry.Networks.Kyve.BlockStartKey = &poolResponse.Pool.Data.StartKey
entry.Networks.Kyve.LatestBlockKey = &poolResponse.Pool.Data.CurrentKey
}
entry.Kyve.BlockStartKey = &poolResponse.Pool.Data.StartKey
entry.Kyve.LatestBlockKey = &poolResponse.Pool.Data.CurrentKey
}
if entry.Kyve.StatePoolID != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointMainnet, int64(*entry.Kyve.StatePoolID))
if err != nil {
return nil, err
if entry.Networks.Kyve.Integrations.KSYNC.StateSyncPool != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointMainnet, int64(*entry.Networks.Kyve.Integrations.KSYNC.StateSyncPool))
if err != nil {
return nil, err
}
entry.Networks.Kyve.StateStartKey = &poolResponse.Pool.Data.StartKey
entry.Networks.Kyve.LatestStateKey = &poolResponse.Pool.Data.CurrentKey
}
entry.Kyve.StateStartKey = &poolResponse.Pool.Data.StartKey
entry.Kyve.LatestStateKey = &poolResponse.Pool.Data.CurrentKey
}
if entry.Kaon.BlockPoolID != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointKaon, int64(*entry.Kaon.BlockPoolID))
if err != nil {
return nil, err
if entry.Networks.Kaon != nil {
if entry.Networks.Kaon.Integrations.KSYNC.BlockSyncPool != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointKaon, int64(*entry.Networks.Kaon.Integrations.KSYNC.BlockSyncPool))
if err != nil {
return nil, err
}
entry.Networks.Kaon.BlockStartKey = &poolResponse.Pool.Data.StartKey
entry.Networks.Kaon.LatestBlockKey = &poolResponse.Pool.Data.CurrentKey
}
entry.Kaon.BlockStartKey = &poolResponse.Pool.Data.StartKey
entry.Kaon.LatestBlockKey = &poolResponse.Pool.Data.CurrentKey
}
if entry.Kaon.StatePoolID != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointKaon, int64(*entry.Kaon.StatePoolID))
if err != nil {
return nil, err
if entry.Networks.Kaon.Integrations.KSYNC.StateSyncPool != nil {
poolResponse, err := pool.GetPoolInfo(utils.RestEndpointKaon, int64(*entry.Networks.Kaon.Integrations.KSYNC.StateSyncPool))
if err != nil {
return nil, err
}
entry.Networks.Kaon.StateStartKey = &poolResponse.Pool.Data.StartKey
entry.Networks.Kaon.LatestStateKey = &poolResponse.Pool.Data.CurrentKey
}
entry.Kaon.StateStartKey = &poolResponse.Pool.Data.StartKey
entry.Kaon.LatestStateKey = &poolResponse.Pool.Data.CurrentKey
}
}
return &sourceRegistry, nil
Expand Down
16 changes: 8 additions & 8 deletions sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

func FormatOutput(entry *types.Entry, chainId string) (string, string, string) {
var blockKey, stateKey, heightKey string
if chainId == utils.ChainIdMainnet {
blockKey, stateKey, heightKey = helpers.FormatKeys(entry.Kyve.BlockStartKey, entry.Kyve.LatestBlockKey, entry.Kyve.StateStartKey, entry.Kyve.LatestStateKey)
} else if chainId == utils.ChainIdKaon {
blockKey, stateKey, heightKey = helpers.FormatKeys(entry.Kaon.BlockStartKey, entry.Kaon.LatestBlockKey, entry.Kaon.StateStartKey, entry.Kaon.LatestStateKey)
if chainId == utils.ChainIdMainnet && entry.Networks.Kyve != nil {
blockKey, stateKey, heightKey = helpers.FormatKeys(entry.Networks.Kyve.BlockStartKey, entry.Networks.Kyve.LatestBlockKey, entry.Networks.Kyve.StateStartKey, entry.Networks.Kyve.LatestStateKey)
} else if chainId == utils.ChainIdKaon && entry.Networks.Kaon != nil {
blockKey, stateKey, heightKey = helpers.FormatKeys(entry.Networks.Kaon.BlockStartKey, entry.Networks.Kaon.LatestBlockKey, entry.Networks.Kaon.StateStartKey, entry.Networks.Kaon.LatestStateKey)
}
return blockKey, stateKey, heightKey
}
Expand Down Expand Up @@ -77,12 +77,12 @@ func getPoolsBySource(chainId, source, registryUrl string) (*int, *int, error) {
}

for _, entry := range sourceRegistry.Entries {
if strings.ToLower(entry.Source.Title) == strings.ToLower(source) ||
strings.ToLower(entry.Source.ChainID) == strings.ToLower(source) {
if strings.ToLower(entry.Networks.Kyve.SourceMetadata.Title) == strings.ToLower(source) ||
strings.ToLower(entry.SourceID) == strings.ToLower(source) {
if chainId == utils.ChainIdMainnet {
return entry.Kyve.BlockPoolID, entry.Kyve.StatePoolID, nil
return entry.Networks.Kyve.Integrations.KSYNC.BlockSyncPool, entry.Networks.Kyve.Integrations.KSYNC.StateSyncPool, nil
} else if chainId == utils.ChainIdKaon {
return entry.Kaon.BlockPoolID, entry.Kaon.StatePoolID, nil
return entry.Networks.Kaon.Integrations.KSYNC.BlockSyncPool, entry.Networks.Kaon.Integrations.KSYNC.StateSyncPool, nil
}
}
}
Expand Down
39 changes: 28 additions & 11 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,45 @@ type Metrics struct {
CatchingUp bool `json:"catching_up"`
}

type SourceMetadata struct {
ChainID string `yaml:"chain_id"`
Hex string `yaml:"hex"`
Title string `yaml:"title"`
type Networks struct {
Kaon *NetworkProperties `yaml:"kaon-1,omitempty"`
Kyve *NetworkProperties `yaml:"kyve-1,omitempty"`
}

type KYVEInfo struct {
BlockPoolID *int `yaml:"block_pool_id,omitempty"`
StatePoolID *int `yaml:"state_pool_id,omitempty"`
type NetworkProperties struct {
LatestBlockKey *string
LatestStateKey *string
BlockStartKey *string
StateStartKey *string
Integrations *Integrations `yaml:"integrations,omitempty"`
Pools *[]Pool `yaml:"pools,omitempty"`
SourceMetadata *SourceMetadata `yaml:"properties,omitempty"`
}

type Integrations struct {
KSYNC *KSYNCIntegration `yaml:"ksync,omitempty"`
}

type KSYNCIntegration struct {
BlockSyncPool *int `yaml:"block-sync-pool"`
StateSyncPool *int `yaml:"state-sync-pool"`
}

type SourceMetadata struct {
Title string `yaml:"title"`
}

type Pool struct {
Id *int `yaml:"id"`
Runtime string `yaml:"runtime"`
}

type Entry struct {
Source SourceMetadata `yaml:"source"`
Kaon *KYVEInfo `yaml:"kaon-1,omitempty"`
Kyve *KYVEInfo `yaml:"kyve-1,omitempty"`
ConfigVersion *int `yaml:"config-version"`
Networks Networks `yaml:"networks"`
SourceID string `yaml:"source-id"`
}

type SourceRegistry struct {
Entries map[string]Entry `yaml:",inline"`
Version string `yaml:"version"`
}
2 changes: 1 addition & 1 deletion utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ const (
)

const (
DefaultRegistryURL = "https://github.com/KYVENetwork/source-registry/releases/latest/download/registry.yml"
DefaultRegistryURL = "https://raw.githubusercontent.com/KYVENetwork/source-registry/main/.github/registry.yml"
)

0 comments on commit 4f0141d

Please sign in to comment.