bitcoinjs / playground

Go nuts! PRs can be useful for discussion, and won't be rejected
MIT License
3 stars 3 forks source link

Integration into bitcoinjs #3

Closed dcousens closed 5 years ago

dcousens commented 6 years ago

I've been having thoughts around how the new script interfaces will integrate into the main library, and overall how they will tie together with 4.0.0.

The existing templates approach in bitcoinjs-lib works, and is powerful, but ends up being very clunky in reality.

This API is very easy to chain together, and feels great to use, but, say if you only want an output script, it might feel a bit over-zealous for this API to always calculate the address and the rest of the details it introspects by default.

We could:

If we did keep both, how would this code integrate into the main library? bitcoin.payments.p2pkh?

junderw commented 6 years ago

let { p2ms, p2sh } = bitcoin.scriptBuilders

Sounds like a cool idiom to place at the top of a function.

dcousens commented 6 years ago

@junderw the issue I had with scriptBuilders, is, like TransactionBuilder, it is a noun, and nouns become associated with OOP.

I wish TransactionBuilder wasn't stateful. PBST is the closest I think we should get to the state idea. The less stateful it is, the easier it is to test, and honestly, with these new APIs, I think we can get 99% of the way.

dcousens commented 6 years ago

Make the API here lazily evaluated where possible, keeping the simplicity benefits

This approach looks great so far, will hopefully push up a branch soon. I generally avoid defineProperty (I prefer simpler objects), but, this reads very simple and clear.

dcousens commented 6 years ago

@junderw as I use this more, and in its lazy-evaluated form, I think this may replace bitcoin.script.[templates] and bitcoin.address in its entirety.

Can we have a chat this week to walk through the APIs before I [hopefully] get the PR up here?