Skip to content

Commit

Permalink
chore: udt:metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
chunteng-web3 committed Nov 8, 2024
1 parent 421c36e commit ead30cc
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,28 @@ USAGE
## Commands
<!-- commands -->

### UDTPausable.is_paused

```shell
ckb_ssri_cli udt:pausable:is-paused PUDT 0xd19228c64920eb8c3d79557d8ae59ee7a14b9d7de45ccf8bafacf82c91fc359e
```

### UDTPausable.enumerate_paused

```shell
ckb_ssri_cli udt:pausable:enumerate-paused PUDT
```

### UDTExtended.mint

```shell
// Note: This is a paused address, but minting will override.
ckb_ssri_cli udt:extended:mint PUDT ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgtlcnzzna2tqst7jw78egjpujn7hdxpackjmmdp 100
ckb_ssri_cli udt:extended:mint PUDT ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg7mkruq9gwjdxsgpw8yzmlvzecsqafcysjyrveq 100
```

### UDT.transfer

```shell
// Note: This will succeed as transferring as owner.
ckb_ssri_cli udt:transfer PUDT ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgtlcnzzna2tqst7jw78egjpujn7hdxpackjmmdp 100
Expand Down
57 changes: 57 additions & 0 deletions src/commands/udt/metadata/decimals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ccc, HasherCkb } from '@ckb-ccc/core'
import {Args, Command, Flags} from '@oclif/core'
import debug from 'debug'
import { getCLIConfig } from '../../../libs/config.js'
import axios from 'axios'

export default class UDTMetadataDecimals extends Command {
static override args = {
txHash: Args.string({description: 'txHash of the UDT cell.', required: true}),
index: Args.integer({description: 'index of the UDT cell.', required: true}),
}

static override description = 'describe the command here'

static override examples = ['<%= config.bin %> <%= command.id %>']

static override flags = {
// flag with no value (-f, --force)
force: Flags.boolean({char: 'f'}),
// flag with a value (-n, --name=VALUE)
name: Flags.string({char: 'n', description: 'name to print'}),
}

public async run(): Promise<void> {
const {args, flags} = await this.parse(UDTMetadataDecimals)
// Method path hex function
const hasher = new HasherCkb()
const decimalPathHex = hasher.update(Buffer.from('UDTMetadata.decimals')).digest().slice(0, 18)
debug(`enumerate-paused | hashed method path hex: ${decimalPathHex}`)

const cliConfig = await getCLIConfig(this.config.configDir)
const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})

// Define the JSON payload
const payload = {
id: 2,
jsonrpc: '2.0',
method: 'run_script_level_code',
params: [args.txHash, Number(args.index), [decimalPathHex]],
}

// Send POST request
axios
.post(process.env.SSRI_SERVER_URL!, payload, {
headers: {'Content-Type': 'application/json'},
})
.then((response) => {
console.log('Response JSON:', response.data)
// TODO: Prettify response.
return
})
.catch((error) => {
console.error('Request failed', error)
})
// TODO: Prettify response.
}
}
57 changes: 57 additions & 0 deletions src/commands/udt/metadata/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {ccc, HasherCkb} from '@ckb-ccc/core'
import {Args, Command, Flags} from '@oclif/core'
import debug from 'debug'
import {getCLIConfig} from '../../../libs/config.js'
import axios from 'axios'

export default class UDTMetadataName extends Command {
static override args = {
txHash: Args.string({description: 'txHash of the UDT cell.', required: true}),
index: Args.integer({description: 'index of the UDT cell.', required: true}),
}

static override description = 'describe the command here'

static override examples = ['<%= config.bin %> <%= command.id %>']

static override flags = {
// flag with no value (-f, --force)
force: Flags.boolean({char: 'f'}),
// flag with a value (-n, --name=VALUE)
name: Flags.string({char: 'n', description: 'name to print'}),
}

public async run(): Promise<void> {
const {args, flags} = await this.parse(UDTMetadataName)
// Method path hex function
const hasher = new HasherCkb()
const namePathHex = hasher.update(Buffer.from('UDTMetadata.name')).digest().slice(0, 18)
debug(`enumerate-paused | hashed method path hex: ${namePathHex}`)

const cliConfig = await getCLIConfig(this.config.configDir)
const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})

// Define the JSON payload
const payload = {
id: 2,
jsonrpc: '2.0',
method: 'run_script_level_code',
params: [args.txHash, Number(args.index), [namePathHex]],
}

// Send POST request
axios
.post(process.env.SSRI_SERVER_URL!, payload, {
headers: {'Content-Type': 'application/json'},
})
.then((response) => {
console.log('Response JSON:', response.data)
// TODO: Prettify response.
return
})
.catch((error) => {
console.error('Request failed', error)
})
// TODO: Prettify response.
}
}
57 changes: 57 additions & 0 deletions src/commands/udt/metadata/symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ccc, HasherCkb } from '@ckb-ccc/core'
import {Args, Command, Flags} from '@oclif/core'
import debug from 'debug'
import { getCLIConfig } from '../../../libs/config.js'
import axios from 'axios'

export default class UDTMetadataSymbol extends Command {
static override args = {
txHash: Args.string({description: 'txHash of the UDT cell.', required: true}),
index: Args.integer({description: 'index of the UDT cell.', required: true}),
}

static override description = 'describe the command here'

static override examples = ['<%= config.bin %> <%= command.id %>']

static override flags = {
// flag with no value (-f, --force)
force: Flags.boolean({char: 'f'}),
// flag with a value (-n, --name=VALUE)
name: Flags.string({char: 'n', description: 'name to print'}),
}

public async run(): Promise<void> {
const {args, flags} = await this.parse(UDTMetadataSymbol)
// Method path hex function
const hasher = new HasherCkb()
const symbolPathHex = hasher.update(Buffer.from('UDTMetadata.symbol')).digest().slice(0, 18)
debug(`enumerate-paused | hashed method path hex: ${symbolPathHex}`)

const cliConfig = await getCLIConfig(this.config.configDir)
const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})

// Define the JSON payload
const payload = {
id: 2,
jsonrpc: '2.0',
method: 'run_script_level_code',
params: [args.txHash, Number(args.index), [symbolPathHex]],
}

// Send POST request
axios
.post(process.env.SSRI_SERVER_URL!, payload, {
headers: {'Content-Type': 'application/json'},
})
.then((response) => {
console.log('Response JSON:', response.data)
// TODO: Prettify response.
return
})
.catch((error) => {
console.error('Request failed', error)
})
// TODO: Prettify response.
}
}
4 changes: 2 additions & 2 deletions src/commands/udt/pausable/enumerate-paused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class UDTPausableEnumeratePaused extends Command {

static override description =
'Enumerate the pause list of the token. Note: This command should be transaction level if using external pause list.'

// TODO: Automatic redirect to transactions with the latest cell dep.
static override examples = ['ckb_ssri_sli udt:pausable:enumerate-paused PUDT']

static override flags = {
Expand All @@ -34,7 +34,7 @@ export default class UDTPausableEnumeratePaused extends Command {
const {args, flags} = await this.parse(UDTPausableEnumeratePaused)
// Method path hex function
const hasher = new HasherCkb()
const enumeratePausedPathHex = hasher.update(Buffer.from('UDT.enumerate_paused')).digest().slice(0, 18)
const enumeratePausedPathHex = hasher.update(Buffer.from('UDTPausable.enumerate_paused')).digest().slice(0, 18)
debug(`enumerate-paused | hashed method path hex: ${enumeratePausedPathHex}`)

const cliConfig = await getCLIConfig(this.config.configDir)
Expand Down
3 changes: 2 additions & 1 deletion src/commands/udt/pausable/is-paused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class UDTPausableIsPaused extends Command {

static strict = false

// TODO: Automatic redirect to transactions with the latest cell dep.
static override description = 'Inspect an array of specific lock hashes to see if any one of they are paused. Note that this command is transaction specific if using external pause list.'

static override examples = ['ckb_ssri_sli udt:pausable:is-paused PUDT 0xd19228c64920eb8c3d79557d8ae59ee7a14b9d7de45ccf8bafacf82c91fc359e']
Expand Down Expand Up @@ -42,7 +43,7 @@ export default class UDTPausableIsPaused extends Command {

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

const client = new ccc.ClientPublicTestnet({url: process.env.CKB_RPC_URL})
Expand Down
14 changes: 14 additions & 0 deletions test/commands/udt/metadata/decimals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {runCommand} from '@oclif/test'
import {expect} from 'chai'

describe('udt:metadata:decimals', () => {
it('runs udt:metadata:decimals cmd', async () => {
const {stdout} = await runCommand('udt:metadata:decimals')
expect(stdout).to.contain('hello world')
})

it('runs udt:metadata:decimals --name oclif', async () => {
const {stdout} = await runCommand('udt:metadata:decimals --name oclif')
expect(stdout).to.contain('hello oclif')
})
})
14 changes: 14 additions & 0 deletions test/commands/udt/metadata/name.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {runCommand} from '@oclif/test'
import {expect} from 'chai'

describe('udt:metadata:name', () => {
it('runs udt:metadata:name cmd', async () => {
const {stdout} = await runCommand('udt:metadata:name')
expect(stdout).to.contain('hello world')
})

it('runs udt:metadata:name --name oclif', async () => {
const {stdout} = await runCommand('udt:metadata:name --name oclif')
expect(stdout).to.contain('hello oclif')
})
})
14 changes: 14 additions & 0 deletions test/commands/udt/metadata/symbol.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {runCommand} from '@oclif/test'
import {expect} from 'chai'

describe('udt:metadata:symbol', () => {
it('runs udt:metadata:symbol cmd', async () => {
const {stdout} = await runCommand('udt:metadata:symbol')
expect(stdout).to.contain('hello world')
})

it('runs udt:metadata:symbol --name oclif', async () => {
const {stdout} = await runCommand('udt:metadata:symbol --name oclif')
expect(stdout).to.contain('hello oclif')
})
})
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/index.ts","./src/commands/config/account/import.ts","./src/commands/config/udt/register.ts","./src/commands/udt/transfer.ts","./src/commands/udt/extended/mint.ts","./src/commands/udt/pausable/enumerate-paused.ts","./src/commands/udt/pausable/is-paused.ts","./src/libs/config.ts","./src/libs/default.ts","./src/libs/utils.ts"],"version":"5.6.3"}
{"root":["./src/index.ts","./src/commands/config/account/import.ts","./src/commands/config/udt/register.ts","./src/commands/udt/transfer.ts","./src/commands/udt/extended/mint.ts","./src/commands/udt/metadata/decimals.ts","./src/commands/udt/metadata/name.ts","./src/commands/udt/metadata/symbol.ts","./src/commands/udt/pausable/enumerate-paused.ts","./src/commands/udt/pausable/is-paused.ts","./src/libs/config.ts","./src/libs/default.ts","./src/libs/utils.ts"],"version":"5.6.3"}

0 comments on commit ead30cc

Please sign in to comment.