Skip to content

rpcserver: add decimal display to asset stats rpc #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jamaljsr
Copy link
Member

In Terminal, we'd like to display the asset supply value with the decimal point based on the decimal_display included in the metadata. We use the QueryAssetStats REST endpoint to fetch assets from the universe server. Currently, the decimal display isn't included in the response.

This PR adds this field to each asset in the response if it was specified in the metadata when minting. I've tested with grouped & non-grouped assets, with and without a decimal_display set.

Here's what the updated response looks like:

{
    "asset_stats": [
        {
            "group_key": "",
            "group_supply": "0",
            "group_anchor": null,
            "asset": {
                "asset_id": "4b69c0f4aeb49ffc22822eb2c26590cedcf6900e6a72bcabbdbc9353f2709554",
                "genesis_point": "dea7f9185efb9554c149516956c0adb3fe8041dbcfead0852212f7d4622166d3:1",
                "total_supply": "1000000",
                "asset_name": "NoGroup",
                "asset_type": "NORMAL",
                "genesis_height": 329,
                "genesis_timestamp": "1748353581",
                "anchor_point": "9da69d2096225bb8ff8220ee1c05fa381e0654743bebb1c31f23c73d5894d9a5:0",
                "decimal_display": 3
            },
            "total_syncs": "0",
            "total_proofs": "1"
        },
        {
            "group_key": "03f54ee69f2ef8caaf7618d334a23c4f141ca0d275943a49fceeeba4dfe84545e5",
            "group_supply": "600000",
            "group_anchor": {
                "asset_id": "4c9ce145d903d303d4d2da125f5cf7a95bf874db3db76188c5e049c4c1a5e2a0",
                "genesis_point": "47e19c099260f609b7a5d4f5beb16df109098ee78714e07330d9e6f6e5b04dd8:1",
                "total_supply": "100000",
                "asset_name": "WithGroup",
                "asset_type": "NORMAL",
                "genesis_height": 303,
                "genesis_timestamp": "1748351609",
                "anchor_point": "052627e9b1da0f79a539c03aaff984ffe171a5df4cf55d8cef337b81d3054b46:0",
                "decimal_display": 2
            },
            "asset": null,
            "total_syncs": "0",
            "total_proofs": "3"
        },
        {
            "group_key": "",
            "group_supply": "0",
            "group_anchor": null,
            "asset": {
                "asset_id": "8b8b8c39c2bbe9a4da518ccf76728108edb9cbd544c3b8717dad2bbafbbf9e06",
                "genesis_point": "9da69d2096225bb8ff8220ee1c05fa381e0654743bebb1c31f23c73d5894d9a5:1",
                "total_supply": "1000",
                "asset_name": "NoDecimals",
                "asset_type": "NORMAL",
                "genesis_height": 335,
                "genesis_timestamp": "1748354548",
                "anchor_point": "caaa428cf8ffba920fbff77812ed201fa5915862145b3bf5a071d0ef362ad9e2:0",
                "decimal_display": 0
            },
            "total_syncs": "0",
            "total_proofs": "1"
        },
    ]
}

My biggest concern with the approach I took here is the performance implications of looking up the decimal display at the rpcserver level, so this compute isn't cached along with the other queried data. This RPC is already pretty slow, and adding more to it may likely degrade performance further. I couldn't figure out how to obtain the decimal display in the QuerySyncStats function, which would include the results in the cache. Please let me know if there are any better ways of doing this.

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM 🎉

@coveralls
Copy link

Pull Request Test Coverage Report for Build 15277888381

Details

  • 0 of 5 (0.0%) changed or added relevant lines in 1 file are covered.
  • 33 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.05%) to 37.122%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcserver.go 0 5 0.0%
Files with Coverage Reduction New Missed Lines %
commitment/tap.go 1 72.05%
internal/test/helpers.go 2 86.48%
tapchannel/aux_leaf_signer.go 2 43.08%
address/address.go 6 67.47%
tapdb/multiverse.go 6 53.03%
address/mock.go 16 88.24%
Totals Coverage Status
Change from base Build 15255103485: -0.05%
Covered Lines: 26972
Relevant Lines: 72658

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants