Closed jdelrue closed 6 years ago
More specifically,
Every time we make a transaction we need to wait for more blocks to be added, We choose how many blocks to wait for, but it should scale with the value of the transaction. Total time to Complete Swap will vary according with how many Blocks we wait for and the current average block time of the blockchain.
So here's a quick list of places where to wait. Assumes a swap between BTC and TFT.
Bob: Publish BTC contract. Alice: Wait for more blocks on BTChain (line 74 acceptor.py - check btc sc height)
Alice: Audit the BTC contract. Alice: Publish TFT contract.
Bob: Wait for more blocks on TFchain (line 75 initiator.py - check tfchain height)
Bob: Audit TFT contract Bob: Publish TFT Claim
Alice: Here I guess from the moment the secret is visible there's no reason not to publish the counterpart claim immediately. (do we have to wait for the secret to become visible? What command to use?)
Alice: Publish BTC Claim
Having gone deeper into how stuff works:
We should be auditing data we get from real Blocks that we can see on a Block Explorer, rather than freshly created possibly pending transactions.
The tfchainc atomicswap auditcontract
command already does this, that's why it needs the explorer module enabled in the daemon (to look up real blocks) and only asks for the OutputID (the only part of the contract the auditor is interested in) as a single argument. (as of the rivine v1.0.5 atomicswap patch)
On the other hand, the btcatomicswap binary from Decred that we are using doesn't get the data from a lookup on a block. It just checks the data we give to it. That's why the btcatomicswap auditcontract
command requires the contract
(which is the Redeem Output/P2SH really...) as an argument. It expects it as a hexstring that we currently get from the other Party/Entity in the atomicswap process, but we should be getting it from the transaction visible on a Block instead.
In the python scripts, we can use the API endpoints of the Bitpay Insight based block explorer to look up the contract using the utxo id (unspent transaction output ID) like so:
import urllib.request
contents = urllib.request.urlopen("https://test-insight.bitpay.com/api/addr/[outputID]/utxo").read()
The utxoID
, or OutputID
, or contract
in this case refers to this hash in the output from the btcatomicswap initiate
command:
And in the JSON object we get from the block explorer it's this one:
(the images are of different transactions that's why the hashes aren't the same)
Current problem: btcatomicswap bin we are using from Decred for auditing the btc contract takes in hexstrings as arguments in a different format than we can find on the Block.
Format comparison:
Scripthash: 2NAuJbBRpXfxNZHi9SycMS74QM4So2WetdH (visible in JSON from block explorer)
Unhashed hex: 6382012088a820dca04d3bb2332d9441964798c846d00d892d8d7dcf8a0cd02ede232dcf12a0298876a9141205a71bca338c827ab7e983fa877d0df4ea068e670423b8065bb17576a914d4cad03b36abd5e2e890dce6d7902abba06d28dc6888ac (btcatomicswap bin expects this format)
In the python exchangenodes timers and checks should be added because blockchain can take a long time