【问题标题】:Kadena Pact Property CheckKadena Pact 财产检查
【发布时间】:2022-11-19 21:49:28
【问题描述】:

Pact 语言有一个属性系统。 对于少于 3 个字符和多于 256 个字符的帐户,对 create-account 的调用应该会失败。但是,我无法让它发挥作用。

这是REPL单元测试的结果。

我原以为名称短于 3 个字符的 create-account 调用会失败。

"FAILURE: empty account names fail to create: expected failure, got result = "Write succeeded""
"FAILURE: account names not >= 3 chars fail: expected failure, got result = "Write succeeded""
"FAILURE: account names not <= 256 chars fail: expected failure, got result = "Write succeeded""

使用验证 ID 创建帐户功能

  (defun create-account:string
    ( account:string
      guard:guard )

    @doc " Create a new account. "

    @model [ (property (valid-account-id account)) ]
    (enforce-reserved account guard)

    (insert token-table account
      { "balance" : 0.0
      , "guard"   : guard
      }
    )
  )

这是模型定义

(module k-token GOVERNANCE

  @doc "K token smart contract"

  @model
    [ (defproperty conserves-mass (amount:decimal)
        (= (column-delta token-table 'balance) 0.0))

      (defproperty valid-account-id (accountId:string)
        (and
          (>= (length accountId) 3)
          (<= (length accountId) 256)))
    ]

【问题讨论】:

    标签: pact-lang kadena


    【解决方案1】:

    属性和模型不在链上使用...它们仅用于形式验证。

    您的create-account 应该调用一个函数来验证帐户字符串。您可以以硬币模块及其功能(验证帐户)为例。

    感谢 Kadena discord 频道上的Pascal3125

    【讨论】:

      猜你喜欢
      • 2022-12-03
      • 2013-01-09
      • 2015-03-05
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多