Skip to content

Commit

Permalink
noto: add check for duplicate states
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Sep 17, 2024
1 parent 79cf7ab commit 19a53fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 12 additions & 7 deletions domains/noto/internal/noto/noto.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,24 @@ func (n *Noto) recoverSignature(ctx context.Context, payload ethtypes.HexBytes0x

func (n *Noto) parseCoinList(label string, states []*pb.EndorsableState) ([]*types.NotoCoin, []*pb.StateRef, *big.Int, error) {
var err error
statesUsed := make(map[string]bool)
coins := make([]*types.NotoCoin, len(states))
refs := make([]*pb.StateRef, len(states))
total := big.NewInt(0)
for i, input := range states {
if input.SchemaId != n.coinSchema.Id {
return nil, nil, nil, fmt.Errorf("unknown schema ID: %s", input.SchemaId)
for i, state := range states {
if state.SchemaId != n.coinSchema.Id {
return nil, nil, nil, fmt.Errorf("unknown schema ID: %s", state.SchemaId)
}
if statesUsed[state.Id] {
return nil, nil, nil, fmt.Errorf("duplicate state provided: %s", state.Id)
}
if coins[i], err = n.unmarshalCoin(input.StateDataJson); err != nil {
return nil, nil, nil, fmt.Errorf("invalid %s[%d] (%s): %s", label, i, input.Id, err)
statesUsed[state.Id] = true
if coins[i], err = n.unmarshalCoin(state.StateDataJson); err != nil {
return nil, nil, nil, fmt.Errorf("invalid %s[%d] (%s): %s", label, i, state.Id, err)
}
refs[i] = &pb.StateRef{
SchemaId: input.SchemaId,
Id: input.Id,
SchemaId: state.SchemaId,
Id: state.Id,
}
total = total.Add(total, coins[i].Amount.BigInt())
}
Expand Down
1 change: 1 addition & 0 deletions domains/noto/internal/noto/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (n *Noto) prepareInputs(ctx context.Context, owner ethtypes.Address0xHex, a
stateRefs := []*pb.StateRef{}
coins := []*types.NotoCoin{}
for {
// TODO: make this configurable
queryBuilder := query.NewQueryBuilder().
Limit(10).
Sort(".created").
Expand Down

0 comments on commit 19a53fe

Please sign in to comment.