Skip to content

Commit 5a07340

Browse files
committed
fix conflicts
2 parents cf01890 + a8c3973 commit 5a07340

File tree

6 files changed

+184
-405
lines changed

6 files changed

+184
-405
lines changed

ignite/cmd/network_chain_join.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ignitecmd
33
import (
44
"context"
55
"fmt"
6+
"os"
67

78
sdk "github.com/cosmos/cosmos-sdk/types"
89
"github.com/pkg/errors"
@@ -48,6 +49,7 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
4849
defer session.Cleanup()
4950

5051
var (
52+
joinOptions []network.JoinOption
5153
gentxPath, _ = cmd.Flags().GetString(flagGentx)
5254
amount, _ = cmd.Flags().GetString(flagAmount)
5355
)
@@ -63,10 +65,6 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
6365
return err
6466
}
6567

66-
joinOptions := []network.JoinOption{
67-
network.WithCustomGentxPath(gentxPath),
68-
}
69-
7068
// if there is no custom gentx, we need to detect the public address.
7169
if gentxPath == "" {
7270
// get the peer public address for the validator.
@@ -78,6 +76,11 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
7876
joinOptions = append(joinOptions, network.WithPublicAddress(publicAddr))
7977
}
8078

79+
cacheStorage, err := newCache(cmd)
80+
if err != nil {
81+
return err
82+
}
83+
8184
n, err := nb.Network()
8285
if err != nil {
8386
return err
@@ -93,6 +96,28 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
9396
return err
9497
}
9598

99+
// use the default gentx path from chain home if not provided
100+
if gentxPath == "" {
101+
gentxPath, err = c.DefaultGentxPath()
102+
if err != nil {
103+
return err
104+
}
105+
}
106+
107+
// create a temporary directory for the chain home and genesis
108+
// create the chain in a temp dir
109+
tmpHome, err := os.MkdirTemp("", "*-spn")
110+
if err != nil {
111+
return err
112+
}
113+
defer os.RemoveAll(tmpHome)
114+
c.SetHome(tmpHome)
115+
116+
// initialize the genesis under a temporary repository
117+
if err := c.Init(cmd.Context(), cacheStorage); err != nil {
118+
return err
119+
}
120+
96121
if amount != "" {
97122
// parse the amount.
98123
amountCoins, err := sdk.ParseCoinsNormalized(amount)
@@ -111,11 +136,11 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
111136
}
112137
}
113138

114-
session.Printf("%s %s\n", icons.Info, "Account request won't be submitted")
139+
_ = session.Printf("%s %s\n", icons.Info, "Account request won't be submitted")
115140
}
116141

117142
// create the message to add the validator.
118-
return n.Join(cmd.Context(), c, launchID, joinOptions...)
143+
return n.Join(cmd.Context(), c, launchID, gentxPath, joinOptions...)
119144
}
120145

121146
// askPublicAddress prepare questions to interactively ask for a publicAddress

ignite/cmd/network_chain_prepare.go

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66

77
"github.com/spf13/cobra"
88

9+
"github.com/ignite/cli/ignite/pkg/cache"
910
"github.com/ignite/cli/ignite/pkg/cliui"
1011
"github.com/ignite/cli/ignite/pkg/cliui/colors"
1112
"github.com/ignite/cli/ignite/pkg/cliui/icons"
1213
"github.com/ignite/cli/ignite/pkg/goenv"
1314
"github.com/ignite/cli/ignite/services/network"
1415
"github.com/ignite/cli/ignite/services/network/networkchain"
16+
"github.com/ignite/cli/ignite/services/network/networktypes"
1517
)
1618

1719
const (
@@ -78,34 +80,13 @@ func networkChainPrepareHandler(cmd *cobra.Command, args []string) error {
7880
return err
7981
}
8082

81-
// fetch the information to construct genesis
82-
genesisInformation, err := n.GenesisInformation(cmd.Context(), launchID)
83-
if err != nil {
84-
return err
85-
}
86-
87-
rewardsInfo, lastBlockHeight, unboundingTime, err := n.RewardsInfo(
88-
cmd.Context(),
89-
launchID,
90-
chainLaunch.ConsumerRevisionHeight,
91-
)
92-
if err != nil {
93-
return err
94-
}
95-
96-
spnChainID, err := n.ChainID(cmd.Context())
97-
if err != nil {
98-
return err
99-
}
100-
101-
if err := c.Prepare(
102-
cmd.Context(),
83+
if err := prepareFromGenesisInformation(
84+
cmd,
10385
cacheStorage,
104-
genesisInformation,
105-
rewardsInfo,
106-
spnChainID,
107-
lastBlockHeight,
108-
unboundingTime,
86+
launchID,
87+
n,
88+
c,
89+
chainLaunch,
10990
); err != nil {
11091
return err
11192
}
@@ -128,3 +109,52 @@ func networkChainPrepareHandler(cmd *cobra.Command, args []string) error {
128109

129110
return nil
130111
}
112+
113+
// prepareFromGenesisInformation prepares the genesis of the chain from the queried genesis information from the launch ID of the chain
114+
func prepareFromGenesisInformation(
115+
cmd *cobra.Command,
116+
cacheStorage cache.Storage,
117+
launchID uint64,
118+
n network.Network,
119+
c *networkchain.Chain,
120+
chainLaunch networktypes.ChainLaunch,
121+
) error {
122+
var (
123+
rewardsInfo networktypes.Reward
124+
lastBlockHeight int64
125+
consumerUnbondingTime int64
126+
)
127+
128+
// fetch the information to construct genesis
129+
genesisInformation, err := n.GenesisInformation(cmd.Context(), launchID)
130+
if err != nil {
131+
return err
132+
}
133+
134+
// fetch the info for rewards if the consumer revision height is defined
135+
if chainLaunch.ConsumerRevisionHeight > 0 {
136+
rewardsInfo, lastBlockHeight, consumerUnbondingTime, err = n.RewardsInfo(
137+
cmd.Context(),
138+
launchID,
139+
chainLaunch.ConsumerRevisionHeight,
140+
)
141+
if err != nil {
142+
return err
143+
}
144+
}
145+
146+
spnChainID, err := n.ChainID(cmd.Context())
147+
if err != nil {
148+
return err
149+
}
150+
151+
return c.Prepare(
152+
cmd.Context(),
153+
cacheStorage,
154+
genesisInformation,
155+
rewardsInfo,
156+
spnChainID,
157+
lastBlockHeight,
158+
consumerUnbondingTime,
159+
)
160+
}

ignite/cmd/network_chain_show_genesis.go

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,59 +55,30 @@ func networkChainShowGenesisHandler(cmd *cobra.Command, args []string) error {
5555
return err
5656
}
5757

58-
genesisPath, err := c.GenesisPath()
58+
// generate the genesis in a temp dir
59+
tmpHome, err := os.MkdirTemp("", "*-spn")
5960
if err != nil {
6061
return err
6162
}
62-
63-
spnChainID, err := n.ChainID(cmd.Context())
64-
if err != nil {
63+
defer os.RemoveAll(tmpHome)
64+
65+
c.SetHome(tmpHome)
66+
67+
if err := prepareFromGenesisInformation(
68+
cmd,
69+
cacheStorage,
70+
launchID,
71+
n,
72+
c,
73+
chainLaunch,
74+
); err != nil {
6575
return err
6676
}
6777

68-
// check if the genesis already exists
69-
if _, err = os.Stat(genesisPath); os.IsNotExist(err) {
70-
// fetch the information to construct genesis
71-
genesisInformation, err := n.GenesisInformation(cmd.Context(), launchID)
72-
if err != nil {
73-
return err
74-
}
75-
76-
// create the chain in a temp dir
77-
tmpHome, err := os.MkdirTemp("", "*-spn")
78-
if err != nil {
79-
return err
80-
}
81-
defer os.RemoveAll(tmpHome)
82-
83-
c.SetHome(tmpHome)
84-
85-
rewardsInfo, lastBlockHeight, unboundingTime, err := n.RewardsInfo(
86-
cmd.Context(),
87-
launchID,
88-
chainLaunch.ConsumerRevisionHeight,
89-
)
90-
if err != nil {
91-
return err
92-
}
93-
94-
if err = c.Prepare(
95-
cmd.Context(),
96-
cacheStorage,
97-
genesisInformation,
98-
rewardsInfo,
99-
spnChainID,
100-
lastBlockHeight,
101-
unboundingTime,
102-
); err != nil {
103-
return err
104-
}
105-
106-
// get the new genesis path
107-
genesisPath, err = c.GenesisPath()
108-
if err != nil {
109-
return err
110-
}
78+
// get the new genesis path
79+
genesisPath, err := c.GenesisPath()
80+
if err != nil {
81+
return err
11182
}
11283

11384
if err := os.MkdirAll(filepath.Dir(out), 0744); err != nil {

0 commit comments

Comments
 (0)