Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typed ACS and transaction streams for Java codegen #14969

Closed
S11001001 opened this issue Sep 7, 2022 · 4 comments · Fixed by #15159
Closed

typed ACS and transaction streams for Java codegen #14969

S11001001 opened this issue Sep 7, 2022 · 4 comments · Fixed by #15159
Assignees
Labels
component/java-ecosystem Java development experience ledger clients facade enriching the ledger API by bindings/codegen, JSON API, custom view team/ledger-clients Related to the Ledger Clients team's components.

Comments

@S11001001
Copy link
Contributor

S11001001 commented Sep 7, 2022

What is the problem you want to solve?

The highest-level subscription to read contracts we offer in Java looks like this:

Flowable<Transaction> getTransactions(
LedgerOffset begin, TransactionFilter filter, boolean verbose);

It requires

  1. knowing how to assemble a TransactionFilter, and
  2. knowing how to decode the result from Transaction.

By contrast, in TypeScript, we offer

async query<T extends object, K, I extends string>(
template: TemplateOrInterface<T, K, I>,
query?: Query<T>,
): Promise<CreateEvent<T, K, I>[]> {

export function useQuery<T extends object, K, I extends string>(
template: Template<T, K, I>,
): QueryResult<T, K, I>;

This hides the mechanics of the relationship between template/interface IDs and the payload format, yielding decoded contracts as a result. Consider CreateEvent above, for example: instead of generic Record createArguments, the payload type matches what you queried.

What is the solution you would propose?

From codegen decoders #14313 , we can produce utility methods that

  1. yield proper TransactionFilters for given party sets, with template or interface selected according to underlying contract-type-type, and
  2. decoders to extract well-typed template payloads or interface views from transactions or ACS responses.

Moreover, these can then be combined into single utility calls to take ContractTypeCompanions and yield well-typed, decoded stream results.

Only a bare minimum of #14313 is needed for this feature: define FromValue, and define how it is derived from TemplateCompanion. Then it becomes possible to write and test the aforementioned utility methods. With #15125, we can consider interface support.

Describe alternatives you've considered

A single ContractTypeCompanion is sufficient to handle all sorts of single-interface or single-template streaming requests. For streaming multiple templates/interfaces at once, you need a combinator language to unify disparate payload types. This is similar to the problem of submitting multiple commands with the API proposed by #14312, and may invite similar thinking.

Additional context

When we decided to unify interface views and template payloads in JSON query, that yielded a TypeScript API that looked exactly the same from a user perspective as the present templates API. "Interface view is contract payload" is a nice way to transition from working with template payloads.

Moreover, while #14313 has been largely considered in terms of choice exercise utilities like #14329, it is equally useful for improving codegen integration into the bindings in this category.

@S11001001 S11001001 added component/java-ecosystem Java development experience team/ledger-clients Related to the Ledger Clients team's components. ledger clients facade enriching the ledger API by bindings/codegen, JSON API, custom view labels Sep 7, 2022
@chunlokling-da chunlokling-da self-assigned this Sep 30, 2022
@chunlokling-da
Copy link
Contributor

chunlokling-da commented Oct 4, 2022

yield proper TransactionFilters for given party sets, with template or interface selected according to underlying contract-type-type, and
decoders to extract well-typed template payloads or interface views from transactions or ACS responses.

I think the template / interface Companion will be the good place for these utility methods, agree?

@S11001001
Copy link
Contributor Author

I think the template / interface Companion will be the good place for these utility methods, agree?

No, I think a static method on TransactionFilter would probably be better.

@chunlokling-da
Copy link
Contributor

No, I think a static method on TransactionFilter would probably be better

How to access Companion in these method? by passing in as a parameter?

public abstract class TransactionFilter {
  public static TransactionFilter transactionFilter(ContractTypeCompanion<?, ?> contractCompanion , Set<String> parties) 
  {
    ...
  }
}

@chunlokling-da
Copy link
Contributor

I have moved transactionFilter from TransactionFilter to ContractUtil, please review the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/java-ecosystem Java development experience ledger clients facade enriching the ledger API by bindings/codegen, JSON API, custom view team/ledger-clients Related to the Ledger Clients team's components.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants