Skip to content

Commit

Permalink
fix: fail if the downloaded hash does not match the one registered wi…
Browse files Browse the repository at this point in the history
…th the rollapp
  • Loading branch information
artemijspavlovs committed Aug 12, 2024
1 parent ded5e48 commit 286177d
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ func Cmd() *cobra.Command {

isRollappRegistered, _ := rollapp.IsRollappRegistered(raID, hd)

// TODO: check whether the rollapp exists

if !isRollappRegistered {
pterm.Error.Printf("%s was not found as a registered rollapp", raID)
return
}

err = runInit(cmd, env, raID)
if err != nil {
fmt.Printf("failed to initialize the RollApp: %v\n", err)
return
}

genesisUrl, err := pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide a genesis file url",
).Show()
Expand All @@ -102,16 +89,41 @@ func Cmd() *cobra.Command {
return
}

hash, err := calculateSHA256(genesisPath)
if genesis.ChainID != raID {
pterm.Error.Printf(
"the genesis file ChainID (%s) does not match the rollapp ID you're trying to initialize (%s)",
genesis.ChainID,
raID,
)
return
}

downloadedGenesisHash, err := calculateSHA256(genesisPath)
if err != nil {
pterm.Error.Println("failed to calculate hash of genesis file: ", err)
}
raGenesisHash, _ := getRollappGenesisHash(raID, hd)
if downloadedGenesisHash != raGenesisHash {
pterm.Error.Println(
"the hash of the downloaded file does not match the one registered with the rollapp",
)
return
}

fmt.Println("hash of the rollapp: ", raGenesisHash)

// TODO: check whether the rollapp exists

fmt.Println(genesis.ChainID)
fmt.Println("hash of the downloaded file: ", hash)
// nolint:ineffassign
raHash, _ := getRollappGenesisHash(raID, hd)
fmt.Println("hash of the rollapp: ", raHash)
if !isRollappRegistered {
pterm.Error.Printf("%s was not found as a registered rollapp", raID)
return
}

err = runInit(cmd, env, raID)
if err != nil {
fmt.Printf("failed to initialize the RollApp: %v\n", err)
return
}
},
}
return cmd
Expand Down

0 comments on commit 286177d

Please sign in to comment.