Skip to content

Commit

Permalink
noto: revert use of QueryBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Sep 16, 2024
1 parent d376cc8 commit ee87400
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions domains/noto/internal/noto/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"encoding/json"
"fmt"
"math/big"
"strconv"

"github.com/hyperledger/firefly-signer/pkg/eip712"
"github.com/hyperledger/firefly-signer/pkg/ethtypes"
"github.com/kaleido-io/paladin/domains/noto/pkg/types"
pb "github.com/kaleido-io/paladin/toolkit/pkg/prototk"
"github.com/kaleido-io/paladin/toolkit/pkg/query"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
)

Expand Down Expand Up @@ -87,17 +87,29 @@ func (n *Noto) prepareInputs(ctx context.Context, owner ethtypes.Address0xHex, a
stateRefs := []*pb.StateRef{}
coins := []*types.NotoCoin{}
for {
queryBuilder := query.NewQueryBuilder().
Limit(10).
Sort(".created").
Equal("owner", owner.String())

// Simple oldest coin first algorithm
// TODO: make this configurable
// TODO: why is filters.QueryJSON not a public interface?
query := map[string]interface{}{
"limit": 10,
"sort": []string{".created"},
"eq": []map[string]string{{
"field": "owner",
"value": owner.String(),
}},
}
if lastStateTimestamp > 0 {
queryBuilder.GreaterThan(".created", lastStateTimestamp)
query["gt"] = []map[string]string{{
"field": ".created",
"value": strconv.FormatInt(lastStateTimestamp, 10),
}}
}
queryJSON, err := json.Marshal(query)
if err != nil {
return nil, nil, nil, err
}

states, err := n.findAvailableStates(ctx, queryBuilder.Query().String())

states, err := n.findAvailableStates(ctx, string(queryJSON))
if err != nil {
return nil, nil, nil, err
}
Expand Down

0 comments on commit ee87400

Please sign in to comment.