hyperledger-iroha / iroha-python

Python library for Hyperledger Iroha, a simple distributed ledger.
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
103 stars 81 forks source link

How to mint asset in iroha v2 python SDK? #154

Closed sokunthaneth-nbc closed 1 year ago

sokunthaneth-nbc commented 1 year ago

The snippet to mint asset in the documentation doesn't work. Please revise.

amount = Expression(Value(U32(42)))
destination = Expression(Value(Identifiable(asset.DefinitionId.parse("rose#wonderland"))))
mint_amount = Mint(amount, destination)
cl.submit_isi(mint_amount)

The error

Traceback (most recent call last):
  File "/home/test-python-sdk-v2/asset.py", line 52, in <module>
    mint_asset()
  File "/home/test-python-sdk-v2/asset.py", line 39, in mint_asset
    hash = cl.submit_isi(mint)
  File "/home/iroha-python/venv/lib/python3.10/site-packages/iroha2/__init__.py", line 26, in submit_isi
    return self.submit_tx([_Instruction(isi)])
  File "/home/iroha-python/venv/lib/python3.10/site-packages/iroha2/__init__.py", line 23, in submit_tx
    return self.cl.submit_all_with_metadata(tx, {})
Exception: Error: data did not match any variant of untagged enum ExpressionDeserializeWrapper
    0: data did not match any variant of untagged enum ExpressionDeserializeWrapper
QuentinI commented 1 year ago

Apologies for lacking documentation Here's how it's supposed to look like:

asset_id = asset.Id("time#wonderland", "alice@wonderland")
destination = Expression(Value.Id(Id.AssetId(asset_id)))
amount = Expression(Value.U32(42))
mint_amount = Mint(amount, destination)
cl.submit_isi(mint_amount)

I trust @6r1d will update documentation accordingly. I have also just pushed a new commit to iroha2-edge branch that should've smoothed out possible inconsistencies in schema which I would advise to pull.

I'm closing the issue for now, please feel free to re-open if you encounter any further problems.