ln-service 59.3.2 → 59.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,87 +0,0 @@
1
- const asyncAuto = require('async/auto');
2
- const {returnResult} = require('asyncjs-util');
3
-
4
- const generateBlocks = require('./generate_blocks');
5
- const rpc = require('./rpc');
6
-
7
- const count = 6;
8
-
9
- /** Mine a transaction into a block
10
-
11
- {
12
- cert: <TLS Cert For RPC Connection Buffer Object>
13
- [chain]: <Chain Type String>
14
- host: <Chain Daemon IP String>
15
- pass: <RPC Password String>
16
- port: <RPC Port Number>
17
- transaction: <Transaction Hex String>
18
- user: <RPC Username String>
19
- }
20
-
21
- @returns via cbk or Promise
22
- */
23
- module.exports = ({cert, chain, host, pass, port, transaction, user}, cbk) => {
24
- return new Promise((resolve, reject) => {
25
- return asyncAuto({
26
- // Check arguments
27
- validate: cbk => {
28
- if (!host) {
29
- return cbk([400, 'ExpectedChainRpcHostForMiningTransaction']);
30
- }
31
-
32
- if (!pass) {
33
- return cbk([400, 'ExpectedChainRpcPassForMiningTransaction']);
34
- }
35
-
36
- if (!port) {
37
- return cbk([400, 'ExpectedChainRpcPortForMiningTransaction']);
38
- }
39
-
40
- if (!transaction) {
41
- return cbk([400, 'ExpectedTransactionToMineIntoBlock']);
42
- }
43
-
44
- if (!user) {
45
- return cbk([400, 'ExpectedChainRpcUserForMiningTransaction']);
46
- }
47
-
48
- return cbk();
49
- },
50
-
51
- // Broadcast
52
- broadcast: ['validate', ({}, cbk) => {
53
- return rpc({
54
- cert,
55
- host,
56
- pass,
57
- port,
58
- user,
59
- cmd: 'sendrawtransaction',
60
- params: [transaction],
61
- },
62
- err => {
63
- if (!!err) {
64
- return cbk([503, 'UnexpectedErrorBroadcastingTransaction', {err}]);
65
- }
66
-
67
- return cbk();
68
- });
69
- }],
70
-
71
- // Generate
72
- generate: ['broadcast', ({}, cbk) => {
73
- return generateBlocks({
74
- cert,
75
- chain,
76
- count,
77
- host,
78
- pass,
79
- port,
80
- user,
81
- },
82
- cbk);
83
- }],
84
- },
85
- returnResult({reject, resolve}, cbk));
86
- });
87
- };
@@ -1,82 +0,0 @@
1
- const fetch = require('@alexbosworth/node-fetch');
2
- const http = require('http');
3
- const https = require('https');
4
-
5
- const asyncAuto = require('async/auto');
6
- const {returnResult} = require('asyncjs-util');
7
-
8
- const defaultTimeout = 1000 * 30;
9
- const agents = {};
10
- let requests = 0;
11
-
12
- /** Call JSON RPC
13
-
14
- {
15
- [cert]: <Cert Buffer Object>
16
- cmd: <Command String>
17
- host: <Host Name String>
18
- params: [<Parameter Object>]
19
- pass: <Password String>
20
- port: <Port Number>
21
- [timeout]: <Milliseconds Timeout Number>
22
- user: <Username String>
23
- }
24
-
25
- @returns via cbk or Promise
26
- <Result Object>
27
- */
28
- module.exports = (args, cbk) => {
29
- return new Promise((resolve, reject) => {
30
- return asyncAuto({
31
- // Check arguments
32
- validate: cbk => {
33
- return cbk();
34
- },
35
-
36
- // Derive an HTTP agent as necessary for using a self-signed cert
37
- agent: ['validate', async ({}) => {
38
- // Exit early when there is no cert and this is a regular HTTP request
39
- if (!args.cert) {
40
- return new http.Agent({});
41
- }
42
-
43
- return new https.Agent({
44
- ca: [args.cert],
45
- cert: args.cert,
46
- ecdhCurve: 'auto',
47
- });
48
- }],
49
-
50
- // Send request to the server
51
- request: ['agent', async ({agent}) => {
52
- const credentials = Buffer.from(`${args.user}:${args.pass}`);
53
- const scheme = !!args.cert ? 'https' : 'http';
54
-
55
- try {
56
- const response = await fetch(
57
- `${scheme}://${args.host}:${args.port}/`,
58
- {
59
- agent,
60
- body: JSON.stringify({
61
- jsonrpc: '1.0',
62
- id: `${++requests}`,
63
- method: args.cmd,
64
- params: args.params,
65
- }),
66
- headers: {
67
- 'Authorization': `Basic ${credentials.toString('base64')}`,
68
- 'Content-Type': 'application/json',
69
- },
70
- method: 'POST',
71
- },
72
- );
73
-
74
- return (await response.json()).result;
75
- } catch (err) {
76
- throw [503, 'UnexpectedErrorFromRpcService', {err}];
77
- }
78
- }],
79
- },
80
- returnResult({reject, resolve, of: 'request'}, cbk));
81
- });
82
- };
@@ -1,88 +0,0 @@
1
- const {join} = require('path');
2
- const {tmpdir} = require('os');
3
-
4
- const removeDir = require('rimraf');
5
- const {v4} = require('uuid');
6
-
7
- const btcsuiteTypeDaemon = require('./btcsuite_type_daemon');
8
-
9
- /** Spawn a chain daemon for testing on regtest
10
-
11
- This method will also listen for uncaught exceptions and stop the daemon
12
- before the process dies.
13
-
14
- {
15
- daemon: <Daemon Type String>
16
- [is_tls]: <Uses TLS Bool> // only supported for btcsuite type
17
- mining_public_key: <Mining Public Key Hex String>
18
- }
19
-
20
- @returns via cbk
21
- {
22
- daemon: <Daemon Child Process Object>
23
- dir: <Data Dir Path String>
24
- listen_port: <Listen Port Number>
25
- [rpc_cert]: <RPC Cert Path String>
26
- rpc_port: <RPC Port Number>
27
- }
28
- */
29
- module.exports = (args, cbk) => {
30
- if (!args.daemon) {
31
- return cbk([400, 'ExpectedDaemonTypeToSpawn']);
32
- }
33
-
34
- let daemon;
35
-
36
- const dir = join(tmpdir(), v4());
37
-
38
- switch (args.daemon) {
39
- case 'btcd':
40
- daemon = btcsuiteTypeDaemon({
41
- dir,
42
- daemon: args.daemon,
43
- is_tls: args.is_tls,
44
- mining_public_key: args.mining_public_key,
45
- },
46
- (err, res) => {
47
- if (!!err) {
48
- return cbk(err);
49
- }
50
-
51
- res.daemon.stderr.on('data', data => {
52
- if (/mandatory.script.verify.flag/gim.test(data+'')) {
53
- return;
54
- }
55
-
56
- if (/txn.already.in.mempool/gim.test(data+'')) {
57
- return;
58
- }
59
-
60
- return;
61
- });
62
-
63
- res.daemon.on('close', async code => await removeDir(dir));
64
-
65
- process.setMaxListeners(20);
66
-
67
- process.on('uncaughtException', err => {
68
- res.daemon.kill();
69
- process.exit(1)
70
- });
71
-
72
- return cbk(null, {
73
- dir,
74
- daemon: res.daemon,
75
- listen_port: res.listen_port,
76
- rpc_cert: join(dir, 'rpc.cert'),
77
- rpc_port: res.rpc_port,
78
- });
79
- });
80
- break;
81
-
82
- default:
83
- return cbk([400, 'UnknownDaemonType', args.daemon]);
84
- }
85
-
86
- return;
87
- };
88
-