From d1056b07b92d439f6532cff4b72ded2b1effa373 Mon Sep 17 00:00:00 2001 From: Alive24 Date: Tue, 7 Jan 2025 22:01:28 +0000 Subject: [PATCH] fix: minor fix --- packages/ssri/src/ssri/index.ts | 2 +- packages/udt/src/udt/index.ts | 66 ++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/ssri/src/ssri/index.ts b/packages/ssri/src/ssri/index.ts index e95171df..3d2949a9 100644 --- a/packages/ssri/src/ssri/index.ts +++ b/packages/ssri/src/ssri/index.ts @@ -124,7 +124,7 @@ export class Server { | { cell: ccc.CellLike } | { transaction: ccc.TransactionLike }, ): Promise { - const pathHex = ccc.hashCkb(ccc.bytesFrom(path)); + const pathHex = ccc.hashCkb(ccc.bytesFrom(path, "utf8")).slice(0, 18); const parsedArgsHex = argsHex.map((arg) => ccc.hexFrom(arg)); const payload = { id: 2, diff --git a/packages/udt/src/udt/index.ts b/packages/udt/src/udt/index.ts index e35711ae..16919426 100644 --- a/packages/udt/src/udt/index.ts +++ b/packages/udt/src/udt/index.ts @@ -58,8 +58,7 @@ export class UDT extends ssri.Contract { * @tag Legacy - Supports xUDT legacy behavior. */ async name(): Promise { - const hasMethod = (await this.hasMethods(["UDT.name"]))[0]; - if (hasMethod) { + try { const rawResult = await this.ssriServer.callMethod( "UDT.name", [], @@ -69,7 +68,7 @@ export class UDT extends ssri.Contract { }, ); return ccc.bytesTo(rawResult, "utf8"); - } else { + } catch (_error) { throw new Error( "UDT.name method not found and ckb-udt-indexer not implemented yet", ); @@ -82,8 +81,7 @@ export class UDT extends ssri.Contract { * @tag Legacy - Supports xUDT legacy behavior. */ async symbol(): Promise { - const hasMethod = (await this.hasMethods(["UDT.symbol"]))[0]; - if (hasMethod) { + try { const rawResult = await this.ssriServer.callMethod( "UDT.symbol", [], @@ -93,7 +91,7 @@ export class UDT extends ssri.Contract { }, ); return ccc.bytesTo(rawResult, "utf8"); - } else { + } catch (_error) { throw new Error( "UDT.symbol method not found and ckb-udt-indexer not implemented yet", ); @@ -106,18 +104,17 @@ export class UDT extends ssri.Contract { * @tag Legacy - Supports xUDT legacy behavior. */ async decimals(): Promise { - const hasMethod = (await this.hasMethods(["UDT.decimals"]))[0]; - if (hasMethod) { + try { const rawResult = await this.ssriServer.callMethod( "UDT.decimals", [], this.cellDep.outPoint, { - script: this.type, - }, + script: this.type, + }, ); return ccc.numFromBytes(rawResult); - } else { + } catch (_error) { throw new Error( "UDT.decimals method not found and ckb-udt-indexer not implemented yet", ); @@ -130,18 +127,17 @@ export class UDT extends ssri.Contract { * @tag Legacy - Supports xUDT legacy behavior. */ async balance(cell: ccc.CellLike): Promise { - const hasMethod = (await this.hasMethods(["UDT.balance"]))[0]; - if (hasMethod) { + try { const rawResult = await this.ssriServer.callMethod( "UDT.balance", [], this.cellDep.outPoint, { - cell, - }, - ); + cell, + }, + ); return ccc.numLeFromBytes(ccc.bytesFrom(rawResult)); - } else { + } catch (_error) { return ccc.numLeFromBytes(ccc.bytesFrom(cell.outputData)); } } @@ -211,8 +207,7 @@ export class UDT extends ssri.Contract { if (toLockArray.length !== toAmountArray.length) { throw new Error("The number of lock scripts and amounts must match"); } - const hasMethod = (await this.hasMethods(["UDT.transfer"]))[0]; - if (hasMethod) { + try { const txEncodedHex = tx ? ccc.hexFrom(ccc.Transaction.from(tx).toBytes()) : "0x"; @@ -233,7 +228,7 @@ export class UDT extends ssri.Contract { ); const resultDecodedArray = ccc.bytesFrom(rawResult); return ccc.Transaction.decode(resultDecodedArray); - } else { + } catch (_error) { let parsedTx: ccc.Transaction; if (!tx) { parsedTx = ccc.Transaction.from({ @@ -276,8 +271,7 @@ export class UDT extends ssri.Contract { if (toLockArray.length !== toAmountArray.length) { throw new Error("The number of lock scripts and amounts must match"); } - const hasMethod = (await this.hasMethods(["UDT.mint"]))[0]; - if (hasMethod) { + try { const txEncodedHex = tx ? ccc.hexFrom(ccc.Transaction.from(tx).toBytes()) : "0x"; @@ -295,7 +289,7 @@ export class UDT extends ssri.Contract { ); const rawResultDecoded = ccc.Transaction.decode(rawResult); return ccc.Transaction.from(rawResultDecoded); - } else { + } catch (_error) { let parsedTx: ccc.Transaction; if (!tx) { parsedTx = ccc.Transaction.from({ @@ -327,15 +321,21 @@ export class UDT extends ssri.Contract { * @tag Legacy - Supports xUDT legacy behavior. */ async icon(): Promise { - const rawResult = await this.ssriServer.callMethod( - "UDT.icon", - [], - this.cellDep.outPoint, - { - script: this.type, - }, - ); - const iconBytes = Buffer.from(ccc.bytesFrom(rawResult)); - return iconBytes; + try { + const rawResult = await this.ssriServer.callMethod( + "UDT.icon", + [], + this.cellDep.outPoint, + { + script: this.type, + }, + ); + const iconBytes = Buffer.from(ccc.bytesFrom(rawResult)); + return iconBytes; + } catch (_error) { + throw new Error( + "UDT.icon method not found and ckb-udt-indexer not implemented yet", + ); + } } }