iroha-python icon indicating copy to clipboard operation
iroha-python copied to clipboard

Replace structures with methods in the Python API

Open appetrosyan opened this issue 3 years ago • 0 comments

The current approach of creating lots of objects is not very pythonic. It would be preferable, if instead we had a way of using dick-typing and methods + keyword arguments to set things up.

Example

As of today our example contains the following:

asset_definition = asset.Definition(
    "pyasset#python",
    asset.ValueType.Quantity(),
    asset.Mintable.Infinitely(),
)

In reality what we should have

asset_definition = asset.definition("pyasset#python", value_type = "q", mintable=True)

Where the method handles the conversion of the shorthand notation of "q" into Quantity, mintable=True into Mintable.Infinitely and not specifying them creates an asset with sensible defaults (which are Quantity and Mintable.Infinitely).

We can also treat the rust FromStr methods to do the conversion in place.

appetrosyan avatar Aug 05 '22 07:08 appetrosyan