Three days ago I asked the question of how to import 'Latest' blocks instead of 'Irreversible' ones. The problem with retrieving only immutable blocks from the Steemit API is that it takes about 20 blocks before they become immutable. One minute lag is far too long for a significant percentage of applications.
The drawback of using 'Latest' is that you might use information that get's deleted from the blockchain. This is something dapps need to deal with in the event of bad blocks being created. I'm not sure how often this happens, but I assume not very.
Regardless, I've finally found a solution, and the difference between 3-6 seconds of lag compared to 50-70 seconds is certainly worth the risk.
However, where does the Steemit API retrieve the blocks from? I figure if I get the blocks directly from the witnesses I can cut that 3-6 seconds into even less time. I guess I'll worry about that later.
In any case, this is supposed to work:
Bugged
client.blockchain.getOperationsStream({mode:dsteem.BlockchainMode.Latest})
This simply does not work. Took me quite a while to figure out it is just flat out bugged. Using getBlockStream() instead works just fine:
Works
client.blockchain.getBlockStream({mode:dsteem.BlockchainMode.Latest})
It turns out dsteem.BlockchainMode.Latest
actually just evaluates to 1
export enum BlockchainMode { /** * Only get irreversible blocks. / Irreversible, /* * Get all blocks. */ Latest, }
This is TypeScript... I'm not familiar with it, but apparently Latest just evaluates to 1 and Irreversible just evaluates to 0, so these are interchangeable. I assum enum is obviously short for enumerated so these things are just sitting in some kind of array being evaluated to integers.
Therefore, this code is equivalent to what I need (and how I am now writing it):
client.blockchain.getBlockStream({mode:1})
Another annoying thing about this whole situation is that importing the full blocks is a bit different than importing standalone operations. It took a few too many conversions in my code to make the switch.
Whatever, I did it... and I'm never going to import standalone operations again for various reasons including this bug. When it really comes down to it, it's smarter to import the full block so that you know you have everything and can database the information easier and with less worry that you have all the information.
Conclusion
Steemit API documentation is still abysmal.
The latest version of dsteem still doesn't work.
Using Version 10 still.
Hopefully after RocksDB they come back and fix stuff like this instead of trying to push more SMT nonsense.
Return from dsteem: getOperationsStream() Broken For "Latest" to edicted's Web3 Blog