Skip to content

Commit 749eaec

Browse files
committed
Add searchUtxos query to cardano-rpc
1 parent e8e80af commit 749eaec

16 files changed

Lines changed: 1312 additions & 254 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-rpc
2+
pr: 1123
3+
kind:
4+
- feature
5+
description: |
6+
Add searchUtxos gRPC method to the UTxO RPC query service, implementing predicate-based UTxO filtering with address, asset, and boolean combinators, plus cursor-based pagination.

cardano-rpc/cardano-rpc.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ library
5858
Cardano.Rpc.Server.Internal.Monad
5959
Cardano.Rpc.Server.Internal.Node
6060
Cardano.Rpc.Server.Internal.Tracing
61+
Cardano.Rpc.Server.Internal.UtxoRpc.Predicate
6162
Cardano.Rpc.Server.Internal.UtxoRpc.Query
6263
Cardano.Rpc.Server.Internal.UtxoRpc.Submit
6364
Cardano.Rpc.Server.Internal.UtxoRpc.Type
@@ -121,6 +122,7 @@ test-suite cardano-rpc-test
121122
type: exitcode-stdio-1.0
122123
build-depends:
123124
base,
125+
bytestring,
124126
cardano-api,
125127
cardano-api:gen,
126128
cardano-ledger-api,
@@ -130,9 +132,11 @@ test-suite cardano-rpc-test
130132
containers,
131133
hedgehog,
132134
hedgehog-extras,
135+
proto-lens,
133136
rio,
134137
tasty,
135138
tasty-hedgehog,
139+
text,
136140
time,
137141

138142
ghc-options:
@@ -142,6 +146,8 @@ test-suite cardano-rpc-test
142146

143147
build-tool-depends: tasty-discover:tasty-discover
144148
other-modules:
149+
Test.Cardano.Rpc.Pagination
150+
Test.Cardano.Rpc.Predicate
145151
Test.Cardano.Rpc.ProtocolParameters
146152
Test.Cardano.Rpc.TxOutput
147153
Test.Cardano.Rpc.Type

cardano-rpc/gen/Proto/Utxorpc/V1beta/Cardano/Cardano.hs

Lines changed: 222 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cardano-rpc/gen/Proto/Utxorpc/V1beta/Cardano/Cardano_Fields.hs

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cardano-rpc/gen/Proto/Utxorpc/V1beta/Query/Query.hs

Lines changed: 135 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cardano-rpc/gen/Proto/Utxorpc/V1beta/Query/Query_Fields.hs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cardano-rpc/proto/utxorpc/v1beta/cardano/cardano.proto

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,15 @@ message UpdateDRepCert {
516516

517517
// Pattern of an address that can be used to evaluate matching predicates.
518518
message AddressPattern {
519-
bytes exact_address = 1; // The address should match this exact address value.
520-
bytes payment_part = 2; // The payment part of the address should match this value.
521-
bytes delegation_part = 3; // The delegation part of the address should match this value.
519+
optional bytes exact_address = 1; // The address should match this exact address value.
520+
optional bytes payment_part = 2; // The payment part of the address should match this value.
521+
optional bytes delegation_part = 3; // The delegation part of the address should match this value.
522522
}
523523

524524
// Pattern of a native asset that can be used to evaluate matching predicates.
525525
message AssetPattern {
526-
bytes policy_id = 1; // The asset should belong to this policy id
527-
bytes asset_name = 2; // The asset should present this name
526+
optional bytes policy_id = 1; // The asset should belong to this policy id
527+
optional bytes asset_name = 2; // The asset should present this name
528528
}
529529

530530
// Pattern of a certificate that can be used to evaluate matching predicates.
@@ -561,8 +561,8 @@ message PoolRetirementPattern {
561561

562562
// Pattern of a tx output that can be used to evaluate matching predicates.
563563
message TxOutputPattern {
564-
AddressPattern address = 1; // Match any address in the output that exhibits this pattern.
565-
AssetPattern asset = 2; // Match any asset in the output that exhibits this pattern.
564+
optional AddressPattern address = 1; // Match any address in the output that exhibits this pattern.
565+
optional AssetPattern asset = 2; // Match any asset in the output that exhibits this pattern.
566566
}
567567

568568
// Pattern of a Tx that can be used to evaluate matching predicates.

cardano-rpc/proto/utxorpc/v1beta/query/query.proto

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ message AnyUtxoPattern {
8181

8282
// Represents a simple utxo predicate that can composed to create more complex ones
8383
message UtxoPredicate {
84-
AnyUtxoPattern match = 1; // Predicate is true if tx exhibits pattern.
84+
optional AnyUtxoPattern match = 1; // Predicate is true if tx exhibits pattern.
8585
repeated UtxoPredicate not = 2; // Predicate is true if tx doesn't exhibit pattern.
8686
repeated UtxoPredicate all_of = 3; // Predicate is true if utxo exhibits all of the patterns.
8787
repeated UtxoPredicate any_of = 4; // Predicate is true if utxo exhibits any of the patterns.
@@ -111,10 +111,10 @@ message ReadUtxosResponse {
111111

112112
// Request to search for UTxO based on a pattern.
113113
message SearchUtxosRequest {
114-
UtxoPredicate predicate = 1; // Pattern to match UTxOs by.
114+
optional UtxoPredicate predicate = 1; // Pattern to match UTxOs by.
115115
google.protobuf.FieldMask field_mask = 2; // Field mask to selectively return fields.
116-
int32 max_items = 3; // The maximum number of items to return.
117-
string start_token = 4; // The next_page_token value returned from a previous request, if any.
116+
optional int32 max_items = 3; // The maximum number of items to return.
117+
optional string start_token = 4; // The next_page_token value returned from a previous request, if any.
118118
}
119119

120120
// Response containing the UTxOs that match the requested addresses.
@@ -170,6 +170,7 @@ message ReadTxResponse {
170170
service QueryService {
171171
rpc ReadParams(ReadParamsRequest) returns (ReadParamsResponse); // Get overall chain state.
172172
rpc ReadUtxos(ReadUtxosRequest) returns (ReadUtxosResponse); // Read specific UTxOs by reference.
173+
rpc SearchUtxos(SearchUtxosRequest) returns (SearchUtxosResponse); // Search for UTxO based on a pattern.
173174

174175
// TODO: decide if we want to expand the scope
175176
// rpc DumpUtxos(ReadUtxosRequest) returns (stream ReadUtxosResponse); // Dump all available utxos

cardano-rpc/src/Cardano/Rpc/Proto/Api/UtxoRpc/Query.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ import Proto.Utxorpc.V1beta.Cardano.Cardano_Fields hiding
2727
, vec'values
2828
)
2929
import Proto.Utxorpc.V1beta.Query.Query
30-
import Proto.Utxorpc.V1beta.Query.Query_Fields
30+
import Proto.Utxorpc.V1beta.Query.Query_Fields hiding
31+
( maybe'tx
32+
, tx
33+
)
3134

3235
type instance RequestMetadata (Protobuf QueryService meth) = NoMetadata
3336

cardano-rpc/src/Cardano/Rpc/Proto/Api/UtxoRpc/Submit.hs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,27 @@ import Network.GRPC.Common
1111
import Network.GRPC.Common.Protobuf
1212

1313
import Proto.Utxorpc.V1beta.Submit.Submit
14-
import Proto.Utxorpc.V1beta.Submit.Submit_Fields
14+
import Proto.Utxorpc.V1beta.Submit.Submit_Fields hiding
15+
( allOf
16+
, anyOf
17+
, cardano
18+
, fieldMask
19+
, items
20+
, match
21+
, maybe'cardano
22+
, maybe'chain
23+
, maybe'fieldMask
24+
, maybe'match
25+
, maybe'parsedState
26+
, maybe'predicate
27+
, nativeBytes
28+
, not
29+
, predicate
30+
, vec'allOf
31+
, vec'anyOf
32+
, vec'items
33+
, vec'not
34+
)
1535

1636
type instance RequestMetadata (Protobuf SubmitService meth) = NoMetadata
1737

0 commit comments

Comments
 (0)