Skip to main content

Crate ckb_transaction_firewall_sdk

Crate ckb_transaction_firewall_sdk 

Source
Expand description

§ckb-transaction-firewall-sdk

Off-chain pre-flight blacklist check for CKB transactions.

Before broadcasting a transaction, call check_transaction to verify that no output’s lock or type args appear in the on-chain BLKL v2 blacklist registry. The check mirrors what the on-chain firewall-lock contract enforces at execution time, letting wallets and dApps reject blacklisted transactions early without spending UTXOs.

§Quick start

use ckb_transaction_firewall_sdk::{
    check_transaction, FirewallConfig, RegistrySpec, HashType,
    CellDepLike, ScriptLike, TxOutputLike, UnsignedTxLike,
};

// Identify the registry cell dep by its type_id_value (bytes 34-66 of
// the registry type-script args). This is stable across governance upgrades.
let spec = RegistrySpec {
    code_hash: [0u8; 32],   // replace with actual code hash
    hash_type: HashType::Type,
    type_id_value: [0u8; 32], // replace with actual type id value
    required: true,
};

let cfg = FirewallConfig { registries: vec![spec] };

// Build the transaction (with the live registry cell as a cell dep)
let tx = UnsignedTxLike {
    cell_deps: vec![/* ... live registry cell dep ... */],
    outputs: vec![TxOutputLike {
        lock_args: vec![0xde, 0xad],
        type_args: None,
    }],
};

let now_secs = std::time::SystemTime::now()
    .duration_since(std::time::UNIX_EPOCH)
    .unwrap()
    .as_secs();

match check_transaction(&cfg, &tx, now_secs) {
    Ok(()) => println!("transaction is clean"),
    Err(e) => println!("blocked: {} (code {})", e, e.code()),
}

§Feature flags

  • serde — derives Serialize / Deserialize on all public types.
  • testnet — exposes the [testnet] module with testnet RPC URL, governance constants, and deployed contract outpoints.

Re-exports§

pub use builder::build_firewall_lock_args;
pub use builder::build_firewall_lock_script;
pub use builder::build_firewall_spend_cell_deps;
pub use errors::error_codes;
pub use errors::FirewallError;
pub use firewall::check_transaction;
pub use firewall::is_blacklisted;
pub use firewall::preflight_check;
pub use registry::encode_governance_header;
pub use registry::encode_registry_payload;
pub use registry::parse_registry_payload;
pub use types::CellDepLike;
pub use types::DepType;
pub use types::FirewallConfig;
pub use types::FirewallLockConfig;
pub use types::FirewallSpendDepsConfig;
pub use types::GovernanceHeader;
pub use types::HashType;
pub use types::OutPointLike;
pub use types::RegistryEntry;
pub use types::RegistryPayload;
pub use types::RegistrySpec;
pub use types::ScriptLike;
pub use types::TransactionCellDep;
pub use types::TxOutputLike;
pub use types::UnsignedTxLike;

Modules§

builder
errors
firewall
registry
types