Hyperledger fabric 创建daml合同时是否可以生成日期

Hyperledger fabric 创建daml合同时是否可以生成日期,hyperledger-fabric,blockchain,daml,digital-assets,Hyperledger Fabric,Blockchain,Daml,Digital Assets,我想得到daml合同创建时的系统日期。有没有办法做到这一点 例如:- 模块示例TemplateModule其中 模板示例模板 with admin: Party todayDate: Date --- In place of this can I use getDate and get today's date where signatory admin 我知道我可以在脚本do块中执行此操作,但我希望在必须

我想得到daml合同创建时的系统日期。有没有办法做到这一点

例如:-

模块示例TemplateModule其中

模板示例模板

with

    admin: Party 

    todayDate: Date     --- In place of this can I use getDate and get today's date
                       
where

    signatory admin

我知道我可以在脚本do块中执行此操作,但我希望在必须创建合同时执行此操作。如果这是不可能的,是否有其他方法可以在创建daml合同时获取系统日期。

您无法在创建中直接获取时间。但是,您可以在选择中获得时间,然后根据该时间创建合同。该选项可以是非消费性的,您只能创建一个调用该选项的助手合约,也可以是消费性的,您可以通过
createAndExercise
调用该选项。下面是一个完整的示例,说明了这两个选项:

module ExampleTemplateModule where

import DA.Date
import Daml.Script

template ExampleTemplate
  with
    admin: Party
    todayDate: Date     --- In place of this can I use getDate and get today's date
  where
    signatory admin

template Helper
  with
    admin : Party
  where
    signatory admin
    nonconsuming choice CreateExampleTemplate : ContractId ExampleTemplate
      controller admin
      do time <- getTime
         create ExampleTemplate with admin = admin, todayDate = toDateUTC time
    choice CreateExampleTemplate' : ContractId ExampleTemplate
      controller admin
      do time <- getTime
         create ExampleTemplate with admin = admin, todayDate = toDateUTC time


test = script do
  p <- allocateParty "p"
  helper <- submit p $ createCmd (Helper p)
  ex1 <- submit p $ exerciseCmd helper CreateExampleTemplate
  e2 <- submit p $ createAndExerciseCmd (Helper p) CreateExampleTemplate'
  pure ()
模块示例TemplateModule其中
进口日期
导入Daml.Script
模板示例模板
具有
管理员:派对
todayDate:Date--我可以使用getDate和获取今天的日期来代替它吗
哪里
签名管理员
模板助手
具有
管理员:派对
哪里
签名管理员
非消耗性选择CreateExampleTemplate:CompactId ExampleTemplate
控制器管理员
做时间