======================== CODE SNIPPETS ======================== TITLE: Deploying Pausable UDT Contract with ckb-cinnabar (Bash) DESCRIPTION: Deploys the `pausable-udt` contract using `ckb-cinnabar`. It specifies the contract name, a tag for versioning, a payer address for transaction fees, and enables Type ID generation for easier upgrades. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_15 LANGUAGE: Bash CODE: ``` ckb-cinnabar deploy --contract-name pausable-udt --tag transaction.v241112 --payer-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtxe0gs9yvwrsc40znvdc6sg4fehd2mttsngg4t4 --type-id ``` ---------------------------------------- TITLE: Migrating Pausable UDT Contract with ckb-cinnabar (Bash) DESCRIPTION: Migrates the `pausable-udt` contract from an older version tag to a newer one using `ckb-cinnabar`. This command simplifies the process of upgrading deployed contracts on the CKB network. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_16 LANGUAGE: Bash CODE: ``` ckb-cinnabar migrate --contract-name pausable-udt --from-tag v241030.1 --to-tag v241030.2 ``` ---------------------------------------- TITLE: UDT Transfer Recipe Configuration in YAML DESCRIPTION: This YAML snippet outlines the input and output cell configurations for a UDT transfer operation within the `pausable-udt` contract. It specifies the `pausable-udt-cell` with its type (code and args) and lock (User Lock A/B), along with the data (amount). It also mentions an optional `external-pausableData-cell` dependency. This recipe illustrates the expected structure of transaction components for transferring UDTs, emphasizing the check for paused lock hashes. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_2 LANGUAGE: YAML CODE: ``` Inputs: pausable-udt-cell: Type: code: args: Lock: Data: Dependencies: external-pausableData-cell: # Only if external pause list is enabled. Data: UDTPausableData Outputs: pausable-udt-cell: Type: code: args: Lock: Data: pausable-udt-cell: Type: code: args: Lock: Data: ``` ---------------------------------------- TITLE: Sending Pausable UDT Transaction via SSRI Server (TypeScript) DESCRIPTION: Demonstrates how to send a constructed JSON-RPC payload to the local SSRI server, unpack the transaction, complete its inputs and fees, and then send it to the CKB network. It includes error handling for the request. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_14 LANGUAGE: TypeScript CODE: ``` try { const response = await axios.post(process.env.SSRI_SERVER_URL!, payload, { headers: { "Content-Type": "application/json" }, }); const mintTx = blockchain.Transaction.unpack(response.data.result); const cccMintTx = ccc.Transaction.from(mintTx); await cccMintTx.completeInputsByCapacity(signer); await cccMintTx.completeFeeBy(signer); const mintTxHash = await signer.sendTransaction(cccMintTx); this.log( `Mint ${args.toAmount} ${args.symbol} to ${args.toAddress}. Tx hash: ${mintTxHash}` ); } catch (error) { console.error("Request failed", error); } ``` ---------------------------------------- TITLE: Pause/Unpause Recipe Configuration in YAML DESCRIPTION: This YAML snippet details the input, output, and dependencies for the `Pause / Unpause` operation, which is available only when using an external pausable data cell. It defines the `proxy-lock-cell` and `external-pausable-data-cell` with their respective types, locks, and data. This recipe demonstrates how administrators can modify the pausing policies by adding or removing lock hashes from the pause list, highlighting the role of multisig and proxy locks for governance. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_3 LANGUAGE: YAML CODE: ``` Inputs: proxy-lock-cell: Type: code: args: Lock: external-pausable-data-cell: Type: code: args: Lock: code: args: Data: UDTMetadataData Dependencies: Outputs: proxy-lock-cell: Type: code: args: Lock: external-pausable-data-cell: Type: code: args: Lock: code: args: Data: UDTMetadataData ``` ---------------------------------------- TITLE: Defining UDTPausableData and ScriptLike Structures in Rust DESCRIPTION: This Rust snippet defines two key data structures: `UDTPausableData` and `ScriptLike`. `UDTPausableData` holds the `pause_list` (a vector of 32-byte lock hashes) and an optional `next_type_script` for chaining external pause lists. `ScriptLike` represents a generic CKB script with `code_hash`, `hash_type`, and `args`. These structures are used for serializing and deserializing data related to the pausable UDT contract, enabling the contract to maintain and refer to the pause list. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_1 LANGUAGE: Rust CODE: ``` use serde::{Serialize, Deserialize}; use serde_molecule::{to_vec, from_slice}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct UDTPausableData { pub pause_list: Vec<[u8; 32]>, pub next_type_script: Option } #[derive(Serialize, Deserialize, Clone, Debug)] pub struct ScriptLike { pub code_hash: [u8; 32], pub hash_type: u8, pub args: Vec, } ``` ---------------------------------------- TITLE: Querying Pausable UDT Decimals Payload (TypeScript) DESCRIPTION: Defines the JSON-RPC payload to query the decimal places of the Pausable UDT. It uses the `run_script_level_code` method, providing the matching cell dependency and the decimal query path. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_11 LANGUAGE: TypeScript CODE: ``` const payload = { id: 2, jsonrpc: "2.0", method: "run_script_level_code", params: [ matchingCellDep.outPoint.txHash, Number(matchingCellDep.outPoint.index), [decimalPathHex], ], }; ``` ---------------------------------------- TITLE: Querying Pausable UDT Symbol Payload (TypeScript) DESCRIPTION: Defines the JSON-RPC payload to query the symbol of the Pausable UDT. It uses the `run_script_level_code` method, providing the matching cell dependency and the symbol query path. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_13 LANGUAGE: TypeScript CODE: ``` const payload = { id: 2, jsonrpc: "2.0", method: "run_script_level_code", params: [ matchingCellDep.outPoint.txHash, Number(matchingCellDep.outPoint.index), [symbolPathHex], ], }; ``` ---------------------------------------- TITLE: Querying Pausable UDT Name Payload (TypeScript) DESCRIPTION: Defines the JSON-RPC payload to query the name of the Pausable UDT. It uses the `run_script_level_code` method, providing the matching cell dependency and the name query path. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_12 LANGUAGE: TypeScript CODE: ``` const payload = { id: 2, jsonrpc: "2.0", method: "run_script_level_code", params: [ matchingCellDep.outPoint.txHash, Number(matchingCellDep.outPoint.index), [namePathHex], ], }; ``` ---------------------------------------- TITLE: Defining UDT and UDTPausable Traits in Rust DESCRIPTION: This snippet defines the `UDT` and `UDTPausable` public module traits in Rust, which are part of the `ckb_ssri_sdk`. The `UDT` trait specifies standard UDT operations like balance, transfer, and mint, while the `UDTPausable` trait extends `UDT` by adding functionalities such as pause, unpause, and checking pause status. These traits provide a standardized interface for SSRI-compliant contracts, enabling discoverability and predictable interactions for dApps and infrastructure. SOURCE: https://github.com/alive24/pausable-udt/blob/master/README.md#_snippet_0 LANGUAGE: Rust CODE: ``` pub trait UDT { type Error; fn balance() -> Result; fn transfer( tx: Option, to_lock_vec: Vec