me-foundation / msigner

msigner is an open source Bitcoin Ordinals Partially Signed Bitcoin Transactions (PSBT) signer library. It supports atomic swap of the inscription and provides a simple and secure way to structure Bitcoin transactions for marketplaces.
Apache License 2.0
233 stars 77 forks source link

What are the 2 new dummy outputs created for? #3

Open jadwahab opened 1 year ago

jadwahab commented 1 year ago

Firstly, thanks for putting this together!

I'm just a little confused about what the 2 new dummy outputs created are for. I see the code says: https://github.com/magiceden-oss/msigner/blob/3de81d4aaac4d030b2fb2967d704a59070981777/src/signer.ts#L465

Is it to avoid having to create a new tx with 2 dummy inputs in a future purchase? Also, do they have any specific values?

nothing0012 commented 1 year ago

Yes, they're used for future purchase, so that people don't need to prepare the dummy utxos again

dannydeezy commented 1 year ago

i don't understand the need for the 2 dummy utxos, can you point me to any materials where i can learn?

casey commented 1 year ago

I was curious about why this library uses two dummy inputs as well. I think it's because if you only use one dummy input, the ordinal winds up being unaligned. Let's say we use one dummy and have a final transaction with inputs valued A, A, and B, and outputs valued 2 A and B, with the ordinal being sold on the first sat of the second A input:

A    2A
A -> B
B

The transaction value balances, however the ordinal will wind up in the middle of the first output.

If, on the other hand, we add an additional dummy:

A    2A
A    A
A -> B
B

Then the ordinals winds up on the first sat of the second output.

And two dummy outputs are used because that's the number of dummy inputs required.