-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
99 lines (89 loc) · 2.83 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
const index = require('./index.js');
const config = {};
config.hostname = 'lb.constellationnetwork.io';
config.port = 9000;
config.debug = false;
config.transportNodeHid = require('@ledgerhq/hw-transport-node-hid');
config.http = require('http');
// config.fee = 1;
// config.salt longMaxValue: 9223372036854775807
// config.salt longMinValue: -9223372036854775808
config.salt = 0;
const commands = {};
commands['linfo'] = async () => {
const response = await index.getLedgerDeviceInfo(config);
console.log('info', response);
};
commands['getmbalance'] = async (mnemonic) => {
const response = await index.getBalanceFromMnemonic(config, mnemonic);
if (config.debug) {
console.log('getBalanceFromMnemonic response', response);
}
if (response.success) {
console.log('address', response.address);
console.log('lastTx', response.lastRef);
console.log('balance', response.balanceWhole);
} else {
console.log('balance error', response.message);
}
};
commands['getlbalance'] = async (mnemonic) => {
const response = await index.getBalanceFromLedger(config);
if (config.debug) {
console.log('getBalanceFromLedger response', response);
}
if (response.success) {
console.log('address', response.address);
console.log('lastTx', response.lastRef);
console.log('balance', response.balance);
} else {
console.log('balance error', response.message);
}
};
commands['msend'] = async (amount, toAddress, mnemonic, debug) => {
if (debug !== undefined) {
config.debug = (debug == 'true');
}
const response = await index.sendAmountUsingMnemonic(config, amount, toAddress, mnemonic);
if (config.debug) {
console.log('sendAmountUsingMnemonic response', JSON.stringify(response));
}
if (response.success) {
console.log('send success', response.message);
} else {
console.log('send error', response.message);
}
};
commands['lsend'] = async (amount, toAddress) => {
console.log('sendAmountUsingLedger', amount, toAddress);
const response = await index.sendAmountUsingLedger(config, amount, toAddress);
if (config.debug) {
console.log('sendAmountUsingLedger tx', JSON.stringify(response.tx));
}
if (response.success) {
console.log('send success');
} else {
console.log('send error', response.message);
}
};
const run = async () => {
console.log('constellationjs');
if (process.argv.length < 3) {
console.log('#usage:');
console.log('https://github.com/coranos/constellationjs/blob/master/docs/cli.md');
} else {
const command = process.argv[2];
const arg0 = process.argv[3];
const arg1 = process.argv[4];
const arg2 = process.argv[5];
const arg3 = process.argv[6];
const fn = commands[command];
if (fn == undefined) {
console.log('unknown command', command);
} else {
await fn(arg0, arg1, arg2, arg3);
}
}
};
run();