-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
452 lines (437 loc) · 20.7 KB
/
main.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
package main
import (
"context"
"fmt"
"os"
"path"
"runtime"
"strings"
"time"
"github.com/gochain/gochain/v4/core/types"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zeus-fyi/gochain/web3/accounts"
"github.com/zeus-fyi/gochain/web3/web3_actions"
serverless_aws_automation "github.com/zeus-fyi/zeus/builds/serverless/aws_automation"
ethereum_automation_cookbook "github.com/zeus-fyi/zeus/cookbooks/ethereum/automation"
aws_aegis_auth "github.com/zeus-fyi/zeus/pkg/aegis/aws/auth"
signing_automation_ethereum "github.com/zeus-fyi/zeus/pkg/artemis/signing_automation/ethereum"
age_encryption "github.com/zeus-fyi/zeus/pkg/crypto/age"
bls_signer "github.com/zeus-fyi/zeus/pkg/crypto/bls"
aegis_random "github.com/zeus-fyi/zeus/pkg/crypto/random"
hestia_req_types "github.com/zeus-fyi/zeus/pkg/hestia/client/req_types"
filepaths "github.com/zeus-fyi/zeus/pkg/utils/file_io/lib/v0/paths"
strings_filter "github.com/zeus-fyi/zeus/pkg/utils/strings"
"k8s.io/apimachinery/pkg/util/rand"
)
func main() {
if err := Cmd.Execute(); err != nil {
log.Err(err)
}
}
var (
nodeURL string
network string
agePubKey string
agePrivKey string
mnemonic string
hdWalletPassword string
numKeysToGen, hdOffset int
keystoresPath = filepaths.Path{
DirIn: "",
DirOut: "",
}
keyGenSecrets bool
genValidatorDeposits bool
sendDeposits bool
eth1AddrPrivKey string
automateSetupOnAWS bool
mnemonicAndHDWalletSecretName = "mnemonicAndHDWallet"
ageEncryptionSecretName = "ageEncryptionKey"
externalZeusLambdaAccessKeys = "externalZeusLambdaAccessKeys"
awsRegion = "us-west-1"
awsAuth = aws_aegis_auth.AuthAWS{
AccountNumber: "",
Region: awsRegion,
AccessKey: "",
SecretKey: "",
}
feeRecipient string
bearerToken string
keyGroupName string
submitValidatorServiceReq bool
externalAwsAuth = hestia_req_types.AuthLamdbaAWS{
ServiceURL: "",
SecretName: "",
AccessKey: "",
SecretKey: "",
}
automationSteps = ""
)
func init() {
cd, err := os.Getwd()
if err != nil {
panic(err)
}
fmt.Println("cd: ", cd)
serverlessDir := path.Join(cd, "builds/serverless")
viper.AddConfigPath(serverlessDir)
err = viper.ReadInConfig()
if err != nil {
panic(err)
}
err = bls_signer.InitEthBLS()
if err != nil {
panic(err)
}
/*
########################################
AWS settings (internal access)
########################################
*/
// aws automation settings for lambda set up
// your aws account number should not have dashes here, even thought it is displayed with dashes in the UI
Cmd.Flags().StringVar(&awsAuth.AccountNumber, "aws-account-number", "", "AWS_ACCOUNT_NUMBER: aws account number")
Cmd.Flags().StringVar(&awsAuth.AccessKey, "aws-access-key", "", "AWS_ACCESS_KEY: your private aws access key, which needs permissions to create iam users, roles, policies, secrets, and lambda functions and layers")
Cmd.Flags().StringVar(&awsAuth.SecretKey, "aws-secret-key", "", "AWS_SECRET_KEY: your private aws secret key")
if viper.GetString("AWS_ACCESS_KEY") != "" && viper.GetString("AWS_SECRET_KEY") != "" && viper.GetString("AWS_ACCOUNT_NUMBER") != "" {
awsAuth.AccountNumber = viper.GetString("AWS_ACCOUNT_NUMBER")
awsAuth.AccessKey = viper.GetString("AWS_ACCESS_KEY")
awsAuth.SecretKey = viper.GetString("AWS_SECRET_KEY")
}
// actions
Cmd.Flags().BoolVar(&automateSetupOnAWS, "aws-automation-on", viper.GetBool("AWS_AUTOMATION"), "AWS_AUTOMATION: automate the entire setup process on aws, requires you provide aws credentials")
/*
########################################
AWS settings (external access)
########################################
*/
// aws service
Cmd.Flags().StringVar(&externalAwsAuth.ServiceURL, "ext-aws-lambda-url", viper.GetString("AWS_LAMBDA_FUNC_URL"), "AWS_LAMBDA_FUNC_URL: your lambda func url for validator service on zeus")
Cmd.Flags().StringVar(&externalAwsAuth.AccessKey, "ext-aws-access-key", "", "AWS_EXTERNAL_ACCESS_KEY: external access token for validator service on zeus")
Cmd.Flags().StringVar(&externalAwsAuth.SecretKey, "ext-aws-secret-key", "", "AWS_EXTERNAL_SECRET_KEY: external secret token for validator service on zeus")
Cmd.Flags().StringVar(&externalAwsAuth.SecretName, "ext-aws-age-secret-name", viper.GetString("AWS_AGE_DECRYPTION_SECRET_NAME"), "AWS_AGE_DECRYPTION_SECRET_NAME: the name of the secret that holds your age decryption keys for validator service on zeus")
if viper.GetString("AWS_EXTERNAL_ACCESS_KEY") != "" && viper.GetString("AWS_EXTERNAL_SECRET_KEY") != "" {
externalAwsAuth.AccessKey = viper.GetString("AWS_EXTERNAL_ACCESS_KEY")
externalAwsAuth.SecretKey = viper.GetString("AWS_EXTERNAL_SECRET_KEY")
}
// secret key generation for serverless
Cmd.Flags().StringVar(&agePrivKey, "age-private-key", "", "AGE_PRIVKEY: age private key")
Cmd.Flags().StringVar(&agePubKey, "age-public-key", "", "AGE_PUBKEY: age public key")
if viper.GetString("AGE_PRIVKEY") != "" && viper.GetString("AGE_PUBKEY") != "" {
agePrivKey = viper.GetString("AGE_PRIVKEY")
agePubKey = viper.GetString("AGE_PUBKEY")
}
// actions
Cmd.Flags().BoolVar(&keyGenSecrets, "keygen", viper.GetBool("KEYGEN_SECRETS"), "KEYGEN_SECRETS: generates secrets for validator encryption and generation")
/*
###################################################
Validator network, keygen, and deposit settings
###################################################
*/
// validator key generation for deposits settings
if viper.GetString("NETWORK") == "" || viper.GetString("NODE_URL") == "" {
log.Info().Msg("no network or node url provided, using ephemery network and eth.ephemeral.zeus.fyi node url")
viper.Set("NETWORK", "ephemery")
viper.Set("NODE_URL", "https://eth.ephemeral.zeus.fyi")
}
Cmd.Flags().StringVar(&nodeURL, "node-url", viper.GetString("NODE_URL"), "NODE_URL: beacon for getting network data for validator deposit generation & submitting deposits")
Cmd.Flags().StringVar(&network, "network", viper.GetString("NETWORK"), "NETWORK: network to run on mainnet, goerli, ephemery, etc")
Cmd.Flags().StringVar(ð1AddrPrivKey, "eth1-addr-priv-key", "", "ETH1_PRIVATE_KEY: eth1 address private key for submitting deposits")
if viper.GetString("ETH1_PRIVATE_KEY") != "" {
eth1AddrPrivKey = viper.GetString("ETH1_PRIVATE_KEY")
}
// validator secret key generation
Cmd.Flags().StringVar(&mnemonic, "mnemonic", "", "MNEMONIC_24_WORDS: twenty four word mnemonic to generate keystores")
Cmd.Flags().StringVar(&hdWalletPassword, "hd-wallet-pw", "", "HD_WALLET_PASSWORD: hd wallet password")
if viper.GetString("MNEMONIC_24_WORDS") != "" && viper.GetString("HD_WALLET_PASSWORD") != "" {
mnemonic = viper.GetString("MNEMONIC_24_WORDS")
hdWalletPassword = viper.GetString("HD_WALLET_PASSWORD")
}
Cmd.Flags().IntVar(&numKeysToGen, "validator-count", viper.GetInt("VALIDATORS_COUNT"), "VALIDATORS_COUNT: number of keys to generate")
Cmd.Flags().IntVar(&hdOffset, "hd-offset", viper.GetInt("HD_OFFSET_VALIDATORS"), "HD_OFFSET_VALIDATORS: offset to start generating keys from hd wallet")
// validator key generation paths
Cmd.Flags().StringVar(&keystoresPath.DirIn, "keystores-dir-in", viper.GetString("KEYSTORE_DIR_IN"), "KEYSTORE_DIR_IN: keystores directory in location (relative to builds dir)")
Cmd.Flags().StringVar(&keystoresPath.DirOut, "keystores-dir-out", viper.GetString("KEYSTORE_DIR_OUT"), "KEYSTORE_DIR_OUT: keystores directory out location (relative to builds dir)")
if keystoresPath.DirIn == "" || keystoresPath.DirOut == "" {
log.Info().Msg("no keystore path provided, using ./serverless/keystores as default, this is relative to the builds directory")
keystoresPath.DirIn = path.Join(serverlessDir, "/keystores")
keystoresPath.DirOut = path.Join(serverlessDir, "/keystores")
}
// actions
Cmd.Flags().BoolVar(&genValidatorDeposits, "keygen-validators", viper.GetBool("KEYGEN_VALIDATORS"), "KEYGEN_VALIDATORS: generates validator deposits, with additional encrypted age keystore")
Cmd.Flags().BoolVar(&sendDeposits, "submit-deposits", viper.GetBool("SUBMIT_DEPOSITS"), "SUBMIT_DEPOSITS: submits validator deposits in keystore directory to the network for activation")
/*
###################################################
Validator service values for Zeus
###################################################
*/
// service on zeus
Cmd.Flags().StringVar(&bearerToken, "bearer", viper.GetString("BEARER"), "BEARER: bearer token for validator service on zeus")
Cmd.Flags().StringVar(&keyGroupName, "key-group-name", viper.GetString("KEY_GROUP_NAME"), "KEY_GROUP_NAME: name for validator service group on zeus")
Cmd.Flags().StringVar(&feeRecipient, "fee-recipient", viper.GetString("FEE_RECIPIENT_ADDR"), "FEE_RECIPIENT_ADDR: fee recipient address for validators service on zeus")
Cmd.Flags().BoolVar(&submitValidatorServiceReq, "submit-validator-service-req", viper.GetBool("SUBMIT_SERVICE_REQUEST"), "SUBMIT_SERVICE_REQUEST: sends a request to zeus to setup a validator service")
/*
###################################################
Automation Steps
###################################################
*/
if viper.GetString("AUTOMATION_STEPS") == "" {
viper.Set("AUTOMATION_STEPS", "all")
}
Cmd.Flags().StringVar(&automationSteps, "automation-steps", viper.GetString("AUTOMATION_STEPS"), "AUTOMATION_STEPS: select which steps to automate and which order, using a comma separated list of numbers. default is all steps in order")
}
// Cmd represents the base command when called without any subcommands
var Cmd = &cobra.Command{
Use: "Validator Key Generation and AWS Lambda Serverless Setup Automation",
Short: "Automates the entire setup process for validator keys and serverless setup on AWS",
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
if automateSetupOnAWS {
if awsAuth.AccountNumber == "" || awsAuth.AccessKey == "" || awsAuth.SecretKey == "" {
panic("ERROR: aws credentials and/or account number missing")
}
}
w3Client := signing_automation_ethereum.Web3SignerClient{
Web3Actions: web3_actions.Web3Actions{
NodeURL: nodeURL,
Network: network,
},
}
if automationSteps == "all" {
automationSteps = "1,2,3,4,5,6,7,8,9"
automateSetupOnAWS = true
}
if automationSteps == "serverless" {
automationSteps = "1,2,3,4,5,6,7"
automateSetupOnAWS = true
}
for _, automationStep := range strings.Split(automationSteps, ",") {
switch automationStep {
case "getMnemonicHDWalletPasswordSecret":
s, err := serverless_aws_automation.GetSecret(ctx, awsAuth, mnemonicAndHDWalletSecretName)
if err != nil {
panic(err)
}
fmt.Println(s)
case "getAgeEncryptionKeySecret":
s, err := serverless_aws_automation.GetSecret(ctx, awsAuth, ageEncryptionSecretName)
if err != nil {
panic(err)
}
fmt.Println(s)
case "getExternalLambdaAccessKeys":
s, err := serverless_aws_automation.GetSecret(ctx, awsAuth, externalZeusLambdaAccessKeys)
if err != nil {
panic(err)
}
fmt.Println(s)
case "updateLambdaKeystoresLayerToLatest":
serverless_aws_automation.UpdateLambdaFunctionKeystoresLayer(ctx, awsAuth)
case "1", "createSecretsAndStoreInAWS":
fmt.Println("INFO: no credentials provided, will generate new credentials, but won't" +
" store these in AWS if you already have them in AWS, it will reuse your AWS stored ones for the following steps")
if agePubKey == "" || agePrivKey == "" {
fmt.Println("INFO: no credentials provided, generating new age keypair")
agePubKey, agePrivKey = age_encryption.GenerateNewKeyPair()
fmt.Println("agePubKey: ", agePubKey)
fmt.Println("agePrivKey: ", agePrivKey)
}
if hdWalletPassword == "" {
fmt.Println("INFO: no credentials provided, generating random string password")
hdWalletPassword = rand.String(32)
fmt.Println("hdWalletPassword: ", hdWalletPassword)
}
if mnemonic == "" {
fmt.Println("INFO: no mnemonic provided, generating new mnemonic")
mnemonic24Words, err := aegis_random.GenerateMnemonic()
if err != nil {
panic(err)
}
mnemonic = mnemonic24Words
fmt.Println("mnemonic: ", mnemonic)
}
if automateSetupOnAWS {
serverless_aws_automation.AddMnemonicHDWalletSecretInAWSSecretManager(ctx, awsAuth, mnemonicAndHDWalletSecretName, hdWalletPassword, mnemonic)
serverless_aws_automation.AddAgeEncryptionKeyInAWSSecretManager(ctx, awsAuth, ageEncryptionSecretName, agePubKey, agePrivKey)
}
case "2", "createInternalLambdaUser":
fmt.Println("INFO: creating internal iam user, role, policies for serverless deployment")
serverless_aws_automation.InternalUserRolePolicySetupForLambdaDeployment(ctx, awsAuth)
case "3", "generateValidatorDeposits":
fmt.Println("INFO: generating keystores, deposit data, and encrypting keystores with age encryption")
s, err := serverless_aws_automation.GetSecret(ctx, awsAuth, ageEncryptionSecretName)
if err != nil {
panic(err)
}
mns, err := serverless_aws_automation.GetSecret(ctx, awsAuth, mnemonicAndHDWalletSecretName)
if err != nil {
panic(err)
}
mnemonic = mns["mnemonic"]
hdWalletPassword = mns["hdWalletPassword"]
for pubkey, privkey := range s {
agePubKey = pubkey
agePrivKey = privkey
}
vdg := signing_automation_ethereum.ValidatorDepositGenerationParams{
Fp: keystoresPath,
Mnemonic: mnemonic,
Pw: hdWalletPassword,
ValidatorIndexOffset: hdOffset,
NumValidators: numKeysToGen,
Network: network,
}
enc := age_encryption.NewAge(agePrivKey, agePubKey)
err = ethereum_automation_cookbook.GenerateValidatorDepositsAndCreateAgeEncryptedKeystores(ctx, w3Client, vdg, enc, hdWalletPassword)
if err != nil {
panic(err)
}
case "4", "createLambdaFunctionKeystoresLayer":
fmt.Println("INFO: creating lambda keystore layer using your encrypted keystores from step 3")
serverless_aws_automation.CreateLambdaFunctionKeystoresLayer(ctx, awsAuth, keystoresPath)
case "5", "createLambdaFunction":
fmt.Println("INFO: creating lambda function")
lambdaFnUrl := serverless_aws_automation.CreateLambdaFunction(ctx, awsAuth)
externalAwsAuth.ServiceURL = lambdaFnUrl
fmt.Println("lambdaFnUrl: ", externalAwsAuth.ServiceURL)
case "6", "createExternalLambdaUser":
fmt.Println("INFO: creating external iam user, role, policies for us to send validator messages to your lambda function")
serverless_aws_automation.ExternalUserRolePolicySetupForLambdaDeployment(ctx, awsAuth)
if externalAwsAuth.AccessKey == "" || externalAwsAuth.SecretKey == "" {
s, err := serverless_aws_automation.GetExternalAccessKeySecretIfExists(ctx, awsAuth, externalZeusLambdaAccessKeys)
if err != nil {
panic(err)
}
externalAwsAuth.AccessKey = s.AccessKey
externalAwsAuth.SecretKey = s.SecretKey
if externalAwsAuth.AccessKey == "" || externalAwsAuth.SecretKey == "" {
externalAccessKeys := serverless_aws_automation.CreateExternalLambdaUserAccessKeys(ctx, awsAuth)
serverless_aws_automation.AddExternalAccessKeysInAWSSecretManager(ctx, awsAuth, externalZeusLambdaAccessKeys, externalAccessKeys)
externalAwsAuth.AccessKey = externalAccessKeys.AccessKey
externalAwsAuth.SecretKey = externalAccessKeys.SecretKey
}
}
case "7", "verifyLambdaFunction":
if externalAwsAuth.ServiceURL == "" {
fmt.Println("INFO: no lambda fn url, looking up url if exists")
externalAwsAuth.ServiceURL = serverless_aws_automation.GetLambdaFunctionUrl(ctx, awsAuth)
}
if externalAwsAuth.ServiceURL == "" {
panic("ERROR: lambda function url not provided or configured")
}
if externalAwsAuth.AccessKey == "" || externalAwsAuth.SecretKey == "" {
fmt.Println("INFO: checking if external access keys are stored in aws secret manager")
s, err := serverless_aws_automation.GetExternalAccessKeySecretIfExists(ctx, awsAuth, externalZeusLambdaAccessKeys)
if err != nil {
panic(err)
}
externalAwsAuth.AccessKey = s.AccessKey
externalAwsAuth.SecretKey = s.SecretKey
if externalAwsAuth.AccessKey == "" || externalAwsAuth.SecretKey == "" {
fmt.Println("INFO: no external access keys found in aws secret manager, generating and storing new access keys")
externalAccessKeys := serverless_aws_automation.CreateExternalLambdaUserAccessKeys(ctx, awsAuth)
externalAwsAuth.AccessKey = externalAccessKeys.AccessKey
externalAwsAuth.SecretKey = externalAccessKeys.SecretKey
serverless_aws_automation.AddExternalAccessKeysInAWSSecretManager(ctx, awsAuth, externalZeusLambdaAccessKeys, externalAccessKeys)
}
}
lambdaAccessAuth := aws_aegis_auth.AuthAWS{
Region: "us-west-1",
AccessKey: externalAwsAuth.AccessKey,
SecretKey: externalAwsAuth.SecretKey,
}
fmt.Println("INFO: verifying we can send validator messages to your lambda function")
serverless_aws_automation.VerifyLambdaSigner(ctx, lambdaAccessAuth, keystoresPath, externalAwsAuth.ServiceURL, ageEncryptionSecretName)
case "8", "createValidatorServiceRequestOnZeus":
fmt.Println("INFO: creating zeus validator service request")
if bearerToken == "" {
panic("ERROR: bearer token not provided")
}
if feeRecipient == "" {
panic("ERROR: fee recipient not provided")
}
err := web3_actions.ValidateToAddress(ctx, feeRecipient)
if err != nil {
panic("ERROR: fee recipient is not a valid ethereum address")
}
feeRecipient = strings_filter.AddHexPrefix(feeRecipient)
serverless_aws_automation.ExternalUserRolePolicySetupForLambdaDeployment(ctx, awsAuth)
if externalAwsAuth.AccessKey == "" || externalAwsAuth.SecretKey == "" {
fmt.Println("INFO: no credentials provided, generating new aws access key pair")
keys, err := serverless_aws_automation.GetExternalAccessKeySecret(ctx, awsAuth, externalZeusLambdaAccessKeys)
if err != nil {
panic("ERROR: failed to get external access key secret")
}
externalAwsAuth.AccessKey = keys.AccessKey
externalAwsAuth.SecretKey = keys.SecretKey
}
if keyGroupName == "" {
fmt.Println("INFO: no key group name provided, generating a key group name")
keyGroupName = fmt.Sprintf("keyGroup-%d", time.Now().Unix())
fmt.Println("INFO: generated key group name: ", keyGroupName)
}
sr := hestia_req_types.ServiceRequestWrapper{
GroupName: keyGroupName,
ProtocolNetworkID: hestia_req_types.ProtocolNetworkStringToID(network),
Enabled: true,
ServiceAuth: hestia_req_types.ServiceAuthConfig{
AuthLamdbaAWS: &hestia_req_types.AuthLamdbaAWS{
ServiceURL: externalAwsAuth.ServiceURL,
SecretName: ageEncryptionSecretName,
AccessKey: externalAwsAuth.AccessKey,
SecretKey: externalAwsAuth.SecretKey,
},
}}
err = sr.ServiceAuth.Validate()
if err != nil {
panic(err)
}
serverless_aws_automation.CreateHestiaValidatorsServiceRequest(ctx, keystoresPath, sr, bearerToken, feeRecipient)
case "9", "sendValidatorDeposits":
fmt.Println("INFO: submitting validator deposits to the network")
if eth1AddrPrivKey == "" {
panic("eth1 address private key is required for submitting deposits, you'll also need 32 Eth per validator + gas fees")
}
fmt.Println("INFO: depositing validators, using the dir in path relative to the build dir: default is builds/serverless/keystores")
fmt.Println("INFO: your keystore directory search path is: ", keystoresPath.DirIn)
acc, err := accounts.ParsePrivateKey(eth1AddrPrivKey)
if err != nil {
panic(err)
}
w3Client.Account = acc
filter := &strings_filter.FilterOpts{StartsWith: "deposit_data", DoesNotInclude: []string{"keystores.tar.gz.age", ".DS_Store"}}
keystoresPath.FilterFiles = filter
dpSlice, err := signing_automation_ethereum.ParseValidatorDepositSliceJSON(ctx, keystoresPath)
if err != nil {
panic(err)
}
if len(dpSlice) <= 0 {
panic("no deposit data found in the dir, please check the path and make sure you have generated validator deposits")
}
txToBroadcast := make([]*types.Transaction, len(dpSlice))
for i, d := range dpSlice {
signedTx, serr := w3Client.SignValidatorDepositTxToBroadcastFromJSON(ctx, d)
if serr != nil {
panic(serr)
}
txToBroadcast[i] = signedTx
rx, serr := w3Client.SubmitSignedTxAndReturnTxData(ctx, signedTx)
if serr != nil {
panic(serr)
}
fmt.Println("tx receipt: ", rx.Hash.String())
}
}
}
}}
func ForceDirToRootDir() string {
_, filename, _, _ := runtime.Caller(0)
dir := path.Join(path.Dir(filename), "")
err := os.Chdir(dir)
if err != nil {
panic(err.Error())
}
return dir
}