@@ -133,42 +133,54 @@ func buildModifiedParams(p1, p2 *channel.Params, s *Setup) (ret []channel.Params
133
133
// Modify complete Params
134
134
{
135
135
modParams := * p2
136
- ret = append (ret , modParams )
136
+ ret = appendModParams (ret , modParams )
137
137
}
138
138
// Modify ChallengeDuration
139
139
{
140
140
modParams := * p1
141
141
modParams .ChallengeDuration = p2 .ChallengeDuration
142
- ret = append (ret , modParams )
142
+ ret = appendModParams (ret , modParams )
143
143
}
144
144
// Modify Parts
145
145
{
146
146
// Modify complete Parts
147
147
{
148
148
modParams := * p1
149
149
modParams .Parts = p2 .Parts
150
- ret = append (ret , modParams )
150
+ ret = appendModParams (ret , modParams )
151
151
}
152
152
// Modify Parts[0]
153
153
{
154
154
modParams := * p1
155
155
modParams .Parts = make ([]wallet.Address , len (p1 .Parts ))
156
156
copy (modParams .Parts , p1 .Parts )
157
157
modParams .Parts [0 ] = s .RandomAddress ()
158
- ret = append (ret , modParams )
158
+ ret = appendModParams (ret , modParams )
159
159
}
160
160
}
161
161
// Modify Nonce
162
162
{
163
163
modParams := * p1
164
164
modParams .Nonce = p2 .Nonce
165
- ret = append (ret , modParams )
165
+ ret = appendModParams (ret , modParams )
166
166
}
167
167
}
168
168
169
169
return
170
170
}
171
171
172
+ func appendModParams (a []channel.Params , modParams channel.Params ) []channel.Params {
173
+ p := channel .NewParamsUnsafe (
174
+ modParams .ChallengeDuration ,
175
+ modParams .Parts ,
176
+ modParams .App ,
177
+ modParams .Nonce ,
178
+ modParams .LedgerChannel ,
179
+ modParams .VirtualChannel ,
180
+ )
181
+ return append (a , * p )
182
+ }
183
+
172
184
// buildModifiedStates returns a slice of States that are different from `s1` assuming that `s2` differs in
173
185
// every member from `s1`.
174
186
// `modifyApp` indicates whether the app should also be changed or not. In some cases (signature) it is desirable
@@ -211,8 +223,11 @@ func buildModifiedStates(s1, s2 *channel.State, modifyApp bool) (ret []channel.S
211
223
{
212
224
// Modify complete Assets
213
225
{
226
+ l1 , l2 := len (s1 .Allocation .Assets ), len (s2 .Allocation .Assets )
214
227
modState := s1 .Clone ()
215
- modState .Allocation .Assets = s2 .Allocation .Assets
228
+ for i := 0 ; i < l1 && i < l2 ; i ++ {
229
+ modState .Allocation .Assets [i ] = s2 .Allocation .Assets [i ]
230
+ }
216
231
ret = append (ret , * modState )
217
232
}
218
233
// Modify Assets[0]
@@ -228,8 +243,11 @@ func buildModifiedStates(s1, s2 *channel.State, modifyApp bool) (ret []channel.S
228
243
{
229
244
// Modify complete Balances
230
245
{
246
+ l1 , l2 := len (s1 .Allocation .Balances ), len (s2 .Allocation .Balances )
231
247
modState := s1 .Clone ()
232
- modState .Allocation .Balances = s2 .Allocation .Balances
248
+ for i := 0 ; i < l1 && i < l2 ; i ++ {
249
+ modState .Allocation .Balances [i ] = s2 .Allocation .Balances [i ]
250
+ }
233
251
ret = append (ret , * modState )
234
252
}
235
253
// Modify Balances[0]
@@ -246,14 +264,14 @@ func buildModifiedStates(s1, s2 *channel.State, modifyApp bool) (ret []channel.S
246
264
}
247
265
}
248
266
// Modify Locked
249
- {
267
+ if len ( s1 . Allocation . Locked ) > 0 && len ( s2 . Allocation . Locked ) > 0 {
250
268
// Modify complete Locked
251
269
{
252
270
modState := s1 .Clone ()
253
271
modState .Allocation .Locked = s2 .Allocation .Locked
254
272
ret = append (ret , * modState )
255
273
}
256
- // Modify AppID
274
+ // Modify Locked ID
257
275
{
258
276
modState := s1 .Clone ()
259
277
modState .Allocation .Locked [0 ].ID = s2 .Allocation .Locked [0 ].ID
0 commit comments