How to add comments or meta-data to an atomic exchange? [closed]

+1 vote
Hi, I see that we can add comments to single transactions, but noticed that there was no such thing in atomic exchanges. Is it possible to do so? Do we have to deserialize the hex string after createrawexchange, add our metadata, then reserialize it?
closed with the note: Great, thanks!
asked Jun 10, 2016 by anonymous
closed Jun 12, 2016

1 Answer

0 votes

The problem with adding metadata using the createrawexchange + appendrawexchange APIs is that these building up the transaction piecemeal, with each matching input/output pair created and signed by a separate user, without committing to a particular user who will participate in the rest of the transaction (unlike regular transactions, the signature type is SIGHASH_SINGLE). Metadata sits in its own (OP_RETURN) output which would not be signed by anyone (let alone everyone) using this method, and therefore have no proof of validity.

If you want to create an atomic exchange with metadata, you should instead use this flow:

* Each user calls preparelockunspent(from) to prepare a transaction output with the assets they're offering, and one user sends their txidvout pair to the other.

* This second user builds the transaction using createrawtransaction + appendrawmetadata, spending the transaction outputs from the previous stage and sending the appropriate amount to each user, to balance the input and output asset quantities. This user then calls signrawtransaction to sign the full transaction, and passes it back to the first.

* The first user examines the partially signed transaction using decoderawtransaction to make sure they're comfortable with asset exchange and included metadata. If so, they sign it with signrawtransaction and then use sendrawtransaction to broadcast it for confirmation.

answered Jun 10, 2016 by MultiChain
...