vulpemventures / liquidjs-lib

A javascript Liquid library for node.js and browsers.
MIT License
27 stars 14 forks source link

Dynafed block parsing #23

Open asoltys opened 3 years ago

asoltys commented 3 years ago

With the dynafed upgrade going live soon, we'll need to be able to handle blocks with dynafed headers. @philippem linked me to this example that we could use as a test case: https://github.com/ElementsProject/rust-elements/blob/master/src/block.rs#L655

The Block.fromHex() method seems to have a problem handling it:

RangeError: value out of range

tiero commented 3 years ago

@asoltys we never touched block (de)serialization when forking from bitcoinjs. So the implementation has be done anyway since is missing also for pre-dynafed blocks.

We implemented that in go-elements tho, could be another reference.

Do you see any use case for browser block parsing? I would wait for neutrino support in Elements before doing any SPV like wallet in the browser

asoltys commented 3 years ago

I use it in the coinos nodejs app server to parse Blocks as they get received to check if any of the block transactions pertain to any of the wallet addresses we're tracking and update their confirmed status. Most people would probably use walletnotify in that case but we're tracking some HD wallets outside of elementsd. That said, I could probably use electrs or bwt for this instead, I think they just weren't around when I wrote the code for this.

Anyways, this isn't something I expect you guys to fix. I might try to take it on though so figured it would be good to have an issue for it. I managed to get pre-dynafed blocks parsing a while ago: https://github.com/asoltys/elementsjs-lib/commit/04547ed6934c95a63da56f23f0024b4b7c3b135d

tiero commented 3 years ago

@asoltys very interesting, thanks for the commit!

Let me see if we can allocate some time for it! Definitely interested in see the code you use to check transaction relative to an HD wallet in blocks, is it open source?

asoltys commented 3 years ago

Yes it's available here: https://github.com/coinos/coinos-server/blob/master/routes/liquid/receive.js#L190

Essentially it just loops over all the txn's in the block and checks if any were destined to an address that we have in our database which could be either from an HD wallet or our custodial node. If so, we update the payment record and user account in our db.

tiero commented 3 years ago

Thanks!

We are see to allocate to some resource to update LiquidJS to support blocks as well ( I always assumed nobody was using the block feature anyway, so thanks for heads up)