-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcosmwasm.go
195 lines (162 loc) · 4.82 KB
/
cosmwasm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package client
import (
"airchains/utils"
"airchains/utils/cosmwasm"
"fmt"
"os"
"strings"
"github.com/manifoldco/promptui"
)
func CosmWasmInitialiazation() {
data := map[string]interface{}{
"chainInfo": CosmWasmChainInfo(),
"daInfo": cosmwasmDAType(),
"sequencerInfo": cosmwasmSequencerType(),
}
utils.CreateFolderAndJSONFile(data, "config", "config.json")
daType := data["daInfo"].(map[string]interface{})["daSelected"].(string)
daTypetoLower := strings.ToLower(daType)
daTypeSend := "http://localhost:5050/" + daTypetoLower
fmt.Println(daTypeSend)
utils.ENVSetup("cosmwasm-sequencer-node", "26657", daTypetoLower)
}
func CosmWasmChainInfo() map[string]interface{} {
var chainInfoKeyValue map[string]interface{}
// First question
validate1 := func(input string) error {
trimmedInput := strings.TrimSpace(input)
if len(trimmedInput) == 0 {
return fmt.Errorf("input cannot be empty")
}
if len(trimmedInput) < 3 {
return fmt.Errorf("input must be at least 3 characters")
}
if trimmedInput == "dummyname" {
return fmt.Errorf("please provide a custom account name other than dummyname")
}
return nil
}
prompt1 := promptui.Prompt{
Label: fmt.Sprintf("What do you want your account name to be? (e.g., %s)", "dummyname"),
Validate: validate1,
}
accountName, err := prompt1.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
os.Exit(1)
}
// Second question
validate2 := func(input string) error {
trimmedInput := strings.TrimSpace(input)
if len(trimmedInput) == 0 {
return fmt.Errorf("input cannot be empty")
}
if len(trimmedInput) < 3 {
return fmt.Errorf("input must be at least 3 characters")
}
if trimmedInput == "dummyname" {
return fmt.Errorf("please provide a custom account name other than dummyname")
}
return nil
}
prompt2 := promptui.Prompt{
Label: fmt.Sprintf("What is the chain ID of your chain? (e.g., %s)", "aircosmic_5501-1107"),
Validate: validate2,
}
chainID, err := prompt2.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
os.Exit(1)
}
// Third question
validate3 := func(input string) error {
trimmedInput := strings.TrimSpace(input)
if len(trimmedInput) == 0 {
return fmt.Errorf("input cannot be empty")
}
if len(trimmedInput) < 3 {
return fmt.Errorf("input must be at least 3 characters")
}
if trimmedInput == "My Chain" {
return fmt.Errorf("please provide a custom account name other than dummyname")
}
return nil
}
prompt3 := promptui.Prompt{
Label: fmt.Sprintf("What do you want the name of your chain? (e.g., %s)", "dummyname"),
Validate: validate3,
}
chainName, err := prompt3.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
os.Exit(1)
}
chainInfoKeyValue = map[string]interface{}{
"key": accountName,
"chainID": chainID,
"moniker": chainName,
}
utils.DelayLoader()
return chainInfoKeyValue
}
func cosmwasmDAType() map[string]interface{} {
var chainInfoKeyValue map[string]interface{}
prompt := promptui.Select{
Label: "Select your DA type : ",
Items: []string{"Celestia", "Avail", "Eigen Layer"},
Templates: &promptui.SelectTemplates{
Label: "{{ . | cyan }}",
Active: "\U000025B6 {{ if eq . \"Eigen Layer\" }}{{ . | red | cyan }} (Coming Soon){{ else }}{{ . | green }}{{ end }}",
Inactive: " {{ . | black }}",
Selected: "\U000025B6 {{ . | cyan | cyan }}",
},
}
_, daTech, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return evmDAType()
}
if daTech == "Eigen Layer" {
fmt.Printf("Eigen Layer is coming soon. Please select other DAs for now\n")
evmDAType()
} else {
fmt.Printf("You selected %s\n", daTech)
utils.DaRPC()
utils.SettlementRPC()
}
chainInfoKeyValue = map[string]interface{}{
"daSelected": daTech,
}
utils.DelayLoader()
return chainInfoKeyValue
}
func cosmwasmSequencerType() map[string]interface{} {
var sequencerKeyValue map[string]interface{}
prompt := promptui.Select{
Label: "Select your sequencer type : ",
Items: []string{"Air Sequencer", "Espresso Sequencer"},
Templates: &promptui.SelectTemplates{
Label: "{{ . | cyan }}",
Active: "\U000025B6 {{ if eq . \"Espresso Sequencer\" }}{{ . | red | cyan }} (Coming Soon){{ else }}{{ . | green }}{{ end }}",
Inactive: " {{ . | black }}",
Selected: "\U000025B6 {{ . | cyan | cyan }}",
},
}
_, sequencerValue, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
evmSequencerType()
}
if sequencerValue == "Espresso Sequencer" {
fmt.Printf("Espresso Sequencer is coming soon. Only air sequencer is available for now\n")
evmSequencerType()
} else {
fmt.Printf("You selected %s\n", sequencerValue)
cosmwasm.CosmwasmSequencerClone()
}
sequencerKeyValue = map[string]interface{}{
"sequencerType": sequencerValue,
}
utils.DelayLoader()
return sequencerKeyValue
}