@@ -693,78 +693,72 @@ func (m *InitializingAppLoading) View() string {
693
693
694
694
func initializeApp (state * RunL1NodeState ) tea.Cmd {
695
695
return func () tea.Msg {
696
- // TODO: Separate this logic depending on the network
697
696
userHome , err := os .UserHomeDir ()
698
697
if err != nil {
699
698
panic (fmt .Sprintf ("failed to get user home directory: %v" , err ))
700
699
}
700
+ weaveDataPath := filepath .Join (userHome , utils .WeaveDataDirectory )
701
+ tarballPath := filepath .Join (weaveDataPath , "initia.tar.gz" )
701
702
702
- var result map [string ]interface {}
703
- err = utils .MakeGetRequest (strings .ToLower (state .network ), "lcd" , "/cosmos/base/tendermint/v1beta1/node_info" , nil , & result )
704
- if err != nil {
705
- panic (err )
706
- }
707
-
708
- if applicationVersion , ok := result ["application_version" ].(map [string ]interface {}); ok {
709
- nodeVersion := applicationVersion ["version" ].(string )
710
-
711
- goos := runtime .GOOS
712
- goarch := runtime .GOARCH
703
+ var nodeVersion , extractedPath , binaryPath , url string
713
704
714
- url := getBinaryURL (nodeVersion , goos , goarch )
715
- if url == "" {
716
- panic ("unsupported OS or architecture" )
705
+ switch state .network {
706
+ case string (Local ):
707
+ nodeVersion = state .initiadVersion
708
+ extractedPath = filepath .Join (weaveDataPath , fmt .Sprintf ("initia@%s" , nodeVersion ))
709
+ url = state .initiadEndpoint
710
+ case string (Mainnet ), string (Testnet ):
711
+ var result map [string ]interface {}
712
+ err = utils .MakeGetRequest (strings .ToLower (state .network ), "lcd" , "/cosmos/base/tendermint/v1beta1/node_info" , nil , & result )
713
+ if err != nil {
714
+ panic (err )
717
715
}
718
716
719
- weaveDataPath := filepath .Join (userHome , utils .WeaveDataDirectory )
720
- tarballPath := filepath .Join (weaveDataPath , "initia.tar.gz" )
721
- extractedPath := filepath .Join (weaveDataPath , fmt .Sprintf ("initia@%s" , nodeVersion ))
722
- binaryPath := filepath .Join (extractedPath , "initiad" )
723
-
724
- if _ , err := os .Stat (binaryPath ); os .IsNotExist (err ) {
725
- if _ , err := os .Stat (extractedPath ); os .IsNotExist (err ) {
726
- err := os .MkdirAll (extractedPath , os .ModePerm )
727
- if err != nil {
728
- panic (fmt .Sprintf ("failed to create weave data directory: %v" , err ))
729
- }
730
- }
731
-
732
- err = utils .DownloadFile (url , tarballPath )
733
- if err != nil {
734
- panic (fmt .Sprintf ("failed to download file: %v" , err ))
735
- }
717
+ applicationVersion , ok := result ["application_version" ].(map [string ]interface {})
718
+ if ! ok {
719
+ panic ("failed to get node version" )
720
+ }
736
721
737
- err = utils .ExtractTarGz (tarballPath , extractedPath )
738
- if err != nil {
739
- panic (fmt .Sprintf ("failed to extract tarball: %v" , err ))
740
- }
722
+ nodeVersion = applicationVersion ["version" ].(string )
723
+ goos := runtime .GOOS
724
+ goarch := runtime .GOARCH
725
+ url = getBinaryURL (nodeVersion , goos , goarch )
726
+ extractedPath = filepath .Join (weaveDataPath , fmt .Sprintf ("initia@%s" , nodeVersion ))
727
+ default :
728
+ panic ("unsupported network" )
729
+ }
741
730
742
- err = os .Remove (tarballPath )
731
+ binaryPath = filepath .Join (extractedPath , "initiad" )
732
+ if _ , err := os .Stat (binaryPath ); os .IsNotExist (err ) {
733
+ if _ , err := os .Stat (extractedPath ); os .IsNotExist (err ) {
734
+ err := os .MkdirAll (extractedPath , os .ModePerm )
743
735
if err != nil {
744
- panic (fmt .Sprintf ("failed to remove tarball file : %v" , err ))
736
+ panic (fmt .Sprintf ("failed to create weave data directory : %v" , err ))
745
737
}
738
+ }
746
739
747
- err = os .Chmod (binaryPath , os .ModePerm )
748
- if err != nil {
749
- panic (fmt .Sprintf ("failed to set permissions for binary: %v" , err ))
750
- }
740
+ if err = utils .DownloadAndExtractTarGz (url , tarballPath , extractedPath ); err != nil {
741
+ panic (fmt .Sprintf ("failed to download and extract binary: %v" , err ))
751
742
}
752
743
753
- err = os .Setenv ( "DYLD_LIBRARY_PATH" , extractedPath )
744
+ err = os .Chmod ( binaryPath , os . ModePerm )
754
745
if err != nil {
755
- panic (fmt .Sprintf ("failed to set DYLD_LIBRARY_PATH : %v" , err ))
746
+ panic (fmt .Sprintf ("failed to set permissions for binary : %v" , err ))
756
747
}
748
+ }
757
749
758
- // TODO: Continue from this
759
- runCmd := exec .Command (binaryPath )
760
- if err := runCmd .Run (); err != nil {
761
- panic (fmt .Sprintf ("failed to run binary: %v" , err ))
762
- }
750
+ err = os .Setenv ("DYLD_LIBRARY_PATH" , extractedPath )
751
+ if err != nil {
752
+ panic (fmt .Sprintf ("failed to set DYLD_LIBRARY_PATH: %v" , err ))
753
+ }
763
754
764
- return utils.EndLoading {}
765
- } else {
766
- panic ("failed to get node version" )
755
+ // TODO: Continue from this
756
+ runCmd := exec .Command (binaryPath )
757
+ if err := runCmd .Run (); err != nil {
758
+ panic (fmt .Sprintf ("failed to run binary: %v" , err ))
767
759
}
760
+
761
+ return utils.EndLoading {}
768
762
}
769
763
}
770
764
0 commit comments