Is it possible to access data stored in lists within contracts directly from the Api calls? I have noticed something like this in some daml
code from here.
let p2Account = (fromSome (ci.d.party!!1).account).accountNumber
Perhaps something like this…
getValue(c, "payload.d.someList[0]")
Or is the only way to access this data from first collecting the array of contract information, then extracting the array, and then writing some javascript to unpack the information?
const contractWithSomeList = getValue(c, "payload.d.someList)
const someList = someList.map(...)
1 Like
I’m not quite sure from your question where you are getting the contract data from, or indeed what your getValue
function is.
If you are getting your data from the JSON API, Daml List
s are returned as JSON arrays so you can access them as you’d expect using []
notation.
If you are getting your data from the gRPC API, you do need to do a bit of unwrapping.
3 Likes
Hi @jamesljaworski85,
The JSON API does not have any facility for requesting parts of a contract, as far as I’m aware. You have various ways of customizing how you match a contract, but if your query matches a contract, you get the entire contract.
If it is important in your use-case that only parts of a contract travels on the wire, you’ll need to work around that by using choices. Those could be nonconsuming choices on some “permanent” contract or on the contracts you’re trying to query themselves, or you could set up some consuming choices on one-use contracts for use with createAndExecute
(probably not recommended if you expect a lot of queries).
Note that even if you were willing to go down that route, it’s not quite clear how you would safely parse a string like "payload.d.someList[0]"
on the Daml side.
If you are not concerned with bandwidth, but instead just want a JS-side query language, that becomes a bit easier (though no safer).
1 Like
Hey @Gary_Verhaegen and @bernhard . Thanks for your reply.
I hadn’t thought of the importance of maintaining the entire contract as a whole. I was more looking for a shortcut to access the information inside the contract.
But based on the downstream effects described above it definitely creates more hurdles than it’s worth.
1 Like