4 [![MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](./LICENSE)
6 - [1 Background](#1-background)
7 - [2 Install](#2-install)
8 - [2.1 Requirements](#21-requirements)
9 - [2.2 Install bytom node](#22-install-bytom-node)
10 - [2.3 Build from source code](#23-build-from-source-code)
12 - [3.1 Swap assets in bytom or vapor](#31-swap-assets-in-bytom-or-vapor)
13 - [3.1.1 Launch bytom node](#311-launch-bytom-node)
14 - [3.1.2 Create account and issue your asset](#312-create-account-and-issue-your-asset)
15 - [3.1.3 Deploy tradeoff contract](#313-deploy-tradeoff-contract)
16 - [3.1.4 Call tradeoff contract](#314-call-tradeoff-contract)
17 - [3.1.5 Cancel tradeoff contract](#315-cancel-tradeoff-contract)
18 - [3.2 Swap assets between bytom and vapor](#32-swap-assets-between-bytom-and-vapor)
19 - [3.2.1 Launch bytom and vapor node](#321-launch-bytom-and-vapor-node)
20 - [3.2.2 Deploy HTLC contract](#322-deploy-htlc-contract)
21 - [3.2.3 Call HTLC contract](#323-call-htlc-contract)
22 - [3.2.4 Cancel HTLC contract](#324-cancel-htlc-contract)
23 - [4 Contributing](#4-contributing)
24 - [5 License](#5-license)
28 Shuttle is designed to help swap different assets in bytom.
34 - [Go](https://golang.org/doc/install) version 1.12 or higher, with `$GOPATH` set to your preferred directory
36 ### 2.2 Install bytom node
38 Firstly, you should install and configure bytom node, see also: [Bytom repository](https://github.com/Bytom/bytom).
40 ### 2.3 Build from source code
42 Shuttle is still in beta, so repository code will be changed frequently. You can build tool from source code directly.
45 $ git clone https://github.com/Bytom/shuttle.git $GOPATH/src/github.com/shuttle
46 $ cd $GOPATH/src/github.com/shuttle
50 Shuttle help information:
54 swap is a commond line client for bytom contract
61 callHTLC call HTLC contract for asset swapping
62 callTradeoff call tradeoff contract for asset swapping
63 cancelHTLC cancel HTLC contract for asset swapping
64 cancelTradeoff cancel tradeoff contract for asset swapping
65 deployHTLC deploy HTLC contract
66 deployTradeoff deploy tradeoff contract
67 help Help about any command
70 -h, --help help for swap
72 Use "swap [command] --help" for more information about a command.
78 $ cd $GOPATH/src/github.com/shuttle
84 ### 3.1 Swap assets in bytom or vapor
86 #### 3.1.1 Launch bytom node
88 For testing, you can launch bytom solonet node.
91 $ bytomd init --chain_id=solonet --home $HOME/bytom/solonet # init bytom solonet node
92 $ bytomd node --home $HOME/bytom/solonet --mining # launch bytom solonet node and start mining
95 #### 3.1.2 Create account and issue your asset
97 You should create several accounts and issue your asset for testing, more details:
99 - [Managing Accounts](https://github.com/Bytom/bytom/wiki/Managing-Accounts)
100 - [Assets registration](https://github.com/Bytom/bytom/wiki/Advanced-Transaction#assets-registration)
102 For example, in bytom blockchain, account a1 has 200 BTC, account a2 has 10 BTM, they can swap their assets using shuttle.
104 #### 3.1.3 Deploy tradeoff contract
107 $ swap deployTradeoff -h
108 deploy tradeoff contract
111 swap deployTradeoff <accountID> <password> [contract flags(paramenters and locked value)] [txFee flag] [URL flags(ip and port)] [flags]
114 --amountLocked uint tradeoff contract locked value with amount
115 --amountRequested uint tradeoff contract paramenter with requested amount
116 --assetLocked string tradeoff contract locked value with assetID
117 --assetRequested string tradeoff contract paramenter with requested assetID
118 --cancelKey string tradeoff contract paramenter with seller pubkey for cancelling the contract
119 -h, --help help for deployTradeoff
120 --ip string network address (default "127.0.0.1")
121 --port string network port (default "9888")
122 --seller string tradeoff contract paramenter with seller control-program
123 --txFee uint contract transaction fee (default 40000000)
127 $ swap deployTradeoff 10CJPO1HG0A02 12345 --amountLocked 20000000000 --amountRequested 1000000000 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff --cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e --seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f --txFee 40000000
128 --> contractUTXOID: 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f
131 Then, wait about 2.5 minutes, and a new block will be mined, the contract will be confirmed.
133 #### 3.1.4 Call tradeoff contract
136 $ swap callTradeoff -h
137 call tradeoff contract for asset swapping
140 swap callTradeoff <accountID> <password> <buyer-program> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
143 -h, --help help for callTradeoff
144 --ip string network address (default "127.0.0.1")
145 --port string network port (default "9888")
146 --txFee uint contract transaction fee (default 40000000)
150 $ swap callTradeoff 10CKAD3000A02 12345 00140fdee108543d305308097019ceb5aec3da60ec66 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f
151 --> txID: 55e43274d2d92504a903a13e3f6517d63434fc19a2fa0e1fc0a9a5c8c75e8f6c
154 When the transaction will be confirmed in a new block, the whole swap is successful.
156 ![tradeoff](./images/tradeoff.png)
158 Now, account a1 get 10 BTM, and account a2 get 200 BTC.
160 #### 3.1.5 Cancel tradeoff contract
162 If someone want to cancel this tradeoff transaction, he can call cancelTradeoff.
165 $ swap cancelTradeoff -h
166 cancel tradeoff contract for asset swapping
169 swap cancelTradeoff <accountID> <password> <redeem-program> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
172 -h, --help help for cancelTradeoff
173 --ip string network address (default "127.0.0.1")
174 --port string network port (default "9888")
175 --txFee uint contract transaction fee (default 40000000)
179 $ swap deployTradeoff 10CJPO1HG0A02 12345 --amountLocked 20000000000 --amountRequested 1000000000 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff --cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e --seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f --txFee 40000000
180 --> contractUTXOID: e898ea907f8586b3211a46b69d0cddd363f8a850f559656570eb6afc6ac382c5
181 $ swap cancelTradeoff 10CJPO1HG0A02 12345 00145b0a81adc5c2d68a9967082a09c96e82d62aa058 e898ea907f8586b3211a46b69d0cddd363f8a850f559656570eb6afc6ac382c5
182 --> txID: 0f75db743196b8b2e514c49d6483dfba9bd5ab8e913a7559ecaea0324977313f
185 ![tradeoff-cancel](./images/tradeoff-cancel.png)
187 Now, account a1 cancel tradeoff transaction, and 200 BTC come back.
189 ### 3.2 Swap assets between bytom and vapor
191 #### 3.2.1 Launch bytom and vapor node
193 For testing, you can launch bytom and vapor solonet node.
195 Launch bytom solonet node:
198 $ bytomd init --chain_id=solonet --home $HOME/bytom/solonet # init bytom solonet node
199 $ bytomd node --home $HOME/bytom/solonet --mining # launch bytom solonet node and start mining
202 Launch vapor solonet node:
205 $ vapord init --chain_id=solonet --home $HOME/bytom/vapor-solonet # init vapor solonet node
206 $ vapord node --home $HOME/bytom/vapor-solonet --mining # launch vapor solonet node and start mining
209 #### 3.2.2 Deploy HTLC contract
216 swap deployHTLC <accountID> <password> [contract flags(paramenters and locked value)] [txFee flag] [URL flags(ip and port)] [flags]
219 --amountLocked uint HTLC contract locked value with amount
220 --assetLocked string HTLC contract locked value with assetID
221 --blockHeight uint HTLC contract locked value with blockHeight
222 --hash string HTLC contract locked value with hash
223 -h, --help help for deployHTLC
224 --ip string network address (default "127.0.0.1")
225 --port string network port (default "9888")
226 --recipient string HTLC contract paramenter with recipientPublicKey
227 --sender string HTLC contract paramenter with sender PublicKey
228 --txFee uint contract transaction fee (default 40000000)
232 $ swap deployHTLC 11BB7TC8G0A02 12345 --sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44 --recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7 --blockHeight 1200 --hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --amountLocked 20000000000
233 --> contractUTXOID: e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e
236 #### 3.2.3 Call HTLC contract
240 call HTLC contract for asset swapping
243 swap callHTLC <accountID> <password> <buyer-program> <preimage> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
246 -h, --help help for callHTLC
247 --ip string network address (default "127.0.0.1")
248 --port string network port (default "9888")
249 --txFee uint contract transaction fee (default 40000000)
253 $ swap callHTLC 11BB86V300A04 12345 0014230cb75fcfcc70c580ce7f1d21c1e374d27334a8 68656c6c6f e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e
254 --> txID: df57b7906684e3d85adf59073ccbc0a3c5114b165626e9791f3269e9e57c319e
257 ![HTLC](./images/HTLC.png)
259 The account a5 in vapor has same steps.
261 #### 3.2.4 Cancel HTLC contract
265 cancel HTLC contract for asset swapping
268 swap cancelHTLC <accountID> <password> <redeem-program> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
271 -h, --help help for cancelHTLC
272 --ip string network address (default "127.0.0.1")
273 --port string network port (default "9888")
274 --txFee uint contract transaction fee (default 40000000)
278 $ swap deployHTLC 11BB7TC8G0A02 12345 --sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44 --recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7 --blockHeight 1200 --hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --amountLocked 20000000000
279 --> contractUTXOID: 68ed6b948b93544ea135482f1acd93d6b10cdc88f52d44133d264a5ee86b1ebd
280 $ swap cancelHTLC 11BB7TC8G0A02 12345 001434fec270871c1f3420db85831f59511b2dd2a026 68ed6b948b93544ea135482f1acd93d6b10cdc88f52d44133d264a5ee86b1ebd
281 --> txID: c70a467e94b287d29c6d91a2cb6f8ef3c7ef4dba315d99acf2dc9ff698996270
284 ![HTLC](./images/HTLC-cancel.png)
286 Now, account a4 cancel HTLC transaction, and 200 BTC come back.
288 The account a5 in vapor has same steps.
292 Welcome to [open an issue](https://github.com/Bytom/btm-swap-tool/issues/new) or submit PRs. This project exists thanks to all the people who contribute.
296 [MIT](./LICENSE) © 2019 Bytom