Skip to content
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

feat: add /rgbpp/v1/address/:address/balance for get bound xUDT balance #146

Merged
merged 12 commits into from
May 28, 2024

Conversation

ahonn
Copy link
Contributor

@ahonn ahonn commented May 21, 2024

Changes

add /rgbpp/v1/address/:address/balance for get bound xUDT balance

The implementation logic is as follows:

  • Retrieve UTXO by btc_address (cacheable).
  • Obtain RGB++ assets cell by UTXO (cacheable).
  • Fetch all info cell (Unique Cell/Inscription Info Cell) transactions (cacheable, 2 mins by default).
  • Filter info cell transactions by the type script of RGB++ assets cell.
  • Decode xUDT information (decode from info cell data)
  • Aggregate the xUDT token balance based on the same token information.

Response data example:

  • Unique Cell as Info Cell
{
  "address": "tb1qtt2vh9q8xam35xxsy35ec6majad8lz8fep8w04",
  "xudt": [
    {
      "name": "XUDT Test Token",
      "decimal": 8,
      "symbol": "XTT",
      "typeHash": "0x10f511f2efb0027191b97ac5b4bd77374ffdac7399e8527d76f5f9bd32e7d35b",
      "amount": "0xa7a3582000"
    },
    {
      "name": "RGBPP Test Token",
      "decimal": 8,
      "symbol": "RTT",
      "typeHash": "0xa9d8fff43320bfaeaf4a6071a1b4432568accd6e7342553eb6fb2d12f10d5a42",
      "amount": "0x775d911905800"
    },
    {
      "name": "RGBPP Test Token",
      "decimal": 8,
      "symbol": "RTT",
      "typeHash": "0x9b1e817fc57b12afd068d37687068d80b0d64593b0f87607dd4db667a9d4a49a",
      "amount": "0x775ee05fb5c00"
    }
  ]
}
  • Inscription Info Cell as Info Cell
{
  "address": "tb1qn3my2r0g95wwzf4n4yyyva6mvre5xcc6l72uzk",
  "xudt": [
    {
      "name": "ZooCoin",
      "decimal": 18,
      "symbol": "Zoo",
      "amount": "0xde0b6b3a7640000",
      "typeHash": "0xae9d5b93b0e457eabf8a13626b326e2e4cf75410b2ef5b8348d06d53c0e172c7"
    },
    {
      "name": "CKB Fist Inscription",
      "decimal": 8,
      "symbol": "CKBI",
      "amount": "0xf3d7f1c906",
      "typeHash": "0x7337d2075479d5c6789564516be1db11478e1d3ca70ad88050fe0bf3ff05acc2"
    }
  ]
}
  • Inscription Info Cell as Info Cell (rebased)
{
  "address": "tb1qxxz8nmffa4d5ppzvazm06pla6rjje93dgx3tq8",
  "xudt": [
    {
      "name": "MemesCoin",
      "decimal": 8,
      "symbol": "MEMES",
      "amount": "0x104c533c000",
      "typeHash": "0x92a76e4d65034c586fecab43b8ba8529bfa4f3150a7f7b08062dae4d0c02951e"
    }
  ]
}

References

@ahonn ahonn linked an issue May 21, 2024 that may be closed by this pull request
Copy link

vercel bot commented May 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
btc-assets-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2024 2:06am

@Flouse Flouse requested a review from ShookLyngs May 22, 2024 02:08
@ahonn ahonn force-pushed the 133-get-bound-xudt-balance-by-btc-address branch from a5f1b91 to 3036250 Compare May 22, 2024 08:13
@ahonn ahonn marked this pull request as ready for review May 22, 2024 08:13
src/routes/rgbpp/address.ts Outdated Show resolved Hide resolved
src/routes/rgbpp/address.ts Outdated Show resolved Hide resolved
src/routes/rgbpp/types.ts Outdated Show resolved Hide resolved
src/routes/rgbpp/address.ts Outdated Show resolved Hide resolved
src/routes/rgbpp/address.ts Outdated Show resolved Hide resolved
src/utils/xudt.ts Outdated Show resolved Hide resolved
src/utils/xudt.ts Outdated Show resolved Hide resolved
@ahonn ahonn force-pushed the 133-get-bound-xudt-balance-by-btc-address branch from b017885 to 15d7d15 Compare May 27, 2024 03:43
src/services/ckb.ts Outdated Show resolved Hide resolved
expect(data).toEqual({
decimal: 8,
name: 'XUDT Test Token',
symbol: 'XTT',
Copy link
Contributor

@Flouse Flouse May 27, 2024

Choose a reason for hiding this comment

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

The symbol of https://pudge.explorer.nervos.org/xudt/0x10f511f2efb0027191b97ac5b4bd77374ffdac7399e8527d76f5f9bd32e7d35b is PDD, not XTT.
It might be a bug of Explorer.

Reason

The token owner has issued PDD in a previous tx https://pudge.explorer.nervos.org/transaction/0x6a35da16ab1198008545c78b91abe22999f0dc823055553a13d7de29f3063111

I think we can ignore this situation for now.

Copy link
Contributor

@Flouse Flouse left a comment

Choose a reason for hiding this comment

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

Will you add the unconfirmed balance/amount data type in this PR or another PR?

@ahonn
Copy link
Contributor Author

ahonn commented May 28, 2024

Will you add the unconfirmed balance/amount data type in this PR or another PR?

Yes, I will open a PR for that

@ahonn ahonn force-pushed the 133-get-bound-xudt-balance-by-btc-address branch from 11c0446 to b99a1ad Compare May 28, 2024 01:00
src/services/ckb.ts Outdated Show resolved Hide resolved
@Flouse Flouse requested a review from Dawn-githup May 28, 2024 01:47
@ahonn ahonn merged commit 41ec191 into develop May 28, 2024
4 checks passed
@ahonn ahonn deleted the 133-get-bound-xudt-balance-by-btc-address branch May 28, 2024 02:08

test('getUniqueCellData: should return the unique cell data', async () => {
// XTT (Unique cell transaction)
const tx = await ckb.rpc.getTransaction('0xe6e23718e45a9c36136367dfb1c47397a7b3db2ff130a1c062f40c795f0b103d');
Copy link
Contributor

@Flouse Flouse May 28, 2024

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

Get bound xUDT balance by btc address
3 participants