Skip to content

Commit

Permalink
Order deposit data from HD wallet accounts by path.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 31, 2025
1 parent 5d95e93 commit 3e173f1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.36.6:
- allow specification of blockid for validator info
- validator depositdata orders deposits from an HD wallet by path

1.36.5:
- avoid corner case mnemonic derivation with 25th word
Expand Down
1 change: 1 addition & 0 deletions cmd/validator/depositdata/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
type dataOut struct {
format string
account string
path string
validatorPubKey *spec.BLSPubKey
withdrawalCredentials []byte
amount spec.Gwei
Expand Down
49 changes: 48 additions & 1 deletion cmd/validator/depositdata/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"context"
"encoding/hex"
"fmt"
"sort"
"strconv"
"strings"

spec "github.com/attestantio/go-eth2-client/spec/phase0"
Expand Down Expand Up @@ -80,7 +82,7 @@ func process(data *dataIn) ([]*dataOut, error) {
copy(depositDataRoot[:], root[:])

validatorWallet := validatorAccount.(e2wtypes.AccountWalletProvider).Wallet()
results = append(results, &dataOut{
result := &dataOut{
format: data.format,
account: fmt.Sprintf("%s/%s", validatorWallet.Name(), validatorAccount.Name()),
validatorPubKey: &pubKey,
Expand All @@ -90,8 +92,53 @@ func process(data *dataIn) ([]*dataOut, error) {
forkVersion: data.forkVersion,
depositMessageRoot: &depositMessageRoot,
depositDataRoot: &depositDataRoot,
}
if pathProvider, isPathProvider := validatorAccount.(e2wtypes.AccountPathProvider); isPathProvider {
result.path = pathProvider.Path()
}
results = append(results, result)
}
if len(results) == 0 {
return results, nil
}

// Order the results
if results[0].path != "" {
// Order accounts by their path components.
sort.Slice(results, func(i int, j int) bool {
iBits := strings.Split(results[i].path, "/")
jBits := strings.Split(results[j].path, "/")
for index := range iBits {
if iBits[index] == "m" && jBits[index] == "m" {
continue
}
if len(jBits) <= index {
return false
}
iBit, err := strconv.ParseUint(iBits[index], 10, 64)
if err != nil {
return true
}
jBit, err := strconv.ParseUint(jBits[index], 10, 64)
if err != nil {
return false
}
if iBit < jBit {
return true
}
if iBit > jBit {
return false
}
}
return len(jBits) > len(iBits)
})
} else {
// Order accounts by their name.
sort.Slice(results, func(i int, j int) bool {
return strings.Compare(results[i].account, results[j].account) < 0
})
}

return results, nil
}

Expand Down

0 comments on commit 3e173f1

Please sign in to comment.