Skip to content
Discussions/App Development/Java gRPC - Get Contract By ContractIdForum ↗

Java gRPC - Get Contract By ContractId

App Development5 posts211 views2 likesLast activity Jun 2022
PR
prajwalhegde3OP
Jun 2022

Hi All,

I’m trying to fetch contract by Id using Java gRPC. Can anyone help me understand what is the difference between TransactionFilter & InclusiveFilter


TransactionServiceStub transactionService = TransactionServiceGrpc.newStub(channel);

		GetTransactionsRequest transactionsRequest = GetTransactionsRequest.newBuilder()
				.setLedgerId(grpcCommonObj.ledgerId)
				.setBegin(LedgerOffset.newBuilder().setBoundary(LedgerOffset.LedgerBoundary.LEDGER_BEGIN))
				.setFilter(TransactionFilter.newBuilder().putFiltersByParty(user, Filters.getDefaultInstance()))
				.build();
ST
stefanobaghino-da
Jun 2022

The TransactionFilter is an object that holds a generic predicate that you can use to filter flat transactions (i.e. contract state changes). Within it, you can have one of several possible predicates. In practice, right now this boils down to either NoFilter or an instance of InclusiveFilter, which specifies a positive predicate, in particular with regards to a set of template IDs. Note that you can filter by template ID only when querying for flat transactions (as you are doing in your snippet) but not for transaction trees (where the Ledger API querying capabilities are limited to specifying parties on behalf of which you’re reading).

PR
prajwalhegde3
Jun 2022

Thanks for the explanation @stefanobaghino-da.

But I’m still unable to achieve the filtering of contracts by Id. Any help with the code is appreciated.

Thank you!!

CO
cocreature
Jun 2022

There is no server side filtering by contract id via the gRPC API. You have to fetch all contracts of a given template and filter on the client side. If you do that frequently, you can keep a custom ods and index by contract id to make that more efficient.

PR
prajwalhegde3
Jun 2022

Thank you @cocreature

← Back to Discussions