-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtum-eth.js
44 lines (32 loc) · 1.32 KB
/
qtum-eth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const ethContract = require('./helpers/ethContract')
const qtumContract = require('./helpers/qtumContract')
const checkBalance = require('./helpers/checkBalance')
const { Alice } = require('./helpers/participants')
const { wait } = require('./helpers/loader')
const swap = async () => {
try {
// Alice owns ETH, Bob owns QTUM
// Alice wants to swap ETH to QTUM
// Alice funds QTUM Contract using here secret hash
await wait(ethContract.fund({ secretHash: Alice.info.secretHash }))
// Alice sends secret hash to Bob
// Bob funds QTUM Contract using Alice's secret hash
await wait(qtumContract.fund({ secretHash: Alice.info.secretHash }))
await wait(checkBalance(ethContract, false))
await wait(checkBalance(qtumContract, false))
// Alice withdraw money from QTUM Contract
// Alice puts here secret
await wait(qtumContract.withdraw({ secret: Alice.info.secret }))
await wait(checkBalance(ethContract, true))
// Bob gets secret from QTUM Contract
const secret = await wait(qtumContract.getSecret())
// Bob withdraw money from ETH Contract using Alice's secret
await wait(ethContract.withdraw({ secret }))
await wait(checkBalance(ethContract, true))
console.log('\nSWAP FINISHED SUCCESSFULLY!')
}
catch (err) {
console.log(err)
}
}
swap()