mcpField
P
plutus-v3-conway

plutus-v3-conway

github.com/flux-point-studios开发840 次安装5 周前更新
代码仓库

关于 plutus-v3-conway

plutus-v3-conway 是面向 Cardano 开发者的指导 Skill,涵盖 Plutus V2 到 V3 的迁移及 Conway 治理脚本编写。它重点说明 V3 接口、可选 datum、新脚本用途和迁移后的哈希变化。

主要功能

  1. 01讲解 V2 到 V3 的接口迁移
  2. 02说明可选 datum 的处理方式
  3. 03介绍投票与提案脚本用途
  4. 04解释 V3 返回类型变化
  5. 05提供治理脚本示例与测试提示

适用场景

  1. 01将 Plutus V2 验证器迁移到 V3
  2. 02编写 Conway 投票或提案脚本
  3. 03检查迁移后脚本哈希与地址

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/flux-point-studios/cardano-agent-skills --skill plutus-v3-conway

安装后在 Claude Code 中输入/plutus-v3-conway确认已加载。

附带文件reference/v3-notes.md

详细介绍

plutus-v3-conway

适用场景

  • 从 Plutus V2 迁移到 V3
  • 编写治理脚本(投票、提案)
  • 了解 Conway 时代的脚本变更

操作规则(必须遵守)

  • 确认目标网络支持 Conway
  • 在测试网上充分测试所有治理脚本
  • 不要混淆 V2 和 V3 的思维模型

V3 的关键变更

1. 统一的上下文参数
V2: validator(datum, redeemer, context) → Bool
V3: validator(context) → ()  // datum/redeemer inside context
2. Datum 现在是可选的
  • 对于花费操作:如果不需要,datum 可以为 Nothing
  • 通过 ScriptContext.scriptInfo 访问
3. 新的脚本用途
Spending      - spending UTxOs (existing)
Minting       - minting/burning tokens (existing)
Rewarding     - withdrawing rewards (existing)
Certifying    - stake certificates (existing)
Voting        - governance voting (NEW in V3)
Proposing     - governance proposals (NEW in V3)
4. 返回类型变更
  • V2:返回 Bool(True/False)
  • V3:返回 ()(unit)——通过错误/trace 表示失败

V3 接口(Aiken)

花费验证器
validator my_validator {
  spend(
    datum: Option<MyDatum>,
    redeemer: MyRedeemer,
    _own_ref: OutputReference,
    tx: Transaction,
  ) {
    // Return () on success
    // Use expect/fail! for failure
    expect Some(d) = datum
    d.owner == get_signer(tx)
  }
}
治理验证器
validator governance {
  vote(
    redeemer: VoteRedeemer,
    voter: Voter,
    tx: Transaction,
  ) {
    // Validate voting logic
    True
  }

  propose(
    redeemer: ProposeRedeemer,
    tx: Transaction,
  ) {
    // Validate proposal logic
    True
  }
}

迁移检查清单(V2 → V3)

1. 更新验证器签名
// V2
fn spend(datum: Datum, redeemer: Redeemer, ctx: ScriptContext) -> Bool

// V3
fn spend(datum: Option<Datum>, redeemer: Redeemer, own_ref: OutputReference, tx: Transaction) -> ()
2. 处理可选 datum
// V3 - datum may be None
spend(datum: Option<Datum>, ...) {
  expect Some(d) = datum  // Fail if None when you need it
  // or
  when datum is {
    Some(d) -> handle_datum(d)
    None -> handle_no_datum()
  }
}
3. 更新返回逻辑
// V2 - return Bool
if condition { True } else { False }

// V3 - return () or fail
if condition { () } else { fail @"Condition not met" }
// or use expect
expect condition
4. 脚本哈希变更
  • V3 脚本的哈希与对应的 V2 脚本不同
  • 重新计算所有脚本地址
  • 更新所有硬编码的引用

示例

示例:简单的 V3 花费验证器
use aiken/collection/list
use cardano/transaction.{Transaction, OutputReference}

type Datum {
  owner: ByteArray,
}

type Redeemer {
  // empty
}

validator simple_lock {
  spend(
    datum: Option<Datum>,
    _redeemer: Redeemer,
    _own_ref: OutputReference,
    tx: Transaction,
  ) {
    expect Some(d) = datum
    list.has(tx.extra_signatories, d.owner)
  }
}
示例:治理投票脚本
use cardano/transaction.{Transaction}
use cardano/governance.{Voter, ProposalProcedure}

validator dao_governance {
  vote(
    redeemer: Data,
    voter: Voter,
    tx: Transaction,
  ) {
    // Check voter is authorized
    // Check voting rules are followed
    True
  }

  propose(
    redeemer: Data,
    proposal: ProposalProcedure,
    tx: Transaction,
  ) {
    // Check proposer has required stake
    // Check proposal format
    True
  }
}

Conway 治理上下文

DRep(委托代表)
  • 用户可以将投票权委托给 DRep
  • 脚本可以充当 DRep
宪法委员会
  • 通过多重签名治理协议变更
  • 脚本可以成为委员会成员
治理操作
  • 参数变更
  • 发起硬分叉
  • 国库提款
  • 宪法变更

V3 的 CLI 标志

# Build V3 script with Aiken
aiken build --plutus-version v3

# CLI transaction with V3 script
cardano-cli conway transaction build \
  --tx-in-script-file my_script_v3.plutus \
  ...

安全 / 密钥处理

  • 治理脚本风险重大——请充分测试
  • V3 治理会影响协议参数
  • 迁移后验证所有脚本哈希
  • 使用 preprod 测试治理流程

参考资料

评论

支持 Markdown