Skip to content

Commit

Permalink
feat: tested examples and transaction logs of Pausable UDT
Browse files Browse the repository at this point in the history
  • Loading branch information
Alive24 committed Jan 16, 2025
1 parent 769a130 commit 6df7a20
Show file tree
Hide file tree
Showing 15 changed files with 823 additions and 10 deletions.
34 changes: 34 additions & 0 deletions packages/examples/src/pauseableUdt/enumeratePaused.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ccc } from "@ckb-ccc/ccc";
import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.UdtPausable(pudtScriptCell.outPoint, pudtType, {
executor,
});

const pudtEnumeratePaused = await pudt.enumeratePaused();
console.log(pudtEnumeratePaused);
// {"res":["0xa320a09489791af2e5e1fe84927eda84f71afcbd2c7a65cb419464fe46e75085"],"cellDeps":[]}
46 changes: 46 additions & 0 deletions packages/examples/src/pauseableUdt/isPaused.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ccc } from "@ckb-ccc/ccc";
import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.UdtPausable(pudtScriptCell.outPoint, pudtType, {
executor,
});

const pausedReceiver =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgy2q6qz79wyaexr2pcez0eejmk5xgw6jcfw7zmg";

const { script: pausedReceiverScript } = await ccc.Address.fromString(
pausedReceiver,
signer.client,
);

const pudtIsPaused = await pudt.isPaused(
[pausedReceiverScript],
["0x787e97af6860c58fcecd12653714330c003f5b960e09f027295a49e3c41d609f"],
);

console.log(pudtIsPaused);
// {"res":[true,false],"cellDeps":[]}
120 changes: 120 additions & 0 deletions packages/examples/src/pauseableUdt/pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { ccc } from "@ckb-ccc/ccc";
import { render, signer } from "@ckb-ccc/playground";

// NOTE: Please use ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2jk6pyw9vlnfakx7vp4t5lxg0lzvvsp3c5adflu as the signer
const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x738072698a31dab785b1b464e0a0aa06d2c8ab5dd52ea8a36a759cbf83301977",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.UdtPausable(pudtScriptCell.outPoint, pudtType, {
executor,
});

// NOTE: This script doesn't contain external data cell while running pause would help you generate the first external data cell so you can upgrade the script accordingly.
const pudtnScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtnScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtnCodeHash = pudtnScriptCell.cellOutput.type?.hash();
if (!pudtnCodeHash) {
throw new Error("PUDT code hash not found");
}
const pudtnType = {
codeHash: pudtnCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudtn = new ccc.udt.UdtPausable(pudtnScriptCell.outPoint, pudtnType, {
executor,
});

const pausedReceiver =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgy2q6qz79wyaexr2pcez0eejmk5xgw6jcfw7zmg";
const targetReceiverAToPause =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwfxam63un4ld5ephk83900h8fqwgn6ktc4kq0lj";
const targetReceiverBToPause =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtsm4z8rqkt060h3ugwyvfhvyc8qqsf5vsh59ey9";

const { script: pausedReceiverScript } = await ccc.Address.fromString(
pausedReceiver,
signer.client,
);

const { script: targetReceiverAScript } = await ccc.Address.fromString(
targetReceiverAToPause,
signer.client,
);

const { script: targetReceiverBScript } = await ccc.Address.fromString(
targetReceiverBToPause,
signer.client,
);

const pudtPauseTx = (
await pudt.pause(
signer,
[targetReceiverAScript, pausedReceiverScript],
undefined,
[targetReceiverBScript.hash()],
)
).res;
await render(pudtPauseTx);

const pudtnPauseTx = (
await pudtn.pause(
signer,
[targetReceiverAScript, pausedReceiverScript],
undefined,
[targetReceiverBScript.hash()],
)
).res;
await render(pudtnPauseTx);

await pudtPauseTx.completeFeeBy(signer);
await pudtnPauseTx.completeFeeBy(signer);
// NOTE: This would fail for 36 ("Nothing To DO") if run again because it's already paused and it would be deduped. Run unpause before pausing them again
const pudtPauseTxHash = await signer.sendTransaction(pudtPauseTx);
console.log(pudtPauseTxHash);
// "0xc8df6b7edaa295f4044107e5c7f5b20fffe6e36e37fcf6513337c2be8c354e39"
const pudtnPauseTxHash = await signer.sendTransaction(pudtnPauseTx);
console.log(pudtnPauseTxHash);
// "0x04fd05e091189d9beae525decd22d61cd8d63bd2ce6949369961fca7fa63a27b"

// NOTE: This won't change because you need to upgrade the script to see the change
const pudtnPaused = await pudtn.enumeratePaused();
console.log(pudtnPaused);
// {"res":[],"cellDeps":[]}

// NOTE: This might be delayed if the transaction is not yet confirmed
const pudtPaused = await pudt.enumeratePaused();
console.log(pudtPaused);
// {"res":["0x787e97af6860c58fcecd12653714330c003f5b960e09f027295a49e3c41d609f","0x0ac6e7d7ed8d8ac0832992f106dbebbd71a2cfa4791ef621dec081a047f7668d","0xa320a09489791af2e5e1fe84927eda84f71afcbd2c7a65cb419464fe46e75085","0x779c916fc89f7c7d03c97d7a2aa5cf4f854d4f279ef0a89f8568dc65e744b3a6"],"cellDeps":[{"txHash":"0xc8df6b7edaa295f4044107e5c7f5b20fffe6e36e37fcf6513337c2be8c354e39","index":"0"}]}
73 changes: 73 additions & 0 deletions packages/examples/src/pauseableUdt/unpause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ccc } from "@ckb-ccc/ccc";
import { render, signer } from "@ckb-ccc/playground";
// NOTE: Please use ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2jk6pyw9vlnfakx7vp4t5lxg0lzvvsp3c5adflu as the signer
const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x738072698a31dab785b1b464e0a0aa06d2c8ab5dd52ea8a36a759cbf83301977",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}
const pudtType = {
codeHash: pudtCodeHash,
hashType: "type",
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
};

const pudt = new ccc.udt.UdtPausable(pudtScriptCell.outPoint, pudtType, {
executor,
});

const pausedReceiver =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgy2q6qz79wyaexr2pcez0eejmk5xgw6jcfw7zmg";
const targetReceiverAToUnpause =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwfxam63un4ld5ephk83900h8fqwgn6ktc4kq0lj";
const targetReceiverBToUnpause =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtsm4z8rqkt060h3ugwyvfhvyc8qqsf5vsh59ey9";

const { script: pausedReceiverScript } = await ccc.Address.fromString(
pausedReceiver,
signer.client,
);

const { script: targetReceiverAScript } = await ccc.Address.fromString(
targetReceiverAToUnpause,
signer.client,
);

const { script: targetReceiverBScript } = await ccc.Address.fromString(
targetReceiverBToUnpause,
signer.client,
);

// NOTE: This would sometimes fail for 36 ("Nothing To DO") if run again because it's already unpaused and it would be deduped. Run pause before unpausing them again
const pudtUnpauseTx = (
await pudt.unpause(
signer,
[targetReceiverAScript, pausedReceiverScript],
undefined,
[targetReceiverBScript.hash()],
)
).res;
await render(pudtUnpauseTx);

await pudtUnpauseTx.completeFeeBy(signer);
const pudtUnpauseTxHash = await signer.sendTransaction(pudtUnpauseTx);
console.log(pudtUnpauseTxHash);
// "0x7715e78b4c5ded8928027c6aa610468eafce81c88e48e1267c1b787f52bb4929"

// NOTE: This might be delayed if the transaction is not yet confirmed
const pudtPaused = await pudt.enumeratePaused();
console.log(pudtPaused);
// {"res":["0x787e97af6860c58fcecd12653714330c003f5b960e09f027295a49e3c41d609f"],"cellDeps":[{"txHash":"0x7715e78b4c5ded8928027c6aa610468eafce81c88e48e1267c1b787f52bb4929","index":"0"}]}
29 changes: 29 additions & 0 deletions packages/examples/src/ssri/getMethods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ccc } from "@ckb-ccc/ccc";
import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}

const pudt = new ccc.ssri.Trait(pudtScriptCell.outPoint, executor);

const pudtMethods = await pudt.getMethods();

console.log(pudtMethods);
///
// {"res":["0x6f2a4642323106f8","0x58f02409de9de7b1","0xb43d1128f8726c19","0xc78a67cec2fcc54f","0x35fa711c8c918aad","0x2f87f08056af234d","0xa306f89e40893737","0x235c6c5c6ee04b08","0x9adf445d336222e1","0x2e04fafee9f986ea","0x03cd9ce840759d42","0x849def40c0e9a525","0x43f92b1ceda6fa2b"],"cellDeps":[]}
45 changes: 45 additions & 0 deletions packages/examples/src/ssri/hasMethods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ccc } from "@ckb-ccc/ccc";
import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}

const pudt = new ccc.ssri.Trait(pudtScriptCell.outPoint, executor);

const pudtHasMethods = await pudt.hasMethods([
"SSRI.get_methods",
"SSRI.has_methods",
"SSRI.version",
"UDT.name",
"UDT.symbol",
"UDT.decimals",
"UDT.icon",
"UDT.transfer",
"UDT.mint",
"UDTPausable.pause",
"UDTPausable.unpause",
"UDTPausable.is_paused",
"UDTPausable.enumerate_paused",
"UNKNOWN",
]);

console.log(pudtHasMethods);
///
// {"res":[true,true,true,true,true,true,true,true,true,true,true,true,true,false],"cellDeps":[]}
///
30 changes: 30 additions & 0 deletions packages/examples/src/ssri/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ccc } from "@ckb-ccc/ccc";
import { signer } from "@ckb-ccc/playground";

const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");

const pudtScriptCell = await signer.client.findSingletonCellByType({
// TypeID Code Hash. Don't change
codeHash:
"0x00000000000000000000000000000000000000000000000000545950455f4944",
hashType: "type",
// TypeID args. Change it to the args of the Type ID script of your UDT
args: "0x8fd55df879dc6176c95f3c420631f990ada2d4ece978c9512c39616dead2ed56",
});
if (!pudtScriptCell) {
throw new Error("PUDT script cell not found");
}

const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
if (!pudtCodeHash) {
throw new Error("PUDT code hash not found");
}

const pudt = new ccc.ssri.Trait(pudtScriptCell.outPoint, executor);

const pudtVersion = await pudt.version();

console.log(pudtVersion);
///
// {"res":"0","cellDeps":[]}
///
Loading

0 comments on commit 6df7a20

Please sign in to comment.