Skip to content

Commit db757d7

Browse files
committed
feat(udt): balance related util methods
1 parent e900c59 commit db757d7

File tree

11 files changed

+2456
-61
lines changed

11 files changed

+2456
-61
lines changed

.changeset/plenty-ads-rush.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ckb-ccc/ssri": minor
3+
---
4+
5+
feat(ssri): `ExecutorResponse.mapAsync`
6+

.changeset/shy-horses-agree.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ckb-ccc/udt": minor
3+
---
4+
5+
feat(udt): balance related util methods
6+

packages/core/src/ckb/transaction.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,12 @@ export class Transaction extends mol.Entity.Base<
17371737
);
17381738
}
17391739

1740+
/**
1741+
* @deprecated Use `Udt.getInputsBalance` from `@ckb-ccc/udt` instead
1742+
* @param client
1743+
* @param type
1744+
* @returns
1745+
*/
17401746
async getInputsUdtBalance(client: Client, type: ScriptLike): Promise<Num> {
17411747
return reduceAsync(
17421748
this.inputs,
@@ -1752,6 +1758,11 @@ export class Transaction extends mol.Entity.Base<
17521758
);
17531759
}
17541760

1761+
/**
1762+
* @deprecated Use `Udt.getOutputsBalance` from `@ckb-ccc/udt` instead
1763+
* @param type
1764+
* @returns
1765+
*/
17551766
getOutputsUdtBalance(type: ScriptLike): Num {
17561767
return this.outputs.reduce((acc, output, i) => {
17571768
if (!output.type?.eq(type)) {
@@ -1869,6 +1880,7 @@ export class Transaction extends mol.Entity.Base<
18691880
* This method succeeds only if enough balance is collected.
18701881
*
18711882
* It will try to collect at least two inputs, even when the first input already contains enough balance, to avoid extra occupation fees introduced by the change cell. An edge case: If the first cell has the same amount as the output, a new cell is not needed.
1883+
* @deprecated Use `Udt.completeInputsByBalance` from `@ckb-ccc/udt` instead
18721884
* @param from - The signer to complete the inputs.
18731885
* @param type - The type script of the UDT.
18741886
* @param balanceTweak - The tweak of the balance.

packages/core/src/ckb/transactionErrors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export class ErrorTransactionInsufficientCapacity extends Error {
2222
}
2323
}
2424

25+
/**
26+
* @deprecated Use `ErrorUdtInsufficientCoin` from `@ckb-ccc/udt` instead.
27+
*/
2528
export class ErrorTransactionInsufficientCoin extends Error {
2629
public readonly amount: Num;
2730
public readonly type: Script;

packages/ssri/src/executor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export class ExecutorResponse<T> {
6363
throw new ExecutorErrorDecode(JSON.stringify(err));
6464
}
6565
}
66+
67+
async mapAsync<U>(fn: (res: T) => Promise<U>): Promise<ExecutorResponse<U>> {
68+
try {
69+
return new ExecutorResponse(await fn(this.res), this.cellDeps);
70+
} catch (err) {
71+
throw new ExecutorErrorDecode(JSON.stringify(err));
72+
}
73+
}
6674
}
6775

6876
/**

packages/udt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
},
2525
"scripts": {
26-
"test": "jest",
26+
"test": "vitest",
2727
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
2828
"lint": "eslint ./src",
2929
"format": "prettier --write . && eslint --fix ./src"

0 commit comments

Comments
 (0)