Skip to content

Commit 3e173f1

Browse files
committed
Order deposit data from HD wallet accounts by path.
1 parent 5d95e93 commit 3e173f1

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1.36.6:
22
- allow specification of blockid for validator info
3+
- validator depositdata orders deposits from an HD wallet by path
34

45
1.36.5:
56
- avoid corner case mnemonic derivation with 25th word

cmd/validator/depositdata/output.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
type dataOut struct {
2525
format string
2626
account string
27+
path string
2728
validatorPubKey *spec.BLSPubKey
2829
withdrawalCredentials []byte
2930
amount spec.Gwei

cmd/validator/depositdata/process.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"context"
1818
"encoding/hex"
1919
"fmt"
20+
"sort"
21+
"strconv"
2022
"strings"
2123

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

8284
validatorWallet := validatorAccount.(e2wtypes.AccountWalletProvider).Wallet()
83-
results = append(results, &dataOut{
85+
result := &dataOut{
8486
format: data.format,
8587
account: fmt.Sprintf("%s/%s", validatorWallet.Name(), validatorAccount.Name()),
8688
validatorPubKey: &pubKey,
@@ -90,8 +92,53 @@ func process(data *dataIn) ([]*dataOut, error) {
9092
forkVersion: data.forkVersion,
9193
depositMessageRoot: &depositMessageRoot,
9294
depositDataRoot: &depositDataRoot,
95+
}
96+
if pathProvider, isPathProvider := validatorAccount.(e2wtypes.AccountPathProvider); isPathProvider {
97+
result.path = pathProvider.Path()
98+
}
99+
results = append(results, result)
100+
}
101+
if len(results) == 0 {
102+
return results, nil
103+
}
104+
105+
// Order the results
106+
if results[0].path != "" {
107+
// Order accounts by their path components.
108+
sort.Slice(results, func(i int, j int) bool {
109+
iBits := strings.Split(results[i].path, "/")
110+
jBits := strings.Split(results[j].path, "/")
111+
for index := range iBits {
112+
if iBits[index] == "m" && jBits[index] == "m" {
113+
continue
114+
}
115+
if len(jBits) <= index {
116+
return false
117+
}
118+
iBit, err := strconv.ParseUint(iBits[index], 10, 64)
119+
if err != nil {
120+
return true
121+
}
122+
jBit, err := strconv.ParseUint(jBits[index], 10, 64)
123+
if err != nil {
124+
return false
125+
}
126+
if iBit < jBit {
127+
return true
128+
}
129+
if iBit > jBit {
130+
return false
131+
}
132+
}
133+
return len(jBits) > len(iBits)
134+
})
135+
} else {
136+
// Order accounts by their name.
137+
sort.Slice(results, func(i int, j int) bool {
138+
return strings.Compare(results[i].account, results[j].account) < 0
93139
})
94140
}
141+
95142
return results, nil
96143
}
97144

0 commit comments

Comments
 (0)