-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chunteng-web3
committed
Nov 8, 2024
1 parent
421c36e
commit ead30cc
Showing
10 changed files
with
226 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |