【问题标题】:How to find on Daml-dazl app a transaction by key?如何在 Daml-dazl app 上通过密钥查找交易?
【发布时间】:2020-04-27 21:16:36
【问题描述】:

例如在这样的智能合约中:

daml 1.2
module Example where

template Account with
    owner : Party
    number : Text
    money : Int
  where
    signatory owner
    key (owner, number) : (Party, Text)
    maintainer key._1

可以根据模板的特定值查询交易

import dazl

network = dazl.Network()
def main():

 with dazl.simple_client('http://localhost:6865', 'Alice') as client:
    # wait for the ACS to be fully read
    client.ready()
    allContracts = client.find(template = "Example.Account")
    for contract in allContracts:
      if contract.cdata ["money"] == 10000:
        print("The query is" )
        print(contract.cdata)

if __name__ == '__main__':
    main()

但是,如何根据key进行查询呢?

【问题讨论】:

    标签: python daml


    【解决方案1】:

    目前唯一的方法是查询与密钥中完全相同的条件(不幸的是,这与模型重复了代码):

    all_contracts = clients.find("Example.Account", {"owner": "blah", "number": "blah"})
    if all_contracts:
       # something exists
      ...
    else:
       # nothing found
       ...
    

    我添加了一个问题来捕获此功能请求:https://github.com/digital-asset/dazl-client/issues/85

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 2014-04-12
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多