mainnet-js 2.7.19 → 2.7.21
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.
- package/dist/index.html +1 -1
- package/dist/{mainnet-2.7.19.js → mainnet-2.7.21.js} +735 -755
- package/dist/module/mine/mine.d.ts +2 -2
- package/dist/module/mine/mine.d.ts.map +1 -1
- package/dist/module/mine/mine.js +22 -23
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -8
- package/src/mine/mine.ts +26 -25
package/src/mine/mine.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import child_process from "child_process";
|
|
1
|
+
import { binToBase64, utf8ToBin } from "@bitauth/libauth";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Mine blocks to a regtest address
|
|
@@ -10,32 +9,34 @@ import child_process from "child_process";
|
|
|
10
9
|
* @remarks
|
|
11
10
|
* This function assumes a local regtest bitcoin node with RPC_* matching the docker configuration
|
|
12
11
|
*/
|
|
13
|
-
|
|
14
|
-
export async function mine({
|
|
12
|
+
export const mine = async ({
|
|
15
13
|
cashaddr,
|
|
16
14
|
blocks,
|
|
17
15
|
}: {
|
|
18
16
|
cashaddr: string;
|
|
19
17
|
blocks: number;
|
|
20
|
-
}) {
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
}): Promise<any> => {
|
|
19
|
+
const response = await fetch(`http://127.0.0.1:${process.env.RPC_PORT}/`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
Authorization:
|
|
24
|
+
"Basic " +
|
|
25
|
+
binToBase64(
|
|
26
|
+
utf8ToBin(`${process.env.RPC_USER}:${process.env.RPC_PASS}`)
|
|
27
|
+
),
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
jsonrpc: "2.0",
|
|
31
|
+
id: "0",
|
|
32
|
+
method: "generatetoaddress",
|
|
33
|
+
params: {
|
|
34
|
+
nblocks: blocks,
|
|
35
|
+
address: cashaddr,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const json = await response.json();
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`bitcoind`,
|
|
27
|
-
`bitcoin-cli`,
|
|
28
|
-
`--rpcconnect=${process.env.RPC_HOST}`,
|
|
29
|
-
`--rpcuser=${process.env.RPC_USER}`,
|
|
30
|
-
`--rpcpassword=${process.env.RPC_PASS}`,
|
|
31
|
-
`--rpcport=${process.env.RPC_PORT}`,
|
|
32
|
-
`generatetoaddress`,
|
|
33
|
-
blocks,
|
|
34
|
-
cashaddr,
|
|
35
|
-
];
|
|
36
|
-
const cli = child_process.spawnSync(`docker`, generateArgs as any);
|
|
37
|
-
if (cli.stderr.length > 0) {
|
|
38
|
-
return console.log("Mine Error: " + cli.stderr.toString());
|
|
39
|
-
}
|
|
40
|
-
return JSON.parse(cli.stdout.toString());
|
|
41
|
-
}
|
|
41
|
+
return json.result;
|
|
42
|
+
};
|