@@ -17,6 +17,8 @@ import (
17
17
"context"
18
18
"encoding/hex"
19
19
"fmt"
20
+ "sort"
21
+ "strconv"
20
22
"strings"
21
23
22
24
spec "github.com/attestantio/go-eth2-client/spec/phase0"
@@ -80,7 +82,7 @@ func process(data *dataIn) ([]*dataOut, error) {
80
82
copy (depositDataRoot [:], root [:])
81
83
82
84
validatorWallet := validatorAccount .(e2wtypes.AccountWalletProvider ).Wallet ()
83
- results = append ( results , & dataOut {
85
+ result := & dataOut {
84
86
format : data .format ,
85
87
account : fmt .Sprintf ("%s/%s" , validatorWallet .Name (), validatorAccount .Name ()),
86
88
validatorPubKey : & pubKey ,
@@ -90,8 +92,53 @@ func process(data *dataIn) ([]*dataOut, error) {
90
92
forkVersion : data .forkVersion ,
91
93
depositMessageRoot : & depositMessageRoot ,
92
94
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
93
139
})
94
140
}
141
+
95
142
return results , nil
96
143
}
97
144
0 commit comments