RGB-WG / rgb

RGB smart contracts: command-line tool & wallet runtime library for desktop and mobile integration
https://rgb.tech
Apache License 2.0
140 stars 36 forks source link

Contract state after issuance shows human-unreadable owned amount #209

Closed nicbus closed 5 months ago

nicbus commented 5 months ago

I have updated rgb-sandbox to the 0.11.0-beta.6 version of rgb-wallet and rgb-schemata.

The run proceeds up to the issuance, which completes with success, but then the contract state doesn't show the correct owned amount.

This is the used contract yaml:

interface: RGB20Fixed

globals:
  spec:
    ticker: USDT
    name: USD Tether
    details: ~
    precision: 0
  terms:
    text: demo NIA asset
    media: ~
  issuedSupply: 2000

assignments:
  assetOwner:
    seal: opret1st:68d478417c6fa5f6382c37f53cc9d53dd6123eee78b845330a6230c85664bbb8:0
    amount: 2000

This is the issuance command:

$ rgb-wallet/bin/rgb -n regtest --electrum=localhost:50001 -d data0 issue -w wallet_0 'KzMZV9bO7gFhox97!klj0FonG2ZKnjuOIg2tFChu$YA#lucas-episode-silicon' ssi:wallet_0 contracts/usdt.yaml

A new contract rgb:sZdo3p$Z-Krwmb1e-3S!4ITe-sOj6rhq-SzSJRu1-0H77oes is issued and added to the stash.
Use `export` command to export the contract.

This is the contract state after issuance:

$ rgb-wallet/bin/rgb -n regtest --electrum=localhost:50001 -d data0 state -w wallet_0 'rgb:sZdo3p$Z-Krwmb1e-3S!4ITe-sOj6rhq-SzSJRu1-0H77oes' RGB20Fixed

Loading descriptor from wallet wallet_0 ... success

Global:
  spec := (ticker=("USDT"), name=("USD Tether"), details=~, precision=0)
  terms := (text=("demo NIA asset"), media=~)
  issuedSupply := (2000)

Owned:
  assetOwner:
    value=TadF, utxo=bc:opret1st:68d478417c6fa5f6382c37f53cc9d53dd6123eee78b845330a6230c85664bbb8:0, witness=~

These are the unspents after the issuance:

$ rgb-wallet/bin/rgb -n regtest --electrum=localhost:50001 -d data0 utxos -w wallet_0
Loading descriptor from wallet wallet_0 ... success

Height     Amount, ṩ    Outpoint
bcrt1qczcwdghm2m7vma5p6m82jg6xgv9lfkhwtzha0s    &9/0
104        100000000    68d478417c6fa5f6382c37f53cc9d53dd6123eee78b845330a6230c85664bbb8:0

Loading descriptor from wallet wallet_0 ... success

Wallet total balance: 100000000 ṩ

This is the data directory for wallet 0: wallet_0.tar.gz

dr-orlovsky commented 5 months ago

Well, this is correct amount, just encoded with the same encoding we use in invoices (non-human readable - base32, only letters, no numbers). Why? Since at this level we do not use interface and thus know nothing about contract precision (and it can be not even a RGB20 contract). Thus, the only way to check the owned amount in meaningful way is to interface contract through one of RGB20 interfaces - and this should be working

nicbus commented 5 months ago

the only way to check the owned amount in meaningful way is to interface contract through one of RGB20 interfaces

I don't see a way to do this via CLI (rgb-wallet) at the moment.

I was able to have the human-readable amount displayed by modifying the state command to return allocation.state.value() instead of allocation.state as the value field. I think this makes sense, as that's already happening only for fungible contracts. I can open a PR with this tiny change if you agree.

dr-orlovsky commented 5 months ago

the only way to check the owned amount in meaningful way is to interface contract through one of RGB20 interfaces

This has to be added as a dedicated command.

I was able to have the human-readable amount displayed by modifying the state command to return allocation.state.value() instead of allocation.state as the value field. I think this makes sense, as that's already happening only for fungible contracts. I can open a PR with this tiny change if you agree.

I am fine with that. I am still a little confused why do we need to display something of no meaning - and asset value has no meaning unless it is equipped with precision information coming from RGB20 interfaces

nicbus commented 5 months ago

This has to be added as a dedicated command.

I think the state command is still a good place to report this info, as it's showing the global state (which includes the precision) and the allocations. It just currently shows a value that the user cannot interpret.

I am fine with that. I am still a little confused why do we need to display something of no meaning - and asset value has no meaning unless it is equipped with precision information coming from RGB20 interfaces

IMO rgb-wallet's CLI needs to give users a way to interact with contracts, amounts included. Having the amount as an integer looks ok to me and it would also stay in sync with the invoice command, which also takes the amount as an integer.

I see the point in having the precision information as well, but I think having it displayed as part of the "Global" section is enough.

After all, the CLI is not providing a full-fledged interface to RGB and all its features, bells and whistles. Rather, if I understood it correctly, it's trying to give a simple and easy to use interface that also tries to remain quite agnostic towards RGB internals. For these reasons I'm not worried about having a fractional amount that includes the precision and would just restore the basic CLI functionality with the suggested change.

dr-orlovsky commented 5 months ago

Ok, argument that precision is in the global state makes sense, so I do agree. I can do the change - or do you want to do it?

nicbus commented 5 months ago

It's a simple (one line) change I already have tested locally, so I'll take care of opening a PR for this.