OSDN Git Service

update readme
[bytom/shuttle.git] / README.md
1 Shuttle
2 ========
3
4 [![MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](./LICENSE)
5
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)
11 - [3 Usage](#3-usage)
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)
25
26 ## 1 Background
27
28 Shuttle is designed to help swap different assets in bytom.
29
30 ## 2 Install
31
32 ### 2.1 Requirements
33
34 - [Go](https://golang.org/doc/install) version 1.12 or higher, with `$GOPATH` set to your preferred directory
35
36 ### 2.2 Install bytom node
37
38 Firstly, you should install and configure bytom node, see also: [Bytom repository](https://github.com/Bytom/bytom).
39
40 ### 2.3 Build from source code
41
42 Shuttle is still in beta, so repository code will be changed frequently. You can build tool from source code directly.
43
44 ```shell
45 $ git clone https://github.com/Bytom/shuttle.git $GOPATH/src/github.com/shuttle
46 $ cd $GOPATH/src/github.com/shuttle
47 $ make install
48 ```
49
50 Shuttle help information:
51
52 ```shell
53 $ swap -h
54 swap is a commond line client for bytom contract
55
56 Usage:
57   swap [flags]
58   swap [command]
59
60 Available Commands:
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
68
69 Flags:
70   -h, --help   help for swap
71
72 Use "swap [command] --help" for more information about a command.
73 ```
74
75 or remove shuttle:
76
77 ```shell
78 $ cd $GOPATH/src/github.com/shuttle
79 $ make clean
80 ```
81
82 ## 3 Usage
83
84 ### 3.1 Swap assets in bytom or vapor
85
86 #### 3.1.1 Launch bytom node
87
88 For testing, you can launch bytom solonet node.
89
90 ```shell
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
93 ```
94
95 #### 3.1.2 Create account and issue your asset
96
97 You should create several accounts and issue your asset for testing, more details:
98
99 - [Managing Accounts](https://github.com/Bytom/bytom/wiki/Managing-Accounts)
100 - [Assets registration](https://github.com/Bytom/bytom/wiki/Advanced-Transaction#assets-registration)
101
102 For example, in bytom blockchain, account a1 has 200 BTC, account a2 has 10 BTM, they can swap their assets using shuttle.
103
104 #### 3.1.3 Deploy tradeoff contract
105
106 ```shell
107 $ swap deployTradeoff -h
108 deploy tradeoff contract
109
110 Usage:
111   swap deployTradeoff <accountID> <password> [contract flags(paramenters and locked value)] [txFee flag] [URL flags(ip and port)] [flags]
112
113 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)
124 ```
125
126 ```shell
127 $ swap deployTradeoff 10CJPO1HG0A02 12345 --amountLocked 20000000000 --amountRequested 1000000000 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff --cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e --seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f --txFee 40000000
128 --> contractUTXOID: 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f
129 ```
130
131 Then, wait about 2.5 minutes, and a new block will be mined, the contract will be confirmed.
132
133 #### 3.1.4 Call tradeoff contract
134
135 ```shell
136 $ swap callTradeoff -h
137 call tradeoff contract for asset swapping
138
139 Usage:
140   swap callTradeoff <accountID> <password> <buyer-program> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
141
142 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)
147 ```
148
149 ```shell
150 $ swap callTradeoff 10CKAD3000A02 12345 00140fdee108543d305308097019ceb5aec3da60ec66 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f
151 --> txID: 55e43274d2d92504a903a13e3f6517d63434fc19a2fa0e1fc0a9a5c8c75e8f6c
152 ```
153
154 When the transaction will be confirmed in a new block, the whole swap is successful.
155
156 ![tradeoff](./images/tradeoff.png)
157
158 Now, account a1 get 10 BTM, and account a2 get 200 BTC.
159
160 #### 3.1.5 Cancel tradeoff contract
161
162 If someone want to cancel this tradeoff transaction, he can call cancelTradeoff.
163
164 ```shell
165 $ swap cancelTradeoff -h
166 cancel tradeoff contract for asset swapping
167
168 Usage:
169   swap cancelTradeoff <accountID> <password> <redeem-program> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
170
171 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)
176 ```
177
178 ```shell
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
183 ```
184
185 ![tradeoff-cancel](./images/tradeoff-cancel.png)
186
187 Now, account a1 cancel tradeoff transaction, and 200 BTC come back.
188
189 ### 3.2 Swap assets between bytom and vapor
190
191 #### 3.2.1 Launch bytom and vapor node
192
193 For testing, you can launch bytom and vapor solonet node.
194
195 Launch bytom solonet node:
196
197 ```shell
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
200 ```
201
202 Launch vapor solonet node:
203
204 ```shell
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
207 ```
208
209 #### 3.2.2 Deploy HTLC contract
210
211 ```shell
212 $ swap deployHTLC -h
213 deploy HTLC contract
214
215 Usage:
216   swap deployHTLC <accountID> <password> [contract flags(paramenters and locked value)] [txFee flag] [URL flags(ip and port)] [flags]
217
218 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)
229 ```
230
231 ```shell
232 $ swap deployHTLC 11BB7TC8G0A02 12345 --sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44 --recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7 --blockHeight 1200 --hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --amountLocked 20000000000
233 --> contractUTXOID: e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e
234 ```
235
236 #### 3.2.3 Call HTLC contract
237
238 ```shell
239 $ swap callHTLC -h
240 call HTLC contract for asset swapping
241
242 Usage:
243   swap callHTLC <accountID> <password> <buyer-program> <preimage> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
244
245 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)
250 ```
251
252 ```shell
253 $ swap callHTLC 11BB86V300A04 12345 0014230cb75fcfcc70c580ce7f1d21c1e374d27334a8 68656c6c6f e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e
254 --> txID: df57b7906684e3d85adf59073ccbc0a3c5114b165626e9791f3269e9e57c319e
255 ```
256
257 ![HTLC](./images/HTLC.png)
258
259 The account a5 in vapor has same steps.
260
261 #### 3.2.4 Cancel HTLC contract
262
263 ```shell
264 $ swap cancelHTLC -h
265 cancel HTLC contract for asset swapping
266
267 Usage:
268   swap cancelHTLC <accountID> <password> <redeem-program> <contractUTXOID> [txFee flag] [URL flags(ip and port)] [flags]
269
270 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)
275 ```
276
277 ```shell
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
282 ```
283
284 ![HTLC](./images/HTLC-cancel.png)
285
286 Now, account a4 cancel HTLC transaction, and 200 BTC come back.
287
288 The account a5 in vapor has same steps.
289
290 ## 4 Contributing
291
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.
293
294 ## 5 License
295
296 [MIT](./LICENSE) © 2019 Bytom