Skip to content

Commit c0893f1

Browse files
committed
feat(udt): Udt.complete* methods
1 parent e2ce0a2 commit c0893f1

File tree

11 files changed

+2292
-61
lines changed

11 files changed

+2292
-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): `Udt.complete*` methods
6+

packages/core/src/ckb/transaction.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,12 @@ export class Transaction extends mol.Entity.Base<
19111911
);
19121912
}
19131913

1914+
/**
1915+
* @deprecated Use `Udt.getInputsBalance` from `@ckb-ccc/udt` instead
1916+
* @param client
1917+
* @param type
1918+
* @returns
1919+
*/
19141920
async getInputsUdtBalance(client: Client, type: ScriptLike): Promise<Num> {
19151921
return reduceAsync(
19161922
this.inputs,
@@ -1926,6 +1932,11 @@ export class Transaction extends mol.Entity.Base<
19261932
);
19271933
}
19281934

1935+
/**
1936+
* @deprecated Use `Udt.getOutputsBalance` from `@ckb-ccc/udt` instead
1937+
* @param type
1938+
* @returns
1939+
*/
19291940
getOutputsUdtBalance(type: ScriptLike): Num {
19301941
return this.outputs.reduce((acc, output, i) => {
19311942
if (!output.type?.eq(type)) {
@@ -2043,6 +2054,7 @@ export class Transaction extends mol.Entity.Base<
20432054
* This method succeeds only if enough balance is collected.
20442055
*
20452056
* 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.
2057+
* @deprecated Use `Udt.completeInputsByBalance` from `@ckb-ccc/udt` instead
20462058
* @param from - The signer to complete the inputs.
20472059
* @param type - The type script of the UDT.
20482060
* @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)