Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: demonstrate interactive name swaps #500

Merged
merged 1 commit into from
Nov 22, 2020
Merged

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Aug 18, 2020

This test isn't designed intentionally to increase test coverage but more to document one method of atomically swapping HNS coins for a name by using an interactive protocol and partially-signed transactions. We don't need to merge it but it may prevent some edge case regression in the future.

The flow goes like this:

  • Alice owns a name and agrees to sell it to Bob for a certain price (they communicate any way possible, not on-chain)
  • Bob sends Alice an address to receive the name
  • Alice signs and broadcasts a TRANSFER covenant committing to Bob's address
    • at this point, Alice still unilaterally owns the name.
    • Bob can see the TX on the blockchain (so can everyone) and confirm his address is in the covenant
    • at any time before the FINALIZE is broadcast, Alice can CANCEL the transfer.
      • Bob can see this CANCEL on chain (back to step 1)
      • no money or name is lost by either party if Alice decides to CANCEL, just the two mining fees so far spent by Alice.
  • After 288 blocks a FINALIZE is valid, and is constructed cooperatively by both parties
    • Alice can complete her end of the protocol at any time, but Bob can not broadcast the FINALIZE until after 288 blocks
    • Alice may decide to CANCEL if Bob doesn't complete the FINALIZE within a certain time
      • this is not enforced by the blockchain, it's just something Alice can do, and should warn Bob about it in step 1
    • Alice constructs and partially signs a FINALIZE that sends value to her own receive address, and consumes the TRANSFER covenant as an input. This requires SIGHASH_ANYONECANPAY | SIGHASH_SINGLEREVERSE so that Bob can still add funds.
    • Alice sends the serialized, partially-signed FINALIZE to Bob as a hex string
    • Bob decodes the blob, verifies what he can
      • his address is in the TRANSFER covenant and the FINALIZE output is valid
      • Alice's signature is valid, and the value output to her address is the agreed price
    • Bob adds funds to the TX inputs and adds a change output if necessary
    • Bob signs his inputs with SIGHASH_ALL
    • Bob broadcasts the final transaction

@pinheadmz pinheadmz requested a review from tynes August 18, 2020 18:41
@handshake-org handshake-org deleted a comment from coveralls Aug 18, 2020
@handshake-org handshake-org deleted a comment from coveralls Aug 18, 2020
@pinheadmz
Copy link
Member Author

Also worth noting that this protocol can be executed entirely with RPC commands, but it gets messy (you need to do coin selection on the client side from listunspent, get the private key with dumpprivkey, and pass it to the node rpc signrawtransaction)

@tynes
Copy link
Contributor

tynes commented Aug 19, 2020

Not sure if this belongs in this repo, although it is really cool.

@chjj
Copy link
Contributor

chjj commented Nov 22, 2020

I'd like to merge it. More tests are always a good thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants