bitcoinjs / playground

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

Stackify / unstackify #2

Closed dcousens closed 6 years ago

dcousens commented 6 years ago

Thoughts on an an opts argument for relevant scripts that might have been used in a P2WSH, and therefore had their stacks become .witness data?

Users would provide { stackify: true } if .input is provided and .witness needed.

And they would provide { unstackify: true } if a .witness is provided and .input needed.

Otherwise, if the signature data was required, fail.

Examples

let lastResult = p2wsh({ redeem: p2pkh({ pubkeys, signatures }) }, { stackify: true }) 
// { redeem: { witness, output }, ... }`

p2pkh(lastResult.redeem, { unstackify: true }) 
// { input, output, pubkeys, signatures, ... }

edit: alternative naming witnessify/unwitnessify (or some other, suggestions open)

dcousens commented 6 years ago

It isn't possible to carry around a chunks Array, as, P2WSH has no idea what chunks it should decode to. A canonical form is no simpler than the alternative of stackify/unstackify.

dcousens commented 6 years ago

stackify/unstackify could be functions on their own - and they can be added when necessary.

The use case here is way too niche, specifically for hardcore TX development and introspection...

I don't think we need to generalize the API to suite that case.

p2wsh automatically transforms redeem.input to a redeem.witness, if it can safely, otherwise it throws.

I don't think we need more than that.