Skip to content

Commit 9b1ee87

Browse files
committed
fixed indexes in states search
1 parent 8500f4f commit 9b1ee87

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

internal/rarimo/stateupdate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ func (m *StateUpdateMessageMaker) getStatesOnBlock(ctx context.Context, issuer,
138138
return nil, nil, errors.Wrap(err, "failed to get overall states count")
139139
}
140140

141-
if length.Cmp(big.NewInt(m.statesPerRequest)) == 0 {
141+
if length.Cmp(big.NewInt(m.statesPerRequest)) <= 0 {
142142
// We need more states on contract. Ignore that state transition.
143-
return nil, nil, nil
143+
return nil, nil, errors.New("states count less then required")
144144
}
145145

146146
length = new(big.Int).Sub(length, big.NewInt(m.statesPerRequest))
@@ -155,8 +155,8 @@ func (m *StateUpdateMessageMaker) getStatesOnBlock(ctx context.Context, issuer,
155155
}
156156

157157
for i := 1; i < len(states); i++ {
158-
replacedState := states[0]
159-
latestState := states[1]
158+
replacedState := states[i-1]
159+
latestState := states[i]
160160
if latestState.CreatedAtBlock.Cmp(block) == 0 {
161161
return &latestState, &replacedState, nil
162162
}
@@ -177,9 +177,9 @@ func (m *StateUpdateMessageMaker) getGISTsOnBlock(ctx context.Context, block *bi
177177
return nil, nil, errors.Wrap(err, "failed to get overall gists count")
178178
}
179179

180-
if length.Cmp(big.NewInt(m.statesPerRequest)) == 0 {
180+
if length.Cmp(big.NewInt(m.statesPerRequest)) <= 0 {
181181
// We need more states on contract. Ignore that state transition.
182-
return nil, nil, nil
182+
return nil, nil, errors.New("GISTs count less then required")
183183
}
184184

185185
length = new(big.Int).Sub(length, big.NewInt(m.statesPerRequest))

0 commit comments

Comments
 (0)