nervosnetwork / mercury

Building on top of ckb-indexer, Mercury provides handy integration features for Nervos CKB.
MIT License
23 stars 15 forks source link

A way to query for a deposited Nervos DAO balance. #448

Closed jordanmack closed 2 years ago

jordanmack commented 2 years ago

What would you like to be added:

A way to query for a deposited Nervos DAO balance of an address using the Mercury RPC.

Why is this needed:

Wallets and exchanges that want to support the Nervos DAO would benefit from a way to query for a Nervos DAO balance that they can display to their users.

EthanYuan commented 2 years ago

We tried adding an enumeration value to the parameter list of get_balance rpc, which can filter Dao cells, similar to the extra parameter in rpc query_transactions.

When you pass in "extra": "Dao", you can get assets that are only locked in DAO.

Below are 3 examples, please see if they can meet the functional requirements.

https://pudge.explorer.nervos.org/address/ckt1qpvvtay34wndv9nckl8hah6fzzcltcqwcrx79apwp2a5lkd07fdxxqtvuu3ysunhkq9qs54fgwarl40wq0xv5ps4wzq06

echo '{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "get_balance",
  "params": [
    {
      "item": {
        "type": "Address",
        "value": "ckt1qpvvtay34wndv9nckl8hah6fzzcltcqwcrx79apwp2a5lkd07fdxxqtvuu3ysunhkq9qs54fgwarl40wq0xv5ps4wzq06"
      },
      "asset_infos": [
        {
          "asset_type": "CKB",
          "udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
        }
      ],
      "extra": "Dao",
      "tip_block_number": "0x6604e6"
    }
  ]
}' \
| tr -d '\n' \
| curl -H 'content-type: application/json' -d @- http://127.0.0.1:8116
{
  "jsonrpc": "2.0", 
  "result": {
    "balances": [
      {
        "ownership": "ckt1qpvvtay34wndv9nckl8hah6fzzcltcqwcrx79apwp2a5lkd07fdxxqtvuu3ysunhkq9qs54fgwarl40wq0xv5ps4wzq06", 
        "asset_info": {
          "asset_type": "CKB", 
          "udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
        }, 
        "free": "0x56bcdc2cb9", 
        "occupied": "0x0", 
        "frozen": "0x0"
      }
    ], 
    "tip_block_number": "0x6604e6"
  }, 
  "id": 42
}

“original total capacity”:3720 "free": 3725.35733433 "occupied": 0 "frozen": 0

https://pudge.explorer.nervos.org/address/ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqw666wuhvsrj60hpmjyr29y348cuel70fsluaa5p

echo '{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "get_balance",
  "params": [
    {
      "item": {
        "type": "Address",
        "value": "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqw666wuhvsrj60hpmjyr29y348cuel70fsluaa5p"
      },
      "asset_infos": [
        {
          "asset_type": "CKB",
          "udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
        }
      ],
      "extra": "Dao",
      "tip_block_number": "0x6604e6"
    }
  ]
}' \
| tr -d '\n' \
| curl -H 'content-type: application/json' -d @- http://127.0.0.1:8116
{
  "jsonrpc": "2.0", 
  "result": {
    "balances": [
      {
        "ownership": "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqw666wuhvsrj60hpmjyr29y348cuel70fsluaa5p", 
        "asset_info": {
          "asset_type": "CKB", 
          "udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
        }, 
        "free": "0x0", 
        "occupied": "0x25ff7a600", 
        "frozen": "0xaedd84882c7"
      }
    ], 
    "tip_block_number": "0x6604e6"
  }, 
  "id": 42
}

“original total capacity“: 120,000 "free": 0 "occupied": 102 "frozen": 120166.52157639

https://pudge.explorer.nervos.org/address/ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqghlgmq3hd8eczvd3ms52wker8l5p3qf6gx4vuwv

echo '{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "get_balance",
  "params": [
    {
      "item": {
        "type": "Address",
        "value": "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqghlgmq3hd8eczvd3ms52wker8l5p3qf6gx4vuwv"
      },
      "asset_infos": [
        {
          "asset_type": "CKB",
          "udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
        }
      ],
      "extra": "Dao",
      "tip_block_number": "0x65fef0"
    }
  ]
}' \
| tr -d '\n' \
| curl -H 'content-type: application/json' -d @- http://127.0.0.1:8116
{
  "jsonrpc": "2.0", 
  "result": {
    "balances": [
      {
        "ownership": "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqghlgmq3hd8eczvd3ms52wker8l5p3qf6gx4vuwv", 
        "asset_info": {
          "asset_type": "CKB", 
          "udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
        }, 
        "free": "0x0", 
        "occupied": "0x25ff7a600", 
        "frozen": "0xe674ad6a00"
      }
    ], 
    "tip_block_number": "0x65fef0"
  }, 
  "id": 42
}

"original total capacity": 10000

EthanYuan commented 2 years ago

PR:

EthanYuan commented 2 years ago

Mercury v0.4.4 has been released and the public service(https://mercury-mainnet.ckbapp.dev/0.4) has been updated.