Skip to content

Add more possibilities to call contract messages #4469

Open
@VargSupercolony

Description

@VargSupercolony

The problem

The problem right now is that contract messages (txs & queries), which have a trait prefix, are only callable like myTraitMyMethod. Previously, the stringCamelCase function allowed commas, so we could differentiate between message name and trait name when calling the functions. Like this:

const myContractCallOutcome: ContractCallOutcome = await myContract.query['MyTrait,myMethod'](...)

But now, as the stringCamelCase function replaces the commas with whitespace (and camelCases the trait), it means we have only one way to call a contract function:

const myContractCallOutcome: ContractCallOutcome = await myContract.query.myTraitMyMethod(...)

As the trait names may grow longer, we end up calling simple methods like this:

const myContractCallOutcome: ContractCallOutcome = await myContract.query.myVeryLongTraitNameBalanceOf(...)

In some cases, we don't want the frontend calls to contain the trait names, and with this approach, it is almost impossible to remove the trait prefixes without doing hacks.

Proposed solution

The proposed solution is following:

  1. For ink v3.0.0-rc6, as the trait names and method names are separated by a comma, leave a comma there, camelCase the method name and write to the query object. (Ends up like myContract.query['MyTrait,myMethod'])
  2. For ink v3.0.0-rc7 and potentially later versions, as the trait names and methods are separated by ::, add the unchanged generated identifier to the query and tx objects. (Ends up like myContract.query['MyTrait::my_method'])
  3. Regardless of the version, add the camelCased version of call as it is now. (Ends up like myContract.tx.myTraitMyMethod)

In the end, we want to end up with several ways to call the same ABI message.

I would be pleased to work on this issue personally if you need my help :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions