Skip to content

Commit

Permalink
fix: minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alive24 committed Jan 7, 2025
1 parent 527786e commit d1056b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/ssri/src/ssri/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Server {
| { cell: ccc.CellLike }
| { transaction: ccc.TransactionLike },
): Promise<ccc.Hex> {
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,
Expand Down
66 changes: 33 additions & 33 deletions packages/udt/src/udt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export class UDT extends ssri.Contract {
* @tag Legacy - Supports xUDT legacy behavior.
*/
async name(): Promise<string> {
const hasMethod = (await this.hasMethods(["UDT.name"]))[0];
if (hasMethod) {
try {
const rawResult = await this.ssriServer.callMethod(
"UDT.name",
[],
Expand All @@ -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",
);
Expand All @@ -82,8 +81,7 @@ export class UDT extends ssri.Contract {
* @tag Legacy - Supports xUDT legacy behavior.
*/
async symbol(): Promise<string> {
const hasMethod = (await this.hasMethods(["UDT.symbol"]))[0];
if (hasMethod) {
try {
const rawResult = await this.ssriServer.callMethod(
"UDT.symbol",
[],
Expand All @@ -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",
);
Expand All @@ -106,18 +104,17 @@ export class UDT extends ssri.Contract {
* @tag Legacy - Supports xUDT legacy behavior.
*/
async decimals(): Promise<ccc.Num> {
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",
);
Expand All @@ -130,18 +127,17 @@ export class UDT extends ssri.Contract {
* @tag Legacy - Supports xUDT legacy behavior.
*/
async balance(cell: ccc.CellLike): Promise<ccc.Num> {
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));
}
}
Expand Down Expand Up @@ -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";
Expand All @@ -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({
Expand Down Expand Up @@ -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";
Expand All @@ -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({
Expand Down Expand Up @@ -327,15 +321,21 @@ export class UDT extends ssri.Contract {
* @tag Legacy - Supports xUDT legacy behavior.
*/
async icon(): Promise<ccc.Bytes> {
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",
);
}
}
}

0 comments on commit d1056b0

Please sign in to comment.