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

Exercise by key #4049

Merged
merged 8 commits into from
Jan 18, 2020
Merged

Exercise by key #4049

merged 8 commits into from
Jan 18, 2020

Conversation

leo-da
Copy link
Contributor

@leo-da leo-da commented Jan 14, 2020

Closes: #4009

TODO

  • Remove reference field, actually flatten it.
  • Update documentation, once reference field is removed.

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

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.

@leo-da leo-da force-pushed the leo-4009-exercise-by-key branch from dc15468 to 93966b0 Compare January 15, 2020 18:55
@digitalasset-cla
Copy link
Member

digitalasset-cla commented Jan 15, 2020

CLA assistant check
All committers have signed the CLA.

@leo-da leo-da marked this pull request as ready for review January 15, 2020 21:11
@leo-da leo-da requested review from S11001001 and hurryabit January 15, 2020 21:11
Copy link
Contributor

@S11001001 S11001001 left a comment

Choose a reason for hiding this comment

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

LGTM modulo forthcoming docs, but @hurryabit may prefer that reference's JSON format always be flattened within the containing object, which is unambiguous and also backward-compatible with the current API.

@leo-da
Copy link
Contributor Author

leo-da commented Jan 15, 2020

LGTM modulo forthcoming docs, but @hurryabit may prefer that reference's JSON format always be flattened within the containing object, which is unambiguous and also backward-compatible with the current API.

Yep, I thought about keeping the existing format. But decided to change it so it is consistent with our domain model. However if @hurryabit insists, reference field can be flattened, manual JSON reader will need to be implemented.

@@ -189,8 +189,10 @@ class Ledger {
*/
async exercise<T extends object, C, R>(choice: Choice<T, C, R>, contractId: ContractId<T>, argument: C): Promise<[R , Event<object>[]]> {
const payload = {
templateId: choice.template().templateId,
contractId,
reference: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? I think the old API was fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because reference can be of ContractLocator type:

  sealed abstract class ContractLocator[+LfV] extends Product with Serializable

  final case class EnrichedContractKey[+LfV](
      templateId: TemplateId.OptionalPkg,
      key: LfV
  ) extends ContractLocator[LfV]

  final case class EnrichedContractId(
      templateId: Option[TemplateId.OptionalPkg],
      contractId: domain.ContractId
  ) extends ContractLocator[Nothing]

Copy link
Contributor Author

@leo-da leo-da Jan 15, 2020

Choose a reason for hiding this comment

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

you see it groups templateId with key and optional templateId with contractId. That is what I currently have in my domain model, which I am not going to flatten that is for sure (I assumed you wanted to have something similar in TypeScript)... JSON can be flattened, but I think reference field kind of makes sense. Again up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

plus I hate writing JSON formatters manually :), if we have a reference field, the formatter can be completely derived.

@leo-da leo-da force-pushed the leo-4009-exercise-by-key branch from db78b00 to 7053493 Compare January 16, 2020 22:06
@leo-da
Copy link
Contributor Author

leo-da commented Jan 16, 2020

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

fields += "choice" -> obj.choice.toJson
fields += "argument" -> obj.argument.toJson
if (obj.meta.isDefined)
fields += "meta" -> obj.meta.toJson
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no value here from not building fields in the functional style; use ++.

Copy link
Contributor

@hurryabit hurryabit left a comment

Choose a reason for hiding this comment

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

The API and the docs look good to me. Many thanks.

I'll leave the review of the implementation and the approval to @S11001001.

@leo-da leo-da merged commit c8c55c4 into master Jan 18, 2020
@leo-da leo-da deleted the leo-4009-exercise-by-key branch January 18, 2020 14:06
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.

Implement Exercise by Key
4 participants