Skip to content

Commit

Permalink
fix: load the first 16 bytes of the XUDT cell data (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShookLyngs authored Jun 3, 2024
1 parent ebb098b commit 4c77e69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-actors-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rgbpp-sdk/ckb": patch
---

Fix the XUDT cell data unpacking logic to load only the first 16 bytes
6 changes: 4 additions & 2 deletions packages/ckb/src/collector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toCamelcase } from '../utils/case-parser';
import { CollectConfig, CollectResult, CollectUdtResult, IndexerCell } from '../types/collector';
import { MIN_CAPACITY } from '../constants';
import { CapacityNotEnoughError, IndexerError, UdtAmountNotEnoughError } from '../error';
import { isRgbppLockCellIgnoreChain, leToU128 } from '../utils';
import { isRgbppLockCellIgnoreChain, leToU128, remove0x } from '../utils';
import { Hex } from '../types';

interface IndexerScript {
Expand Down Expand Up @@ -148,7 +148,9 @@ export class Collector {
since: '0x0',
});
sumInputsCapacity = sumInputsCapacity + BigInt(cell.output.capacity);
sumAmount += leToU128(cell.outputData);
// XUDT cell.data = <amount: uint128> <xudt data (optional)>
// Ref: https://blog.cryptape.com/enhance-sudts-programmability-with-xudt#heading-xudt-cell
sumAmount += leToU128(remove0x(cell.outputData).slice(0, 32));
if (sumAmount >= needAmount && !isRgbppLock) {
break;
}
Expand Down

0 comments on commit 4c77e69

Please sign in to comment.