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

Add contract keys to created events in the Ledger API #1586

Merged
merged 12 commits into from Jun 14, 2019

Conversation

stefanobaghino-da
Copy link
Contributor

@stefanobaghino-da stefanobaghino-da commented Jun 11, 2019

Fixes #1268

Pull Request Checklist

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

@stefanobaghino-da stefanobaghino-da force-pushed the ledger-api-contract-keys branch 3 times, most recently from 4426faa to 861f85c Compare June 11, 2019 16:39
@stefanobaghino-da stefanobaghino-da marked this pull request as ready for review June 11, 2019 16:39
@stefanobaghino-da
Copy link
Contributor Author

Note

I would greatly benefit from some input from either @S11001001 or @leo-da on how to reflect this change in the Scala bindings (so that this information can also be added to the navigator).

@gerolf-da suggested using a type dependent type on Templates, which seemed reasonable but didn't lead me anywhere. If you could provide some guidance on how you think this change can be added, it would really help me.

@stefanobaghino-da
Copy link
Contributor Author

Nonetheless, I would consider merging this PR as-is (modulo the review) and add the Scala bindings and navigator support for contract keys as a separate contribution (just to keep things simple).

@stefanobaghino-da stefanobaghino-da force-pushed the ledger-api-contract-keys branch 4 times, most recently from d99c68b to 33bb02e Compare June 12, 2019 16:45
Copy link
Contributor

@gerolf-da gerolf-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @stefanobaghino-da.

Copy link
Contributor

@gerolf-da gerolf-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @stefanobaghino-da 👍

@stefanobaghino-da
Copy link
Contributor Author

@S11001001 your explicit approval is required in order to merge this PR.

@stefanobaghino-da
Copy link
Contributor Author

As discussed off-band with @gerolf-da, it would be desirable to improve the codegen by exposing contract keys

  1. only if they are defined over the template, and
  2. with the generated type rather then the raw bindings Value

Copy link
Contributor

@gerolf-da gerolf-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, please only generate a contract key field in the java codegen of the right type if there is an key defined in the model.

stefanobaghino-da added a commit that referenced this pull request Jun 14, 2019
Also adds support in daml-lf/interface for contract keys

Addresses #1586 (review)
@stefanobaghino-da
Copy link
Contributor Author

@gerolf-da The latest commit should fix it, thanks for the guidance.

@S11001001 I added contract keys support to the interface reader, you may want to have a look at it.

contractKeyFieldName)
} else {
spec.addStatement(
"return new $T($L, $L, $L)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could build up the return statement with something like the following to avoid having to duplicate the statement itself:

val names = Vector(idFieldName, dataFieldName, agreementFieldName) ++ maybeContractKeyClassName.map(_ => contractKeyFieldName)
val params = names.map(n => CodeBlock.of("$L", n)).asJava
val allParams = CodeBlock.join(params, ", ")
spec.addStatement("return new $T($L)", className, params)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both my Scala and my javapoet became rusty after the last few months. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 4249373

Copy link
Contributor

@gerolf-da gerolf-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, @stefanobaghino-da. Very smoothly integrated. 👏
Only had 1 comment that you could also apply to other places in this commit where you find you had to duplicate code depending on whether the key was defined or not.

stefanobaghino-da added a commit that referenced this pull request Jun 14, 2019
Copy link
Contributor

@gerolf-da gerolf-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

stefanobaghino-da and others added 12 commits June 14, 2019 18:11
…/digitalasset/platform/tests/integration/ledger/api/TransactionServiceIT.scala

Co-Authored-By: Stephen Compall <scompall@nocandysw.com>
…ledger/rxjava/grpc/helpers/TransactionGenerator.scala

Co-Authored-By: Stephen Compall <scompall@nocandysw.com>
…/digitalasset/platform/tests/integration/ledger/api/TransactionServiceIT.scala

Co-Authored-By: Stephen Compall <scompall@nocandysw.com>
…orm/participant/util/LfEngineToApi.scala

Co-Authored-By: Stephen Compall <scompall@nocandysw.com>
Applies the suggestion introduced by 7cc5c3e
Also adds support in daml-lf/interface for contract keys

Addresses #1586 (review)
private val getArguments = CodeBlock.of("event.getArguments()")
private val getAgreementText = CodeBlock.of("event.getAgreementText()")
private def getContractKey(t: TypeName) =
CodeBlock.of("event.getContractKey().map($T::fromValue)", t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this seems to not work as expected when t is a TupleN for some N.
The fromValue functions for tuples expect additional arguments to convert the components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally right, fixed by #1743, thanks for the detailed report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add key to CreatedEvent in API
4 participants