-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathethatomicswap.js
53 lines (45 loc) · 1.75 KB
/
ethatomicswap.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
45
46
47
48
49
50
51
52
53
/**
* Ethereum atomic swaps
*
* @author Djenad Razic
* @company Altcoin Exchange, Inc.
*/
var AbiConfig = require("../abi/atomicswap");
var AppConfig = require("../config");
var AtomicSwap = require("../modules/atomicswap");
// Get arguments
var argv = require('minimist')(process.argv.slice(2), opts={string:"_"});
var help = "Usage: ethatomicswap [cmd] [params] \n\n" +
"initiate <refundTime> <hashedSecret> <participantAddress> <amount> \n" +
"participate <refundTime> <hashedSecret> <initiatorAddress> <amount> \n" +
"redeem <secret> <hashedSecret> \n" +
"refund <hashedSecret> \n";
// Available commands
var _commands = ["initiate", "participate", "redeem", "refund"];
argv._[0] = argv._[0].toLowerCase();
// Check for available commands
if (_commands.indexOf(argv._[0]) == -1) {
console.log(help);
return;
}
try {
var swap = new AtomicSwap(AbiConfig, AppConfig.hosts[0]);
if (argv._[0] == "initiate")
swap.Initiate(argv._[1], argv._[2], argv._[3], argv._[4], argv._[5]).then(function(result) {
console.log("Initiated with transaction number: " + result);
});
else if (argv._[0] == "participate")
swap.Participate(argv._[1], argv._[2], argv._[3], argv._[4], argv._[5]).then(function(result) {
console.log("Participated with transaction number: " + result);
});
else if (argv._[0] == "redeem")
swap.Redeem(argv._[1], argv._[2], argv._[3]).then(function(result) {
console.log("Redeemed with transaction number: " + result);
});
else if (argv._[0] == "refund")
swap.Refund(argv._[1], argv._[2]).then(function(result) {
console.log("Refunded with transaction number: " + result);
});
} catch (e) {
console.log(e);
}