Rohit Khatri
Rohit Khatri

Reputation: 2018

How to query transactions for a particular resource in hyperledger sawtooth

I am doing multiple transactions like location update for an asset, and couldn't find any way to query the transactions based on that resource:

For example If I create an asset fish1, and then make transactions to update the location of the fish, now I want to fetch the transactions for the fish1 so I can get a list of geopoints and plot them on the map.

If anyone has done something like this, please help. Thanks

Upvotes: 3

Views: 683

Answers (1)

Frank C.
Frank C.

Reputation: 8088

On-chain solutions

There are two approaches depending on how you 'update' the location.

  1. If you are updating information at the same address then you must take precaution to capture all the updates. This assumes the asset has a collection that it can add to at transaction time. Using this approach it would be simply a matter of fetching the address data (using /state/ REST-API call) and splaying out the collection of data updates however you want.
  2. On the other hand, if each update results in a new piece of data being added to the blockchain then you would be using some address scheme (I assume) where you can use a prefix in the '/state?address=xxx` call to collect all asset updates. You would probably want to also fetch the block to determine order unless the data at each address captures some kind of time information to sort on.

There are pros and cons using either approach of course.

Off-chain solutions

Sawtooth provides an Event registry where a client (of some kind) can register Event listeners to store data off-chain in any form the application requires. This is often suggested for solutions that have a broad/rich querying need as the sawtooth Merkle Trie (where blockchain data is stored) does not offer this flexibility.

Upvotes: 5

Related Questions