Skip to content

Commit

Permalink
fix: bump up compatibility for deposit data json to 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush-rockx committed Dec 4, 2023
1 parent f748773 commit d80c02d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmd/generate_keystore
dkg_results_*
keyshares-*
deposit-data_*
deposit_data-*
build/bin/*
release/*
*.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ rockx-dkg-cli generate-deposit-data --request-id 33a5b7fe2b415673c4d971e6c0b002c
This will right the results to a json file in the following way

```
writing deposit data json to file deposit-data_1701318343.json
writing deposit data json to file deposit_data-1701318343.json
```

#### Get Keyshares
Expand Down
45 changes: 30 additions & 15 deletions internal/cli/handle_get_deposit_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ import (
"github.com/urfave/cli/v2"
)

var (
DepositCliVersion = "2.7.0"
)

type DepositDataJson struct {
PubKey string `json:"pubkey"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
Amount phase0.Gwei `json:"amount"`
Signature string `json:"signature"`
DepositMessageRoot string `json:"deposit_message_root"`
DepositDataRoot string `json:"deposit_data_root"`
ForkVersion string `json:"fork_version"`
NetworkName string `json:"network_name"`
DepositCliVersion string `json:"deposit_cli_version"`
PubKey string `json:"pubkey"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
Amount uint64 `json:"amount"`
Signature string `json:"signature"`
DepositMessageRoot string `json:"deposit_message_root"`
DepositDataRoot string `json:"deposit_data_root"`
ForkVersion string `json:"fork_version"`
NetworkName string `json:"network_name"`
DepositCliVersion string `json:"deposit_cli_version"`
}

func (h *CliHandler) HandleGetDepositData(c *cli.Context) error {
Expand Down Expand Up @@ -74,28 +78,39 @@ func (h *CliHandler) HandleGetDepositData(c *cli.Context) error {
WithdrawalCredentials: withdrawalCredentials,
Amount: amount,
}
depositMsgRoot, _ := depositMsg.HashTreeRoot()

blsSigBytes, _ := hex.DecodeString(results.Output[firstOperator].Data.DepositDataSignature)
depositMsgRoot, err := depositMsg.HashTreeRoot()
if err != nil {
return fmt.Errorf("HandleGetDepositData: failed to generate deposit message root: %w", err)
}

blsSigBytes, err := hex.DecodeString(results.Output[firstOperator].Data.DepositDataSignature)
if err != nil {
return fmt.Errorf("HandleGetDepositData: failed to decode bls signature: %w", err)
}

blsSig := phase0.BLSSignature{}
copy(blsSig[:], blsSigBytes)
depositData.Signature = blsSig

depositDataRoot, _ := depositData.HashTreeRoot()
depositDataRoot, err := depositData.HashTreeRoot()
if err != nil {
return fmt.Errorf("HandleGetDepositData: failed to generate deposit data root: %w", err)
}

depositDataJson := DepositDataJson{
PubKey: results.Output[firstOperator].Data.ValidatorPubKey,
WithdrawalCredentials: c.String("withdrawal-credentials"),
Amount: amount,
Amount: types.MaxEffectiveBalanceInGwei,
Signature: results.Output[firstOperator].Data.DepositDataSignature,
DepositMessageRoot: hex.EncodeToString(depositMsgRoot[:]),
DepositDataRoot: hex.EncodeToString(depositDataRoot[:]),
ForkVersion: hex.EncodeToString(fork[:]),
NetworkName: c.String("fork-version"),
DepositCliVersion: "2.3.0",
DepositCliVersion: DepositCliVersion,
}

filepath := fmt.Sprintf("deposit-data_%d.json", time.Now().UTC().Unix())
filepath := fmt.Sprintf("deposit_data-%d.json", time.Now().UTC().Unix())
fmt.Printf("writing deposit data json to file %s\n", filepath)
return utils.WriteJSON(filepath, []DepositDataJson{depositDataJson})
}

0 comments on commit d80c02d

Please sign in to comment.