CrowdCell Campaign 类型脚本 约束CrowdCell Campaign Type Script Constraints

来源:alesfer001/CrowdCell / contracts/campaign/src/main.rs@2fd13f6 · 0x1d9b…659c (data2,仅测试网) · 社区合约,未经独立审计Source: alesfer001/CrowdCell / contracts/campaign/src/main.rs@2fd13f6 · 0x1d9b…659c (data2, testnet only) · community contract, not independently audited
Type 脚本Type scriptDeFiDeFi测试网Testnet开源Open source社区Community

0 → 1创建众筹Create campaign

Inputs 输入Inputs
首个 inputfirst input任意 cell(决定 TypeID)any cell (seeds the TypeID)
➜
Outputs 输出Outputs
campaignCell{ type: { codeHash: CAMPAIGN, args: type_id 32B ‖ pledge_lock_code_hash 32B }, data: creator_lock_hash ‖ funding_goal>0 ‖ deadline_block>0 ‖ total_pledged=0 ‖ status=0 ‖ reserved ‖ metadata }
type args 字节布局(64B)type args byte layout (64B)
type_id32B
pledge_lock_code_hash32B
  • type_id 32B TypeIDTypeID check_type_id(0,32)check_type_id(0,32) (12)
  • pledge_lock_code_hash 32B pledge-lock 的 code_hashcode hash of pledge-lock 非全零non-zero (15)
campaign data 字节布局(≥65B)campaign data byte layout (≥65B)
creator_lock_hash32B
funding_goal8B
deadline_block8B
total_pledged8B
status1B
reserved‖metadata8B+
  • creator_lock_hash 32B 创建者 lock hashcreator lock hash 不可变immutable
  • funding_goal 8B 目标 u64 LE(shannon)goal u64 LE (shannons) 创建时 > 0;不可变> 0 at creation; immutable (3)
  • deadline_block 8B 截止区块 u64 LEdeadline block u64 LE 创建时 > 0;不可变> 0 at creation; immutable (4)
  • total_pledged 8B 累计认捐 u64 LEaccumulated pledges u64 LE 创建时 = 0= 0 at creation (5)
  • status 1B 0 Active · 1 Success · 2 Failed0 Active · 1 Success · 2 Failed 其它值 → 2other values → 2 (2)
  • reserved‖metadata 8B+ 保留 8B + 元数据尾部8B reserved + metadata tail [57..] 不可变,长度不变[57..] immutable, length unchanged

限制Constraints

  • args:: TypeID 校验失败TypeID check fails (12)
  • args:: 长度 ≥ 64 且 pledge_lock_code_hash ≠ 0length ≥ 64 and pledge_lock_code_hash ≠ 0 (15)
  • group:: group 内输入、输出各至多 1 个at most 1 group input and 1 group output (21)
  • data ≥ 65 字节≥ 65 bytes (1)
  • data[56]:: status ∈ {0,1,2}status ∈ {0,1,2} (2)
  • funding_goal > 0> 0 (3)
  • deadline_block > 0(不检查是否在未来)> 0 (not checked to be in the future) (4)
  • total_pledged = 0= 0 (5)
  • status = 0 Active= 0 Active (6)

1 → 1认捐:累计器更新(Active → Active)Pledge: accumulator update (Active → Active)

Inputs 输入Inputs
campaignCell{ capacity: C, data: …total_pledged = T, status = 0 }
可选:旧 pledgeoptional: consumed pledgesCell{ lock: { codeHash: pledge_lock_code_hash, args: campaign_type_hash ‖ … } }
➜
Outputs 输出Outputs
campaignCell{ capacity ≥ C, data: total_pledged = T + Σnew − Σold, status = 0, 其余字段不变 }Cell{ capacity ≥ C, data: total_pledged = T + Σnew − Σold, status = 0, other fields unchanged }
pledgeCell{ lock: { codeHash: pledge_lock_code_hash, args: campaign_type_hash ‖ deadline ‖ backer_lock_hash }, data(72B)[64..72] = amount ≥ 100 CKB, capacity ≥ amount + occupied }

限制Constraints

  • capacity:: 输出 campaign capacity ≥ 输入output campaign capacity ≥ input (17)
  • status:: 旧状态必须为 Activeold status must be Active (16)
  • data:: creator_lock_hash / funding_goal / deadline_block / 长度 / [57..] 不变creator_lock_hash / funding_goal / deadline_block / length / [57..] unchanged (16)
  • pledge data:: 属于本 campaign 的 pledge cell data ≥ 72 字节pledge cell data of this campaign ≥ 72 bytes (16)
  • amount:: 新建 pledge 的 amount ≥ 100 CKB(10,000,000,000 shannon)new pledge amount ≥ 100 CKB (10,000,000,000 shannons) (23)
  • capacity:: pledge capacity ≥ amount + occupied capacitypledge capacity ≥ amount + occupied capacity (22)
  • total_pledged:: Σ新建 > Σ消耗,且新 total = 旧 total + 差值Σcreated > Σconsumed, and new total = old total + delta (16)
  • u64:: 累加溢出addition overflows (19)

1 → 2结算:Active → Success / FailedFinalize: Active → Success / Failed

Inputs 输入Inputs
campaignCell{ data: status = 0 }, since = 绝对区块号 ≥ deadline_blockCell{ data: status = 0 }, since = absolute block ≥ deadline_block
➜
Outputs 输出Outputs
campaignCell{ capacity ≥ C, data: total_pledged 不变, status = total ≥ goal ? 1 : 2 }Cell{ capacity ≥ C, data: total_pledged unchanged, status = total ≥ goal ? 1 : 2 }

限制Constraints

  • capacity:: 输出 capacity ≥ 输入output capacity ≥ input (17)
  • since:: 非 0、绝对、标志合法、按区块号,且 ≥ deadline_blocknon-zero, absolute, valid flags, block number, ≥ deadline_block (10)
  • status:: 旧状态 Active;新状态不能是 Activeold status Active; new status not Active (10)
  • data:: 不可变字段与 total_pledged 不变immutable fields and total_pledged unchanged (10)
  • status:: Success 要求 total ≥ goal;Failed 要求 total < goalSuccess requires total ≥ goal; Failed requires total < goal (18)

2 → 0销毁已结算的 campaignDestroy a finalized campaign

Inputs 输入Inputs
campaignCell{ capacity: C, data: status ∈ {1,2} }, since = 绝对区块号 ≥ deadline + 1,944,000Cell{ capacity: C, data: status ∈ {1,2} }, since = absolute block ≥ deadline + 1,944,000
➜
Outputs 输出Outputs
创建者creatorΣ Cell{ lock hash = creator_lock_hash }.capacity ≥ C − 1 CKB

限制Constraints

  • status:: Active 不可销毁Active cannot be destroyed (13)
  • inputs:: 同一交易中不得花费任何 pledge-lock cellno pledge-lock cell may be spent in the same tx (25)
  • outputs:: 付给 creator_lock_hash 的 capacity ≥ C − 1 CKBcapacity paid to creator_lock_hash ≥ C − 1 CKB (24)
  • since:: 非 0、绝对区块号且 ≥ deadline_block + 1,944,000(约 180 天)non-zero absolute block ≥ deadline_block + 1,944,000 (~180 days) (13)
部署与来源Deployments & source 未核验unverified
源码source alesfer001/CrowdCell@2fd13f6b · contracts/campaign/src/main.rs (main HEAD read 2026-10-22; author Ayoub_Lesfer (Nervos Talk) offered CrowdCell in https://talk.nervos.org/t/11014/2. Testnet only; deployment from README / deployment/deployed-contracts-testnet.json, hash_type data2 from off-chain/frontend/src/lib/constants.ts)
二进制核验binary check 未核验unverified hash appears in the repo only as a deployment record or doc, which does not prove the recorded commit builds this binary (reproducible build not attempted)
0x1d9b9e5959…3bd2659c: listed in README.md; listed in deployment/deployed-contracts-devnet.json; listed in deployment/deployed-contracts-testnet.json
网络networkcode_hashcell_deptype_id args数据哈希data hash部署交易deploy tx
testnet0x1d9b9e5959c932c0ff6486e03cd69d0e51a6b087dacf80b909c23d713bd2659c data20x609fbcf588…de9ca1ba:0 code—0x1d9b9e5959…3bd2659c0x609fbcf588…de9ca1ba #22448242
链上数据核对于 on-chain data checked 2026-10-22
错误码(main.rs):1 data 过短 · 2 status 非法 · 3 goal=0 · 4 deadline=0 · 5 创建时 total≠0 · 6 创建时非 Active · 7 NO_SCRIPT · 9 LOAD_DATA · 10 INVALID_FINALIZATION · 12 INVALID_TYPE_ID · 13 DESTRUCTION_NOT_ALLOWED · 14 LOAD_SINCE · 15 INVALID_ARGS · 16 INVALID_PLEDGE_UPDATE · 17 CAPACITY_DECREASED · 18 STATUS_NOT_JUSTIFIED · 19 OVERFLOW · 20 LOAD_CELL · 21 MULTIPLE_CAMPAIGN_CELLS · 22 PLEDGE_UNDERFUNDED · 23 PLEDGE_BELOW_MINIMUM · 24 CREATOR_NOT_PAID · 25 DESTRUCTION_WITH_PLEDGES(11 MODIFICATION_NOT_ALLOWED 已定义但未使用)Error codes (main.rs): 1 data too short · 2 bad status · 3 goal=0 · 4 deadline=0 · 5 total≠0 at creation · 6 not Active at creation · 7 NO_SCRIPT · 9 LOAD_DATA · 10 INVALID_FINALIZATION · 12 INVALID_TYPE_ID · 13 DESTRUCTION_NOT_ALLOWED · 14 LOAD_SINCE · 15 INVALID_ARGS · 16 INVALID_PLEDGE_UPDATE · 17 CAPACITY_DECREASED · 18 STATUS_NOT_JUSTIFIED · 19 OVERFLOW · 20 LOAD_CELL · 21 MULTIPLE_CAMPAIGN_CELLS · 22 PLEDGE_UNDERFUNDED · 23 PLEDGE_BELOW_MINIMUM · 24 CREATOR_NOT_PAID · 25 DESTRUCTION_WITH_PLEDGES (11 MODIFICATION_NOT_ALLOWED is defined but unused)
pledge 归属判定用 pledge cell 的 lock(code_hash = args[32..64] 且 lock args[0..32] = 本 campaign type hash),pledge data 里的 campaign_id 仅作信息A pledge belongs to the campaign by its lock (code_hash = args[32..64] and lock args[0..32] = this campaign's type hash); campaign_id in pledge data is informational
谁能花费 campaign cell(以及截止前能否结算)由 campaign-lock 决定,本页不覆盖;pledge cell 自身的 type 规则见 CrowdCell 的 pledge 类型脚本(未收录)Who may spend the campaign cell is decided by campaign-lock (not covered here); pledge cells' own type rules live in CrowdCell's pledge type script (not included)
非本合约规则:README 的 ~180 天按 8 秒/块估算Not a contract rule: the README's ~180 days assumes 8 s blocks
CrowdCell 自述为测试网预览,合约已由 CKB 开发者审阅但未经独立审计CrowdCell describes itself as a testnet preview; contracts reviewed by CKB developers but not independently audited
GitHub · gpBlockchain/ckb-contract-flow-html