pact-lang - 如何创建一个 KDA 钱包防护,允许任意数量的人在满足特定条件的情况下从中提款?

标签 pact-lang kadena

问题:如何创建一个钱包保护程序,允许任意数量的人在满足特定条件的情况下从中提款?

我正在尝试制作一个带有保护装置的钱包,让用户根据他们拥有 NFT 的时间等因素,从钱包中提取特定金额。现在我正在做最基本的检查:查看传递到声明函数的“接收者”地址是否是特定 NFT 的所有者。如果他们拥有该 NFT,他们可以想提取多少就提取多少。

   (defcap WITHDRAW (recipient:string nft-id:string)
        (with-read mledger nft-id
            {'owner-address := owner-address }
            (enforce (= recipient owner-address) "not the owner of this NFT")
        )
        (compose-capability (BANK_DEBIT))
    )

    (defun require-WITHDRAW (recipient:string nft-id:string) 
        (require-capability (WITHDRAW recipient nft-id))
    )

    (defun create-WITHDRAW-guard (recipient:string nft-id:string)
        (create-user-guard (require-WITHDRAW recipient nft-id))
    )

    (defun create-simple-user-guard (funder:string nft-id:string BANK_KDA_ACCT:string amount:decimal recipient:string)
        (coin.transfer-create funder BANK_KDA_ACCT 
          (create-WITHDRAW-guard recipient nft-id) amount)
    )

使用我当前的代码,只有我传入的第一个输入 (create-simple-user-guard) 会影响谁可以撤回,但我不知道如何允许守卫接受许多不同的收件人和 NFT-id 。任何建议将不胜感激。

我正在关注这个“教程”https://medium.com/kadena-io/deprecation-notice-for-module-guards-and-pact-guards-2efbf64f488f但在实现更强大的借记功能后,它会丢失任何数量的细节

最佳答案

假设您的 nft-id 可以引用一个集合,而不仅仅是一个单独的 NFT,则此代码应该允许任何拥有该集合的个人从合约中索取某些内容。

(defcap WITHDRAW (nft-id:string)
  (with-read mledger nft-id
      {'owner-address := owner-address }
      (enforce (= (read-msg "recipient") owner-address) "not the owner of this NFT")
  )
  (compose-capability (BANK_DEBIT))
)

(defun require-WITHDRAW (nft-id:string) 
  (require-capability (WITHDRAW nft-id))
)

(defun create-WITHDRAW-guard (nft-id:string)
  (create-user-guard (require-WITHDRAW nft-id))
)

(defun create-simple-user-guard (funder:string nft-id:string BANK_KDA_ACCT:string amount:decimal)
  (coin.transfer-create funder BANK_KDA_ACCT 
    (create-WITHDRAW-guard nft-id) amount)
)

请记住,此代码要求您以这种方式将recipient传递到交易的环境数据中:

{ "recipient": "k:abcd..." }

希望这有帮助!

关于pact-lang - 如何创建一个 KDA 钱包防护,允许任意数量的人在满足特定条件的情况下从中提款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74168590/

相关文章:

module - 在 PACT 中存储和检索模块引用

cryptocurrency - 尝试在测试网上初始化 kadena token - readrow 错误数据库错误

pact-lang - 如何在 Windows 上安装 Pact?

pact-lang - Pact 形式验证属性

pact-lang - 在函数中键入变量

atom-editor - 如何注释掉 Pact 中的代码块?

pact-lang - Kadena 无法在命名空间之外定义键集错误