Skip to content

Commit a373537

Browse files
author
chunteng-web3
committed
chore: prepare for demo
1 parent a7732f0 commit a373537

File tree

15 files changed

+214
-137
lines changed

15 files changed

+214
-137
lines changed

.vscode/launch.json

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4-
{
5-
"command": "npm exec ckb_ssri_cli udt:pausable:is-paused 0xa9c1b6b195ce5b7a3f0bbc07d16e00100db0935798b9f7421cc86fb8218ba299",
6-
"name": "Run npm exec",
7-
"request": "launch",
8-
"type": "node-terminal"
9-
},
10-
{
11-
"type": "node",
12-
"request": "attach",
13-
"name": "Attach",
14-
"port": 9229,
15-
"skipFiles": ["<node_internals>/**"]
16-
},
174
{
185
"type": "node",
196
"request": "launch",
20-
"name": "Execute Command",
21-
"skipFiles": ["<node_internals>/**"],
22-
"runtimeExecutable": "node",
23-
"runtimeArgs": ["--loader", "ts-node/esm", "--no-warnings=ExperimentalWarning"],
24-
"program": "${workspaceFolder}/bin/dev.js",
25-
"args": ["hello", "world"]
7+
"name": "Launch Program",
8+
"program": "${workspaceFolder}/bin/run",
9+
"args": [
10+
"--name",
11+
"Callum",
12+
"--force",
13+
"argument"
14+
]
2615
}
2716
]
28-
}
17+
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cSpell.words": [
3-
"PUDT"
3+
"PUDT",
4+
"USDI"
45
]
56
}

src/commands/config/account/import.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default class ConfigAccountImport extends Command {
3131
privateKey: flags.privateKey,
3232
}
3333

34+
this.log(`Account imported with alias: ${accountRegistryKey}. The address is ${signer.getRecommendedAddress()}.`);
35+
3436
await updateCLIConfig(this.config.configDir, cliConfig);
3537
}
3638
}

src/commands/config/index.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Args, Command, Flags} from '@oclif/core'
22
import { getCLIConfig, UDTConfig, updateCLIConfig } from '../../../libs/config.js'
33

4-
export default class ConfigUdtRegister extends Command {
4+
export default class ConfigUDTRegister extends Command {
55
static override args = {
66
jsonString: Args.string({description: 'JsonString', required: true}),
77
}
@@ -16,21 +16,25 @@ export default class ConfigUdtRegister extends Command {
1616
}
1717

1818
public async run(): Promise<void> {
19-
const {args, flags} = await this.parse(ConfigUdtRegister)
19+
const {args, flags} = await this.parse(ConfigUDTRegister)
2020

2121
// Read JSON string as UDTConfig
22-
const rawUdtConfig = JSON.parse(args.jsonString)
23-
24-
const parsedUdtConfig: UDTConfig = {
25-
symbol: rawUdtConfig.symbol,
26-
code_hash: rawUdtConfig.code_hash,
27-
args: rawUdtConfig.args,
28-
cellDepSearchKeys: rawUdtConfig.cellDepSearchKeys,
29-
decimals: rawUdtConfig.decimals,
22+
const rawUDTConfig = JSON.parse(args.jsonString)
23+
24+
const parsedUDTConfig: UDTConfig = {
25+
network: rawUDTConfig.network,
26+
symbol: rawUDTConfig.symbol,
27+
code_hash: rawUDTConfig.code_hash,
28+
args: rawUDTConfig.args,
29+
cellDepSearchKeys: rawUDTConfig.cellDepSearchKeys,
30+
decimals: rawUDTConfig.decimals,
3031
}
3132

3233
let cliConfig = await getCLIConfig(this.config.configDir);
33-
cliConfig.UDTRegistry[parsedUdtConfig.symbol] = parsedUdtConfig
34+
cliConfig.UDTRegistry[parsedUDTConfig.symbol] = parsedUDTConfig
35+
36+
this.log(`UDT registered with symbol: ${parsedUDTConfig.symbol}.`);
37+
this.log(`UDT Config: ${JSON.stringify(parsedUDTConfig)}`);
3438
await updateCLIConfig(this.config.configDir, cliConfig);
3539
}
3640
}

src/commands/udt/extended/mint.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {ccc, Cell, CellDep, CellDepLike} from '@ckb-ccc/core'
22
import {Args, Command, Flags} from '@oclif/core'
3-
import {getCellDepsFromSearchKeys, getCLIConfig, getUDTConfig} from '../../../libs/config.js'
3+
import {getCellDepsFromSearchKeys, getCLIConfig } from '../../../libs/config.js'
44
import 'dotenv/config'
55

6-
export default class UdtExtendedMint extends Command {
6+
export default class UDTExtendedMint extends Command {
77
static override args = {
88
symbol: Args.string({description: 'Symbol of UDT to mint.', required: true}),
99
toAddress: Args.string({description: 'file to read', required: true}),
@@ -29,7 +29,7 @@ export default class UdtExtendedMint extends Command {
2929
}
3030

3131
public async run(): Promise<void> {
32-
const {args, flags} = await this.parse(UdtExtendedMint)
32+
const {args, flags} = await this.parse(UDTExtendedMint)
3333

3434
const CLIConfig = await getCLIConfig(this.config.configDir)
3535
// TODO: Mainnet support.
@@ -43,7 +43,7 @@ export default class UdtExtendedMint extends Command {
4343

4444
const toLock = (await ccc.Address.fromString(args.toAddress, signer.client)).script
4545

46-
const udtConfig = getUDTConfig(args.symbol)
46+
const udtConfig = CLIConfig.UDTRegistry[args.symbol]
4747
const udtTypeScript = new ccc.Script(udtConfig.code_hash, 'type', udtConfig.args)
4848

4949
const mintTx = ccc.Transaction.from({
@@ -64,6 +64,6 @@ export default class UdtExtendedMint extends Command {
6464
// TODO: At the moment only simple lock script is supported. Should support more in the future, particularly proxy lock.
6565
const mintTxHash = await signer.sendTransaction(mintTx)
6666

67-
this.log(`Minted UDT with transaction hash: ${mintTxHash}`)
67+
this.log(`Minted ${args.toAmount} ${args.symbol} to ${args.toAddress}. Tx hash: ${mintTxHash}`)
6868
}
6969
}

src/commands/udt/pausable/enumerate-paused.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import {Args, Command, Flags} from '@oclif/core'
33
import {cccA} from '@ckb-ccc/core/advanced'
44
import {encodeHex, encodeU832Array} from '../../../libs/utils.js'
55
import axios from 'axios'
6-
import {getCellDepsFromSearchKeys, getUDTConfig} from '../../../libs/config.js'
7-
import {debug} from 'debug'
6+
import {getCellDepsFromSearchKeys, getCLIConfig} from '../../../libs/config.js'
7+
import debug from 'debug'
88

9-
export default class UdtPausableIsPaused extends Command {
9+
export default class UDTPausableEnumeratePaused extends Command {
1010
static override args = {
1111
symbol: Args.string({description: 'Symbol of UDT to mint.', required: true}),
1212
}
1313

1414
static strict = false
1515

16-
static override description = 'describe the command here'
16+
static override description =
17+
'Enumerate the pause list of the token. Note: This command should be transaction level if using external pause list.'
1718

18-
static override examples = ['<%= config.bin %> <%= command.id %>']
19+
static override examples = ['ckb_ssri_sli udt:pausable:enumerate-paused PUDT']
1920

2021
static override flags = {
2122
target: Flags.string({description: 'Target cell'}),
@@ -30,16 +31,17 @@ export default class UdtPausableIsPaused extends Command {
3031

3132
// TODO: This would only work for code only pause list at the moment. Will need to raise to transaction level for external metadata/pause data cell.
3233
public async run(): Promise<void> {
33-
const {args, flags} = await this.parse(UdtPausableIsPaused)
34+
const {args, flags} = await this.parse(UDTPausableEnumeratePaused)
3435
// Method path hex function
3536
const hasher = new HasherCkb()
3637
const enumeratePausedPathHex = hasher.update(Buffer.from('UDT.enumerate_paused')).digest().slice(0, 18)
3738
debug(`enumerate-paused | hashed method path hex: ${enumeratePausedPathHex}`)
3839

40+
const cliConfig = await getCLIConfig(this.config.configDir)
3941
const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})
40-
const udtConfig = getUDTConfig(args.symbol)
42+
const udtConfig = cliConfig.UDTRegistry[args.symbol]
4143

42-
const codeCellDep = (await getCellDepsFromSearchKeys(client, udtConfig.cellDepSearchKeys))[0];
44+
const codeCellDep = (await getCellDepsFromSearchKeys(client, udtConfig.cellDepSearchKeys))[0]
4345

4446
// Define the JSON payload
4547
const payload = {
@@ -55,7 +57,25 @@ export default class UdtPausableIsPaused extends Command {
5557
headers: {'Content-Type': 'application/json'},
5658
})
5759
.then((response) => {
58-
this.log('Response JSON:', response.data)
60+
this.debug('Response JSON:', response.data)
61+
const lengthBytes = new Uint8Array(4)
62+
for (let i = 0; i < 8; i += 2) {
63+
lengthBytes[i / 2] = parseInt(
64+
response.data.result
65+
.toString()
66+
.slice(2)
67+
.slice(i, i + 2),
68+
16,
69+
)
70+
}
71+
const pauseListLength = new cccA.moleculeCodecCkb.Uint32(lengthBytes)
72+
this.log(`Pause List Length: ${pauseListLength.toLittleEndianUint32()}`)
73+
const pauseListHex = response.data.result.toString().slice(10)
74+
let pauseList = []
75+
for (let i = 0; i < pauseListHex.length; i += 64) {
76+
pauseList.push(pauseListHex.slice(i, i + 64))
77+
}
78+
this.log(`Pause List: \n${pauseList}`)
5979
})
6080
.catch((error) => {
6181
console.error('Request failed', error)
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {ccc, Cell, CellDepLike, HasherCkb, numToBytes, numToHex} from '@ckb-ccc/core'
22
import {Args, Command, Flags} from '@oclif/core'
33
import {cccA} from '@ckb-ccc/core/advanced'
4-
import { encodeHex, encodeU832Array } from '../../../libs/utils.js'
4+
import {encodeHex, encodeU832Array} from '../../../libs/utils.js'
55
import axios from 'axios'
6-
import { getCellDepsFromSearchKeys, getUDTConfig } from '../../../libs/config.js'
6+
import {getCellDepsFromSearchKeys, getCLIConfig} from '../../../libs/config.js'
77
import debug from 'debug'
88

9-
export default class UdtPausableIsPaused extends Command {
9+
export default class UDTPausableIsPaused extends Command {
1010
static override args = {
1111
symbol: Args.string({description: 'Symbol of UDT to mint.', required: true}),
1212
lock_hash: Args.string({description: 'Lock hash in hex. Variable length'}),
1313
}
1414

15-
static strict = false;
15+
static strict = false
1616

1717
static override description = 'describe the command here'
1818

@@ -30,25 +30,26 @@ export default class UdtPausableIsPaused extends Command {
3030
}
3131

3232
public async run(): Promise<void> {
33-
const {args, argv, flags} = await this.parse(UdtPausableIsPaused)
34-
let lockHashU832Array = [];
33+
const {args, argv, flags} = await this.parse(UDTPausableIsPaused)
34+
let lockHashU832Array = []
3535
for (const lock_hash of argv.slice(1)) {
36-
lockHashU832Array.push(numToBytes(String(lock_hash), 32).reverse());
36+
lockHashU832Array.push(numToBytes(String(lock_hash), 32).reverse())
3737
}
38-
debug(`is-paused | lockHashU832Array: ${lockHashU832Array}`);
39-
const lockHashU832ArrayEncoded = encodeU832Array(lockHashU832Array);
40-
debug(`is-paused | lockHashArrayEncoded: ${lockHashU832ArrayEncoded}`);
41-
const lockHashU832ArrayEncodedHex = encodeHex(lockHashU832ArrayEncoded);
38+
debug(`is-paused | lockHashU832Array: ${lockHashU832Array}`)
39+
const lockHashU832ArrayEncoded = encodeU832Array(lockHashU832Array)
40+
debug(`is-paused | lockHashArrayEncoded: ${lockHashU832ArrayEncoded}`)
41+
const lockHashU832ArrayEncodedHex = encodeHex(lockHashU832ArrayEncoded)
4242

4343
// Method path hex function
44-
const hasher = new HasherCkb();
45-
const isPausedPathHex = hasher.update(Buffer.from('UDT.is_paused')).digest().slice(0, 18);
46-
debug(`is-paused | hashed method path hex:${isPausedPathHex}`);
44+
const hasher = new HasherCkb()
45+
const isPausedPathHex = hasher.update(Buffer.from('UDT.is_paused')).digest().slice(0, 18)
46+
debug(`is-paused | hashed method path hex:${isPausedPathHex}`)
4747

48-
const client = new ccc.ClientPublicTestnet({ url: process.env.CKB_RPC_URL });
49-
const udtConfig = getUDTConfig(args.symbol);
48+
const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})
49+
const cliConfig = await getCLIConfig(this.config.configDir)
50+
const udtConfig = cliConfig.UDTRegistry[args.symbol]
5051

51-
const codeCellDep = (await getCellDepsFromSearchKeys(client, udtConfig.cellDepSearchKeys))[0];
52+
const codeCellDep = (await getCellDepsFromSearchKeys(client, udtConfig.cellDepSearchKeys))[0]
5253
// Define the JSON payload
5354
const payload = {
5455
id: 2,
@@ -57,9 +58,10 @@ export default class UdtPausableIsPaused extends Command {
5758
params: [
5859
codeCellDep.outPoint.txHash,
5960
Number(codeCellDep.outPoint.index),
60-
// args.index,
61-
[isPausedPathHex, `0x${lockHashU832ArrayEncodedHex}`]],
62-
};
61+
// args.index,
62+
[isPausedPathHex, `0x${lockHashU832ArrayEncodedHex}`],
63+
],
64+
}
6365

6466
// Send POST request
6567
axios
@@ -71,7 +73,7 @@ export default class UdtPausableIsPaused extends Command {
7173
})
7274
.catch((error) => {
7375
console.error('Request failed', error)
74-
});
76+
})
7577
// TODO: Prettify response.
7678
}
7779
}

src/commands/udt/transfer.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {ccc, Cell, CellDepLike} from '@ckb-ccc/core'
22
import {Args, Command, Flags} from '@oclif/core'
3-
import {getCellDepsFromSearchKeys, getUDTConfig} from '../../libs/config.js'
3+
import {getCellDepsFromSearchKeys, getCLIConfig} from '../../libs/config.js'
44

5-
export default class UdtTransfer extends Command {
5+
export default class UDTTransfer extends Command {
66
static override args = {
77
symbol: Args.string({description: 'Symbol of UDT to transfer.', required: true}),
88
toAddress: Args.string({description: 'file to read', required: true}),
@@ -28,21 +28,24 @@ export default class UdtTransfer extends Command {
2828
}),
2929
// TODO: Implement fromTransactionJson and holdSend.
3030
fromTransactionJson: Flags.file({
31-
description: 'Assemble transaction on the basis of a previous action; use together with holdSend to make multiple transfers within the same transaction.',
31+
description:
32+
'Assemble transaction on the basis of a previous action; use together with holdSend to make multiple transfers within the same transaction.',
3233
}),
3334
holdSend: Flags.boolean({
34-
description: 'Hold the transaction and send it later. Will output the transaction JSON. Use together with fromTransactionJson to make multiple transfers within the same transaction.',
35+
description:
36+
'Hold the transaction and send it later. Will output the transaction JSON. Use together with fromTransactionJson to make multiple transfers within the same transaction.',
3537
}),
3638
}
3739

3840
public async run(): Promise<void> {
39-
const {args, flags} = await this.parse(UdtTransfer)
41+
const {args, flags} = await this.parse(UDTTransfer)
4042

4143
const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})
4244
const signer = new ccc.SignerCkbPrivateKey(client, process.env.MAIN_WALLET_PRIVATE_KEY!)
4345
const toLock = (await ccc.Address.fromString(args.toAddress, signer.client)).script
4446

45-
const udtConfig = getUDTConfig(args.symbol)
47+
const cliConfig = await getCLIConfig(this.config.configDir)
48+
const udtConfig = cliConfig.UDTRegistry[args.symbol]
4649
const udtTypeScript = new ccc.Script(udtConfig.code_hash, 'type', udtConfig.args)
4750

4851
const transferTx = ccc.Transaction.from({
@@ -61,7 +64,7 @@ export default class UdtTransfer extends Command {
6164
transferTx.addCellDeps(await getCellDepsFromSearchKeys(client, udtConfig.cellDepSearchKeys))
6265
const transferTxTxHash = await signer.sendTransaction(transferTx)
6366

64-
this.log(`Transferred UDT with transaction hash: ${transferTxTxHash}`)
67+
this.log(`Transferred ${args.toAmount} ${args.symbol} to ${args.toAddress}. Tx hash: ${transferTxTxHash}`)
6568

6669
// TODO: Process error.
6770
}

0 commit comments

Comments
 (0)