0

For example in a smart contract like this:

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

It is possible to query a transaction based on a specific value of the template

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()

However, how is possible to query based on key?

HectorCode
  • 205
  • 2
  • 11

1 Answers1

0

The only way to do this at the moment is to query on exactly the same condition you have in your key (which unfortunately duplicates code with the model):

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

I added an issue to capture this feature request going forward: https://github.com/digital-asset/dazl-client/issues/85

dtanabe
  • 1,611
  • 9
  • 18