@ickb/core
Version:
iCKB Core utils built on top of CCC
84 lines • 2.56 kB
JavaScript
import { ccc } from "@ckb-ccc/core";
import { getHeader, } from "@ickb/utils";
import { OwnerData, ReceiptData } from "./entities.js";
import { ickbValue } from "./udt.js";
import { daoCellFrom } from "@ickb/dao";
const isIckbDepositSymbol = Symbol("isIckbDeposit");
export async function ickbDepositCellFrom(options) {
const daoCell = "maturity" in options ? options : await daoCellFrom(options);
return {
...daoCell,
udtValue: ickbValue(daoCell.cell.capacityFree, daoCell.headers[0].header),
[isIckbDepositSymbol]: true,
};
}
export async function receiptCellFrom(options) {
const cell = "cell" in options
? options.cell
: await options.client.getCell(options.outpoint);
if (!cell) {
throw Error("Cell not found");
}
const txHash = cell.outPoint.txHash;
const header = {
header: await getHeader(options.client, {
type: "txHash",
value: txHash,
}),
txHash,
};
const { depositQuantity, depositAmount } = ReceiptData.decode(cell.outputData);
return {
cell,
header,
ckbValue: cell.cellOutput.capacity,
udtValue: ickbValue(depositAmount, header.header) * depositQuantity,
};
}
export class WithdrawalGroup {
constructor(owned, owner) {
Object.defineProperty(this, "owned", {
enumerable: true,
configurable: true,
writable: true,
value: owned
});
Object.defineProperty(this, "owner", {
enumerable: true,
configurable: true,
writable: true,
value: owner
});
}
get ckbValue() {
return this.owned.ckbValue + this.owner.cell.cellOutput.capacity;
}
get udtValue() {
return this.owned.udtValue;
}
}
export class OwnerCell {
constructor(cell) {
Object.defineProperty(this, "cell", {
enumerable: true,
configurable: true,
writable: true,
value: cell
});
Object.defineProperty(this, "udtValue", {
enumerable: true,
configurable: true,
writable: true,
value: 0n
});
}
get ckbValue() {
return this.cell.cellOutput.capacity;
}
getOwned() {
const { txHash, index } = this.cell.outPoint;
const { ownedDistance } = OwnerData.decodePrefix(this.cell.outputData);
return new ccc.OutPoint(txHash, index + ownedDistance);
}
}
//# sourceMappingURL=cells.js.map