ckb-cell / rgbpp-sdk

Utilities for Bitcoin and RGB++ asset integration
ISC License
53 stars 16 forks source link

refactor(rgbpp): calculate XUDT amount separately in AssetSummarizer #275

Closed ShookLyngs closed 4 weeks ago

ShookLyngs commented 4 weeks ago

Changes

The XUDT/DOB summary issue

Previously, when calculating AssetSummary, DOBs were treated as regular XUDT cells. This led to inaccuracies in the calculation of the total containing amount of an XUDT asset because the data for DOBs was treated as XUDT amounts and added to the summary result, while in reality, the data for DOBs differs from that of XUDT cells.

For example, the following asset summary includes a very large amount that looks unusual at first glance:

result.summary.excluded.assets {
  '0xdec25e81ad1d5b909926265b0cdf404e270250b9885d436852b942d56d06be38': { utxoCount: 1, cellCount: 1, amount: 1000000000n },
  '0x578ff15dfe17f0896cfa05501aaa400aa1cb1bbb519e96ae4077e7f61b5d894a': {
    utxoCount: 1,
    cellCount: 1,
    amount: 3644495476209561851583027740754n
  }
}

This PR ensures the accuracy of the XUDT total containing amount calculation by adding a check statement while iterating through each cell related to a UTXO. However, the summary calculation for those non-XUDT assets has not been implemented:

for (const cell of cells) {
  const isXudt = !!cell.cellOutput.type && isUDTTypeSupported(cell.cellOutput.type, this.isMainnet);
  if (isXudt) {
    // If the cell type is a supported xUDT type, record its asset information
    ...
  } else {
    // TODO: If the cell type is empty or not xUDT, how should we handle/record its info?
  }
}