Skip to content

Commit

Permalink
fix: import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Jul 30, 2024
1 parent 3a40a02 commit 5b01140
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
7 changes: 5 additions & 2 deletions app/e2e_include_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

package app

import "github.com/babylonlabs-io/babylon/app/upgrades/vanilla"
import (
"github.com/babylonlabs-io/babylon/app/upgrades/launchsignet"
"github.com/babylonlabs-io/babylon/app/upgrades/vanilla"
)

func init() {
Upgrades = append(Upgrades, vanilla.Upgrade)
Upgrades = append(Upgrades, vanilla.Upgrade, launchsignet.Upgrade)
}
3 changes: 1 addition & 2 deletions app/upgrades/launchsignet/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/babylonlabs-io/babylon/app/keepers"
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/app/upgrades"
"github.com/babylonlabs-io/babylon/cmd/babylond/cmd/genhelpers"
btclightkeeper "github.com/babylonlabs-io/babylon/x/btclightclient/keeper"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
)
Expand Down Expand Up @@ -68,7 +67,7 @@ func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) {
}

btcHeadersFilePath := filepath.Join(pwd, "data/btc_headers.json")
gs, err := genhelpers.LoadBtcLightGenStateFromFile(appparams.DefaultEncodingConfig().Codec, btcHeadersFilePath)
gs, err := btclighttypes.LoadBtcLightGenStateFromFile(appparams.DefaultEncodingConfig().Codec, btcHeadersFilePath)
if err != nil {
return nil, err
}
Expand Down
26 changes: 1 addition & 25 deletions cmd/babylond/cmd/genhelpers/set_btc_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package genhelpers

import (
"fmt"
"os"
"path/filepath"

cmtos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
Expand Down Expand Up @@ -51,7 +47,7 @@ Possible content of 'btc_headers.json' is
config := server.GetServerContextFromCmd(cmd).Config
config.SetRoot(clientCtx.HomeDir)

inputBtcHeaders, err := LoadBtcLightGenStateFromFile(clientCtx.Codec, args[0])
inputBtcHeaders, err := btclighttypes.LoadBtcLightGenStateFromFile(clientCtx.Codec, args[0])
if err != nil {
return err
}
Expand Down Expand Up @@ -102,23 +98,3 @@ Possible content of 'btc_headers.json' is

return cmd
}

func LoadBtcLightGenStateFromFile(cdc codec.Codec, inputFilePath string) (*btclighttypes.GenesisState, error) {
filePath := filepath.Clean(inputFilePath)
if !cmtos.FileExists(filePath) {
return nil, fmt.Errorf("input file %s does not exists", filePath)
}

bz, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}

var genState btclighttypes.GenesisState
err = cdc.UnmarshalJSON(bz, &genState)
if err != nil {
return nil, err
}

return &genState, nil
}
18 changes: 18 additions & 0 deletions x/btclightclient/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"

bbn "github.com/babylonlabs-io/babylon/types"
"github.com/btcsuite/btcd/chaincfg"
Expand Down Expand Up @@ -86,3 +88,19 @@ func GenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMessa

return genesisState
}

func LoadBtcLightGenStateFromFile(cdc codec.Codec, inputFilePath string) (*GenesisState, error) {
filePath := filepath.Clean(inputFilePath)
bz, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}

var genState GenesisState
err = cdc.UnmarshalJSON(bz, &genState)
if err != nil {
return nil, err
}

return &genState, nil
}

0 comments on commit 5b01140

Please sign in to comment.