Skip to content

Commit

Permalink
fix: block and snapshot pool id
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Dec 9, 2024
1 parent 5bf09f2 commit 2629bd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewCosmosApp() (*CosmosApp, error) {

app.Genesis = appGenesis

appSource, err := source.NewSource(app.Genesis.GetChainId(), flags.ChainId)
appSource, err := source.NewSource(app.Genesis.GetChainId())
if err != nil {
return nil, fmt.Errorf("failed to init source: %w", err)
}
Expand Down
31 changes: 12 additions & 19 deletions app/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package source

import (
"fmt"
"github.com/KYVENetwork/ksync/flags"
"github.com/KYVENetwork/ksync/types"
"github.com/KYVENetwork/ksync/utils"
"gopkg.in/yaml.v2"
Expand All @@ -11,16 +12,13 @@ import (
)

type Source struct {
sourceId string
chainId string
registryUrl string
blockPoolId string
snapshotPoolId string
sourceId string
registryUrl string

sourceRegistry types.SourceRegistry
}

func NewSource(sourceId, chainId string) (*Source, error) {
func NewSource(sourceId string) (*Source, error) {
response, err := http.Get(utils.DefaultRegistryURL)
if err != nil {
return nil, err
Expand All @@ -44,47 +42,42 @@ func NewSource(sourceId, chainId string) (*Source, error) {

return &Source{
sourceId: sourceId,
chainId: chainId,
sourceRegistry: sourceRegistry,
}, nil
}

func (source *Source) GetRegistryUrl() string {
return source.registryUrl
}

func (source *Source) GetSourceBlockPoolId() (int64, error) {
if source.blockPoolId != "" {
return strconv.ParseInt(source.blockPoolId, 10, 64)
if flags.BlockPoolId != "" {
return strconv.ParseInt(flags.BlockPoolId, 10, 64)
}

entry, found := source.sourceRegistry.Entries[source.sourceId]
if !found {
return 0, fmt.Errorf("source with id \"%s\" not found in registry", source.sourceId)
}

if source.chainId == utils.ChainIdMainnet {
if flags.ChainId == utils.ChainIdMainnet {
return int64(*entry.Networks.Kyve.Integrations.KSYNC.BlockSyncPool), nil
} else if source.chainId == utils.ChainIdKaon {
} else if flags.ChainId == utils.ChainIdKaon {
return int64(*entry.Networks.Kaon.Integrations.KSYNC.BlockSyncPool), nil
}

return 0, fmt.Errorf("failed to get block pool id from registry entry")
}

func (source *Source) GetSourceSnapshotPoolId() (int64, error) {
if source.snapshotPoolId != "" {
return strconv.ParseInt(source.snapshotPoolId, 10, 64)
if flags.SnapshotPoolId != "" {
return strconv.ParseInt(flags.SnapshotPoolId, 10, 64)
}

entry, found := source.sourceRegistry.Entries[source.sourceId]
if !found {
return 0, fmt.Errorf("source with id \"%s\" not found in registry", source.sourceId)
}

if source.chainId == utils.ChainIdMainnet {
if flags.ChainId == utils.ChainIdMainnet {
return int64(*entry.Networks.Kyve.Integrations.KSYNC.StateSyncPool), nil
} else if source.chainId == utils.ChainIdKaon {
} else if flags.ChainId == utils.ChainIdKaon {
return int64(*entry.Networks.Kaon.Integrations.KSYNC.StateSyncPool), nil
}

Expand Down

0 comments on commit 2629bd6

Please sign in to comment.