question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide contract choice metadata as constants in contract's class

See original GitHub issue

What is the problem you want to solve?

The upcoming deprecated exercise by key command currently hard codes the choice name such as:

...

  public static ExerciseByKeyCommand exerciseByKeyCreateManager(String key,
      CreateManager arg) {
    return new ExerciseByKeyCommand(Organization.TEMPLATE_ID, new Party(key), "CreateManager", arg.toValue());
  }

..

The choice name is hard coded and cannot be referenced / re-used.

If I create the command manually I would use:

ExerciseCommand(Organization.TEMPLATE_ID, "someContractId", "CreateManager", args)

But again I have to know about the choice name and if the choice name changed in the future, compile time errors would not appear.

What is the solution you would propose?

Could we get the choice names on a contract as constants (or some equivalent) so we can insert them as references?

It would also be helpful to have some contextual information about choices, such as is it a consuming or non-consuming, etc choice, so we can code around expected behaviour: example knowing it is a consuming choice can mean we remove it from the UI on submission (and re-add it if command eventually fails), vs non-consuming we would never remove it. But would settle for just have the constants to start!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
S11001001commented, Sep 7, 2022

TypeScript has a sort of counterpart to this ChoiceMetadata proposal in the Choice type.

https://github.com/digital-asset/daml/blob/a516be732849880c0d24586ab480c081f6da4472/language-support/ts/daml-types/index.ts#L116-L122

Of note, the C and R tparams can be used to drive argument encoding and result decoding in the way I’ve described for ArgType and ResType above:

https://github.com/digital-asset/daml/blob/a516be732849880c0d24586ab480c081f6da4472/language-support/ts/daml-ledger/index.ts#L1104-L1108

0reactions
S11001001commented, Oct 12, 2022

With #15116 merged, the example in description can be written as

-ExerciseCommand(Organization.TEMPLATE_ID, "someContractId", "CreateManager", args)
+ExerciseCommand(Organization.TEMPLATE_ID, "someContractId", Organization.CHOICE_CreateManager.name, args)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Contracts — Solidity 0.8.17 documentation
State variables can be declared as constant or immutable . In both cases, the variables cannot be modified after the contract has been...
Read more >
Structure of a Contract — Vyper documentation - Read the Docs
Contracts in Vyper are contained within files, with each file being one ... State variables are values which are permanently stored in contract...
Read more >
Creating contract status picklist values with the meta data api
The Contract Status field is a process picklist, in lines with Opportunity Stage and Lead Status. These fields are tied to specific object ......
Read more >
Fungible Token Metadata Standard · Discussion #148 · near/NEPs ...
Many smart-contracts need to carry extra information data. Notably, token smart contract should provide minimum information to a user about it's usage.
Read more >
Spring Cloud Contract Features
You can also provide an import to the Contract class ( import ... As with the Java DSL, you can put your contracts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found