zbxcat/README.md

123 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2017-08-02 12:41:39 -07:00
# ZBXCAT
2017-08-25 12:22:40 -07:00
**NOTE: Experimental software, use at your own risk, PR's welcome :)**
2017-08-02 12:41:39 -07:00
A work-in-progress for Zcash Bitcoin Cross-Chain Atomic Transactions
Bitcoin scripts use python-bitcoinlib, and Zcash scripts use python-zcashlib (a Zcash fork of python-bitcoinlib).
2017-08-25 12:22:40 -07:00
Currently defaults to using testnet.
2017-08-02 12:41:39 -07:00
## Setup
2017-08-02 12:55:24 -07:00
To successfully run this code, you'll need python3, the dependencies installed, and a bitcoin and zcash daemon synced on whichever chain you want to trade on.
2017-08-02 12:41:39 -07:00
It's recommended that you install python3 in a virtualenv. Run this command from the top level of the directory:
```
virtualenv -p python3 venv
source venv/bin/activate
```
2017-08-02 12:55:24 -07:00
To install this code, clone the repo and install as a python package.
```
git clone https://github.com/zcash/zbxcat.git
pip install zbxcat
```
2017-09-04 10:13:11 -07:00
Install the dependencies. Note that this package depends on the experimental [python-zcashlib package](https://github.com/arcalinea/python-zcashlib).
2017-08-02 12:41:39 -07:00
```
2017-09-04 10:13:11 -07:00
pip install -r requirements.txt
2017-08-02 12:41:39 -07:00
```
2017-09-04 10:13:11 -07:00
2017-08-02 12:55:24 -07:00
Run Zcash and Bitcoin daemons locally, on whichever network you want to trade on (recommended: testnet, regtest).
2017-08-02 12:41:39 -07:00
2017-08-02 12:55:24 -07:00
Make sure the rpcuser and rpcpassword values are set in your zcash.conf or bitcoin.conf files.
2017-08-02 12:41:39 -07:00
2017-08-02 12:55:24 -07:00
Example `~/.zcash/zcash.conf` file:
2017-08-02 12:41:39 -07:00
```
2017-08-02 12:55:24 -07:00
rpcuser=user
rpcpassword=password
2017-08-02 12:41:39 -07:00
```
2017-08-02 17:18:35 -07:00
## Example trade
2017-08-02 12:41:39 -07:00
2017-08-02 12:55:24 -07:00
You can try this on regtest on one computer, or on testnet across two computers.
2017-08-01 13:25:50 -07:00
2017-08-25 13:21:28 -07:00
Since this is still under active development, we recommend that you do not trade more than you can afford to lose on mainnet.
2017-08-01 13:32:09 -07:00
2017-08-02 17:18:35 -07:00
We use the term "seller" for whoever initiates the trade, and "buyer" for whoever fulfills the other end.
2017-08-02 21:42:02 -07:00
### Seller Setup:
To start a trade using default addresses, edit the buyer and seller addresses for the chosen network in `xcatconf.py`. You will initiate the trade using these default addresses by passing in the variable through a `-conf` flag.
2017-08-01 13:32:09 -07:00
### Seller:
2017-08-01 13:25:50 -07:00
2017-08-02 21:42:02 -07:00
To initiate a new trade, the seller enters all the necessary trade data and saves it under a tradeid. We will use the tradeid "testtrade" for this example. The amounts being traded will have to be agreed upon in advance, and the seller will need the buyer's destination addresses on both chains. The `-c` field will pass in the name of the network addresses set in `xcatconf.py`. (If addresses are not set, initiator addresses are generated on your computer, and you can enter the buyer's addresses on the command line.)
2017-08-01 13:33:01 -07:00
2017-08-02 21:42:02 -07:00
`xcat -c=regtest newtrade testtrade`
2017-08-01 13:25:50 -07:00
2017-08-25 12:22:40 -07:00
After creating, the seller exports the trade data encoded as a hex string to transfer the terms of the trade to the buyer. They can send this hex string to the buyer through email or any other channel.
2017-08-02 17:18:35 -07:00
A standard export. Returns a long hex string which the seller sends to the buyer.
2017-08-01 13:33:01 -07:00
2017-08-01 13:25:50 -07:00
`xcat exporttrade testtrade`
2017-08-01 13:33:01 -07:00
2017-08-25 12:22:40 -07:00
There is also built-in support to transfer the data directly between two computers through [magic-wormhole](https://github.com/warner/magic-wormhole), which you will have to have installed locally on your computer. Available for download through pip or the apt repository.
2017-08-02 17:18:35 -07:00
An export using magic-wormhole, which uses a short passphrase the seller must communicate to the buyer.
`xcat -w exporttrade testtrade`
2017-08-01 13:25:50 -07:00
2017-08-01 13:32:09 -07:00
### Buyer:
2017-08-02 17:18:35 -07:00
To examine trade, buyer imports it. A standard import requires the full hex string.
`xcat importttrade testtrade <hexstring>`
An import using magic-wormhole, which prompts the user for the short passphrase generated by the seller.
2017-08-01 13:33:24 -07:00
2017-08-02 17:18:35 -07:00
`xcat -w importtrade`
2017-08-01 13:25:50 -07:00
If it looks ok, inform seller to proceed.
2017-08-01 13:32:09 -07:00
### Seller:
2017-08-01 13:25:50 -07:00
Funds sell p2sh. They can use the checktrade command to automatically take the next step in this trade.
2017-08-01 13:33:01 -07:00
2017-08-01 13:25:50 -07:00
`xcat checktrade testtrade`
2017-08-01 13:32:09 -07:00
### Buyer:
2017-08-01 13:35:11 -07:00
Funds buy p2sh, also by using checktrade command to automatically proceed.
2017-08-01 13:33:01 -07:00
2017-08-01 13:25:50 -07:00
`xcat checktrade testtrade`
2017-08-01 13:32:09 -07:00
### Seller:
2017-08-01 13:25:50 -07:00
Redeems buyer p2sh.
2017-08-01 13:33:01 -07:00
2017-08-01 13:25:50 -07:00
`xcat checktrade testtrade`
2017-08-01 13:32:09 -07:00
### Buyer:
2017-08-02 12:41:39 -07:00
Redeems seller p2sh. The secret they need to redeem will be automatically parsed from the seller's redeemtx on the blockchain.
2017-08-01 13:33:01 -07:00
2017-08-01 13:25:50 -07:00
`xcat checktrade testtrade`
2017-08-02 12:41:39 -07:00
Trade is done! Buyer or seller can check the status again, but it will indicate that it is complete.
2017-08-02 12:55:24 -07:00
# Testing and Development
You can install modules locally in editable mode through pip, so that you can make changes to the code and they will be applied immediately.
To use pip to install a package in editable mode, use the `-e` flag to pass in the path on your local filesystem:
`pip install -e <path-to-package-repo>`
To install our code as a python package in editable mode, passing in the directory containing `setup.py` should work.
`pip install -e <directory that setup.py for xcat is in>`