Stream Smart Filter: Get Transaction Information through TxID

+3 votes

While I was developing a Smart Filter I encountered a situation where the streamItem.keys[0] was a transactionID and I had to get information about that transactionID. 

Basically, I needed a function 

getTransaction :: TxID -> { TransationInfo } 
where I could pass a transaction ID and receive more information about that transaction. 

Use-Case: The user is posting some data into the stream, referring (through a txID in the key), that this new data is supposed to replace an older item with said ID, and I need to make sure that this old ID exists (and a few other properties as well). 

asked Mar 26, 2019 by tloriato

1 Answer

+2 votes

I'm afraid it's not possible to query the blockchain by txid from within smart filter code, since not every node will necessarily have a full index of transactions (see txindex runtime parameter). But it may be something we add in future.

In the meantime perhaps you can represent the replacement logic by using the same stream item key as the original item, rather than pointing to the txid of the original item in that key. This is how we designed streams to be used.

answered Mar 27, 2019 by MultiChain
I'm sorry, I don't think I understood it very well. Let's say I publish an invoice with keys = [a, b, c]. And then for some reason I need to republish it and "cancel" the first one. I should publish this new item with the same keys = [a, b, c] and then implementing the replacement logic off-chain?

Or maybe I should create a new stream for replacements, and then they publish the new one there with keys [ otherStreamName, a, b, c]?

Hm... I'm not sure if any of them would work but I'll think a little. It seems to add a little complexity on the question: "Was this invoice replaced?", but probably easier than me implementing this.
Yes, you would publish the new invoice under the same key or keys.

At retrieval time you can then decide what to do, for example:

Most recent version: liststreamkeyitems stream1 key1 false 1
First version: liststreamkeyitems stream1 key1 false 1 0
Full history: liststreamkeyitems stream1 key1 false 999999
When passing a key as ['value1, 'value2', 'value3'], does Multichain consider each value an individual key associated with that item? Or is it the array the key? I say this because the old invoice would have [ a, b, c, keyA] and the new invoice would have [d, b, e, keyA, keyB] , and I'd like it to list all items on the stream with keyA in them, for instance?
If you pass the parameters correctly (using MultiChain 2.0 with a chain that was upgraded) then each of them is an individual key.