@leofcoin/workers 1.1.0 → 1.2.0
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/bundle/commonjs/block-worker-21ad8152.js +45 -0
- package/dist/bundle/commonjs/block-worker.js +3 -4
- package/dist/{commonjs/machine-worker-481c0a4b.js → bundle/commonjs/machine-worker-13071997.js} +47 -37
- package/dist/bundle/commonjs/machine-worker.js +4 -5
- package/dist/bundle/commonjs/{pool-worker-61189fde.js → pool-worker-f450eeff.js} +6 -17
- package/dist/bundle/commonjs/pool-worker.js +3 -3
- package/dist/bundle/commonjs/{transaction-6a24c91e.js → transaction-d7c6a8ee.js} +2 -2
- package/dist/bundle/commonjs/transaction-worker-176a5aaa.js +27 -0
- package/dist/bundle/commonjs/transaction-worker.js +3 -3
- package/dist/bundle/commonjs/{utils-6a02b156.js → utils-6e881be4.js} +45 -2
- package/dist/bundle/commonjs/{index-f77ba3de.js → worker-6ace445f.js} +97 -0
- package/dist/bundle/commonjs/workers.js +7 -8
- package/dist/bundle/module/block-worker-414860e0.js +43 -0
- package/dist/bundle/module/block-worker.js +3 -4
- package/dist/bundle/module/{machine-worker-a812956d.js → machine-worker-421324a1.js} +46 -36
- package/dist/bundle/module/machine-worker.js +4 -5
- package/dist/bundle/module/{pool-worker-012d12c9.js → pool-worker-0d927e3c.js} +6 -17
- package/dist/bundle/module/pool-worker.js +3 -3
- package/dist/bundle/module/{transaction-e9126d7b.js → transaction-cec98ce8.js} +1 -1
- package/dist/bundle/module/transaction-worker-548cd200.js +25 -0
- package/dist/bundle/module/transaction-worker.js +3 -3
- package/dist/bundle/module/{utils-d240ed61.js → utils-ac8c68e6.js} +44 -2
- package/dist/bundle/module/{index-6715242b.js → worker-def77c26.js} +79 -1
- package/dist/bundle/module/workers.js +7 -8
- package/dist/commonjs/block-worker-60e4cfa3.js +50 -0
- package/dist/commonjs/block-worker.js +3 -3
- package/dist/{bundle/commonjs/machine-worker-b376daef.js → commonjs/machine-worker-696e3b91.js} +52 -37
- package/dist/commonjs/machine-worker.js +4 -3
- package/dist/commonjs/{pool-worker-3d581327.js → pool-worker-81e8b4c0.js} +9 -15
- package/dist/commonjs/pool-worker.js +2 -1
- package/dist/commonjs/transaction-worker-8eecc7a1.js +32 -0
- package/dist/commonjs/transaction-worker.js +2 -1
- package/dist/commonjs/{utils-def2fce8.js → utils-1dc37f72.js} +44 -0
- package/dist/commonjs/workers.js +7 -6
- package/dist/module/block-worker-f539b1b2.js +44 -0
- package/dist/module/block-worker.js +3 -3
- package/dist/module/{machine-worker-08b605fa.js → machine-worker-e7d98549.js} +46 -35
- package/dist/module/machine-worker.js +4 -3
- package/dist/module/{pool-worker-8d3369b4.js → pool-worker-f65671d7.js} +5 -15
- package/dist/module/pool-worker.js +2 -1
- package/dist/module/{transaction-worker-0f96397e.js → transaction-worker-105deaa8.js} +11 -18
- package/dist/module/transaction-worker.js +2 -1
- package/dist/module/{utils-96ad7b3e.js → utils-e87bc63d.js} +44 -1
- package/dist/module/workers.js +7 -6
- package/package.json +22 -22
- package/src/block-worker.js +13 -44
- package/src/machine-worker.js +46 -34
- package/src/pool-worker.js +7 -16
- package/src/transaction-worker.js +13 -19
- package/dist/bundle/commonjs/block-worker-42d9ae8e.js +0 -115
- package/dist/bundle/commonjs/transaction-worker-90623101.js +0 -35
- package/dist/bundle/module/block-worker-efe837c4.js +0 -113
- package/dist/bundle/module/transaction-worker-8afddd7e.js +0 -33
- package/dist/commonjs/block-worker-d849f917.js +0 -115
- package/dist/commonjs/transaction-worker-02476daf.js +0 -35
- package/dist/module/block-worker-f5b28240.js +0 -113
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var worker$1 = require('./worker-6ace445f.js');
|
|
4
|
+
var utils = require('./utils-6e881be4.js');
|
|
5
|
+
|
|
6
|
+
const worker = new worker$1.EasyWorker();
|
|
7
|
+
|
|
8
|
+
globalThis.BigNumber = utils.BigNumber;
|
|
9
|
+
|
|
10
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
11
|
+
globalThis.contracts = {};
|
|
12
|
+
|
|
13
|
+
const run = async (blocks) => {
|
|
14
|
+
blocks = await Promise.all(blocks.map(block => new utils.BlockMessage(block)));
|
|
15
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
16
|
+
|
|
17
|
+
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
18
|
+
// todo: tx worker or nah?
|
|
19
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
20
|
+
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${utils.formatBytes(size)}`);
|
|
21
|
+
resolve(block);
|
|
22
|
+
})));
|
|
23
|
+
return blocks
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const tasks = async blocks => {
|
|
27
|
+
globalThis.peernet.codecs = {
|
|
28
|
+
'block-message': {
|
|
29
|
+
codec: parseInt('626d', 16),
|
|
30
|
+
hashAlg: 'keccak-256'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
blocks = await run(blocks);
|
|
35
|
+
worker.postMessage(blocks);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
worker.onmessage(data => tasks(data));
|
|
40
|
+
|
|
41
|
+
var blockWorker = /*#__PURE__*/Object.freeze({
|
|
42
|
+
__proto__: null
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
exports.blockWorker = blockWorker;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
6
|
-
require('child_process');
|
|
3
|
+
require('./worker-6ace445f.js');
|
|
4
|
+
require('./utils-6e881be4.js');
|
|
5
|
+
require('./block-worker-21ad8152.js');
|
|
7
6
|
require('stream');
|
|
8
7
|
require('events');
|
|
9
8
|
require('buffer');
|
package/dist/{commonjs/machine-worker-481c0a4b.js → bundle/commonjs/machine-worker-13071997.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var utils = require('./utils-
|
|
5
|
-
var
|
|
3
|
+
var worker$1 = require('./worker-6ace445f.js');
|
|
4
|
+
var utils = require('./utils-6e881be4.js');
|
|
5
|
+
var require$$1 = require('path');
|
|
6
6
|
|
|
7
7
|
var proto = `
|
|
8
8
|
message ContractMessage {
|
|
@@ -12,7 +12,7 @@ message ContractMessage {
|
|
|
12
12
|
}
|
|
13
13
|
`;
|
|
14
14
|
|
|
15
|
-
class ContractMessage extends
|
|
15
|
+
class ContractMessage extends worker$1.FormatInterface_1 {
|
|
16
16
|
get keys() {
|
|
17
17
|
return ['creator', 'contract', 'constructorParameters']
|
|
18
18
|
}
|
|
@@ -37,6 +37,8 @@ var bytecodes = {
|
|
|
37
37
|
validators: validators
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
const worker = new worker$1.EasyWorker();
|
|
41
|
+
|
|
40
42
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
41
43
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
42
44
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -47,6 +49,7 @@ globalThis.BigNumber = utils.BigNumber;
|
|
|
47
49
|
globalThis.peernet = globalThis.peernet || {};
|
|
48
50
|
globalThis.contracts = {};
|
|
49
51
|
|
|
52
|
+
|
|
50
53
|
const get = (contract, method, params) => {
|
|
51
54
|
let result;
|
|
52
55
|
if (params?.length > 0) {
|
|
@@ -92,7 +95,6 @@ const execute = async (contract, method, params) => {
|
|
|
92
95
|
} else {
|
|
93
96
|
result = await contracts[contract][method](...params);
|
|
94
97
|
}
|
|
95
|
-
|
|
96
98
|
// state.put(result)
|
|
97
99
|
return result
|
|
98
100
|
} catch (e) {
|
|
@@ -110,6 +112,22 @@ const createMessage = (sender = globalThis.peerid) => {
|
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
const _init = async ({ contracts, blocks, peerid })=> {
|
|
115
|
+
|
|
116
|
+
globalThis.peernet.codecs = {
|
|
117
|
+
'contract-message': {
|
|
118
|
+
codec: parseInt('63636d', 16),
|
|
119
|
+
hashAlg: 'keccak-256'
|
|
120
|
+
},
|
|
121
|
+
'transaction-message': {
|
|
122
|
+
codec: parseInt('746d', 16),
|
|
123
|
+
hashAlg: 'keccak-256'
|
|
124
|
+
},
|
|
125
|
+
'block-message': {
|
|
126
|
+
codec: parseInt('626d', 16),
|
|
127
|
+
hashAlg: 'keccak-256'
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
113
131
|
globalThis.peerid = peerid;
|
|
114
132
|
contracts = [
|
|
115
133
|
contractFactoryMessage,
|
|
@@ -124,19 +142,29 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
124
142
|
return contract
|
|
125
143
|
}));
|
|
126
144
|
|
|
127
|
-
const
|
|
145
|
+
const _worker = new worker$1.EasyWorker(require$$1.join(__dirname, './block-worker.js'), {serialization: 'advanced'});
|
|
128
146
|
// worker.on('message')
|
|
129
|
-
|
|
147
|
+
_worker.once('message', async (blocks) => {
|
|
130
148
|
for (const block of blocks) {
|
|
131
149
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
132
|
-
const {from, to, method, params} = message
|
|
150
|
+
const {from, to, method, params} = message;
|
|
133
151
|
globalThis.msg = createMessage(from);
|
|
134
152
|
|
|
135
153
|
await execute(to, method, params);
|
|
136
154
|
}));
|
|
137
155
|
}
|
|
138
|
-
|
|
139
|
-
|
|
156
|
+
let lastBlock;
|
|
157
|
+
if (blocks.length > 0) {
|
|
158
|
+
lastBlock = blocks[blocks.length - 1].decoded;
|
|
159
|
+
|
|
160
|
+
lastBlock = await new utils.BlockMessage(lastBlock);
|
|
161
|
+
lastBlock = {
|
|
162
|
+
...lastBlock.decoded,
|
|
163
|
+
hash: await lastBlock.hash
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
worker.postMessage({type: 'machine-ready', lastBlock });
|
|
167
|
+
_worker.terminate();
|
|
140
168
|
|
|
141
169
|
|
|
142
170
|
|
|
@@ -145,54 +173,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
145
173
|
};
|
|
146
174
|
|
|
147
175
|
const tasks = async (e) => {
|
|
148
|
-
|
|
149
|
-
'contract-message': {
|
|
150
|
-
codec: parseInt('63636d', 16),
|
|
151
|
-
hashAlg: 'keccak-256'
|
|
152
|
-
},
|
|
153
|
-
'transaction-message': {
|
|
154
|
-
codec: parseInt('746d', 16),
|
|
155
|
-
hashAlg: 'keccak-256'
|
|
156
|
-
},
|
|
157
|
-
'block-message': {
|
|
158
|
-
codec: parseInt('626d', 16),
|
|
159
|
-
hashAlg: 'keccak-256'
|
|
160
|
-
}
|
|
161
|
-
};
|
|
176
|
+
const id = e.id;
|
|
162
177
|
if (e.type === 'init') await _init(e.input);
|
|
163
178
|
if (e.type === 'get') {
|
|
164
179
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
165
|
-
|
|
180
|
+
worker.postMessage({
|
|
166
181
|
type: 'response',
|
|
167
|
-
id
|
|
182
|
+
id,
|
|
168
183
|
value
|
|
169
184
|
});
|
|
170
185
|
}
|
|
171
186
|
if (e.type === 'execute') {
|
|
172
187
|
try {
|
|
173
188
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
174
|
-
|
|
189
|
+
worker.postMessage({
|
|
175
190
|
type: 'response',
|
|
176
|
-
id
|
|
191
|
+
id,
|
|
177
192
|
value
|
|
178
193
|
});
|
|
179
194
|
} catch(e) {
|
|
180
|
-
|
|
195
|
+
worker.postMessage({
|
|
181
196
|
type: 'executionError',
|
|
182
|
-
message: e,
|
|
183
|
-
id
|
|
197
|
+
message: e.message,
|
|
198
|
+
id
|
|
184
199
|
|
|
185
200
|
});
|
|
186
201
|
}
|
|
187
202
|
}
|
|
188
203
|
};
|
|
189
204
|
|
|
190
|
-
|
|
191
|
-
if (globalThis.process) {
|
|
192
|
-
process.on('message', tasks);
|
|
193
|
-
} else {
|
|
194
|
-
onmessage = message => tasks(message.data);
|
|
195
|
-
}
|
|
205
|
+
worker.onmessage(data => tasks(data));
|
|
196
206
|
|
|
197
207
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
198
208
|
__proto__: null
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./machine-worker-
|
|
4
|
-
require('./
|
|
5
|
-
require('./utils-
|
|
6
|
-
require('
|
|
3
|
+
require('./machine-worker-13071997.js');
|
|
4
|
+
require('./worker-6ace445f.js');
|
|
5
|
+
require('./utils-6e881be4.js');
|
|
6
|
+
require('path');
|
|
7
7
|
require('stream');
|
|
8
8
|
require('events');
|
|
9
9
|
require('buffer');
|
|
10
10
|
require('util');
|
|
11
11
|
require('string_decoder/');
|
|
12
12
|
require('fs');
|
|
13
|
-
require('path');
|
|
14
13
|
require('os');
|
|
15
14
|
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
var transaction = require('./transaction-
|
|
3
|
+
var worker$1 = require('./worker-6ace445f.js');
|
|
4
|
+
var transaction = require('./transaction-d7c6a8ee.js');
|
|
5
5
|
|
|
6
6
|
globalThis.peernet = globalThis.peernet || {};
|
|
7
7
|
globalThis.contracts = {};
|
|
8
8
|
|
|
9
|
+
const worker = new worker$1.EasyWorker();
|
|
10
|
+
|
|
9
11
|
const tasks = async transactions => {
|
|
10
12
|
|
|
11
13
|
globalThis.peernet.codecs = {
|
|
12
|
-
'contract-message': {
|
|
13
|
-
codec: parseInt('63636d', 16),
|
|
14
|
-
hashAlg: 'keccak-256'
|
|
15
|
-
},
|
|
16
14
|
'transaction-message': {
|
|
17
15
|
codec: parseInt('746d', 16),
|
|
18
16
|
hashAlg: 'keccak-256'
|
|
19
|
-
},
|
|
20
|
-
'block-message': {
|
|
21
|
-
codec: parseInt('626d', 16),
|
|
22
|
-
hashAlg: 'keccak-256'
|
|
23
17
|
}
|
|
24
18
|
};
|
|
25
19
|
|
|
@@ -29,15 +23,10 @@ const tasks = async transactions => {
|
|
|
29
23
|
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
30
24
|
}));
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
worker.postMessage(transactions);
|
|
33
27
|
|
|
34
28
|
};
|
|
35
|
-
|
|
36
|
-
if (globalThis.process) {
|
|
37
|
-
process.on('message', tasks);
|
|
38
|
-
} else {
|
|
39
|
-
onmessage = message => tasks(message.data);
|
|
40
|
-
}
|
|
29
|
+
worker.onmessage(data => tasks(data));
|
|
41
30
|
|
|
42
31
|
var poolWorker = /*#__PURE__*/Object.freeze({
|
|
43
32
|
__proto__: null
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
require('./transaction-
|
|
5
|
-
require('./pool-worker-
|
|
3
|
+
require('./worker-6ace445f.js');
|
|
4
|
+
require('./transaction-d7c6a8ee.js');
|
|
5
|
+
require('./pool-worker-f450eeff.js');
|
|
6
6
|
require('stream');
|
|
7
7
|
require('events');
|
|
8
8
|
require('buffer');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var worker = require('./worker-6ace445f.js');
|
|
4
4
|
|
|
5
5
|
var proto = `
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ message TransactionMessage {
|
|
|
15
15
|
}
|
|
16
16
|
`;
|
|
17
17
|
|
|
18
|
-
class TransactionMessage extends
|
|
18
|
+
class TransactionMessage extends worker.FormatInterface_1 {
|
|
19
19
|
get keys() {
|
|
20
20
|
return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
|
|
21
21
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var worker$1 = require('./worker-6ace445f.js');
|
|
4
|
+
var transaction = require('./transaction-d7c6a8ee.js');
|
|
5
|
+
|
|
6
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
7
|
+
globalThis.contracts = {};
|
|
8
|
+
|
|
9
|
+
const worker = new worker$1.EasyWorker();
|
|
10
|
+
|
|
11
|
+
worker.onmessage(async (transactions) => {
|
|
12
|
+
globalThis.peernet.codecs = {
|
|
13
|
+
'transaction-message': {
|
|
14
|
+
codec: parseInt('746d', 16),
|
|
15
|
+
hashAlg: 'keccak-256'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
transactions = await Promise.all(transactions.map(async message => new transaction.TransactionMessage(message)));
|
|
19
|
+
|
|
20
|
+
worker.postMessage(transactions);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var transactionWorker = /*#__PURE__*/Object.freeze({
|
|
24
|
+
__proto__: null
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
exports.transactionWorker = transactionWorker;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
require('./transaction-
|
|
5
|
-
require('./transaction-worker-
|
|
3
|
+
require('./worker-6ace445f.js');
|
|
4
|
+
require('./transaction-d7c6a8ee.js');
|
|
5
|
+
require('./transaction-worker-176a5aaa.js');
|
|
6
6
|
require('stream');
|
|
7
7
|
require('events');
|
|
8
8
|
require('buffer');
|
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var worker = require('./worker-6ace445f.js');
|
|
4
|
+
|
|
5
|
+
var proto = `
|
|
6
|
+
message ValidatorMessage {
|
|
7
|
+
required string address = 1;
|
|
8
|
+
required string reward = 2;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
message Transaction {
|
|
12
|
+
required string hash = 1;
|
|
13
|
+
required uint64 timestamp = 2;
|
|
14
|
+
required string from = 3;
|
|
15
|
+
required string to = 4;
|
|
16
|
+
required uint64 nonce = 5;
|
|
17
|
+
required string method = 6;
|
|
18
|
+
repeated string params = 7;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
message BlockMessage {
|
|
22
|
+
required uint64 index = 1;
|
|
23
|
+
required string previousHash = 3;
|
|
24
|
+
required uint64 timestamp = 4;
|
|
25
|
+
required uint64 reward = 5;
|
|
26
|
+
required string fees = 6;
|
|
27
|
+
repeated Transaction transactions = 7;
|
|
28
|
+
repeated ValidatorMessage validators = 8;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
class BlockMessage extends worker.FormatInterface_1 {
|
|
33
|
+
get keys() {
|
|
34
|
+
return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get messageName() {
|
|
38
|
+
return 'BlockMessage'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
constructor(buffer) {
|
|
42
|
+
const name = 'block-message';
|
|
43
|
+
super(buffer, proto, {name});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
4
46
|
|
|
5
47
|
var bn = {exports: {}};
|
|
6
48
|
|
|
@@ -3352,7 +3394,7 @@ var bn = {exports: {}};
|
|
|
3352
3394
|
var res = this.imod(a._invmp(this.m).mul(this.r2));
|
|
3353
3395
|
return res._forceRed(this);
|
|
3354
3396
|
};
|
|
3355
|
-
})(module,
|
|
3397
|
+
})(module, worker.commonjsGlobal);
|
|
3356
3398
|
} (bn));
|
|
3357
3399
|
|
|
3358
3400
|
var _BN = bn.exports;
|
|
@@ -4093,4 +4135,5 @@ const formatBytes = (bytes, decimals = 2) => {
|
|
|
4093
4135
|
};
|
|
4094
4136
|
|
|
4095
4137
|
exports.BigNumber = BigNumber;
|
|
4138
|
+
exports.BlockMessage = BlockMessage;
|
|
4096
4139
|
exports.formatBytes = formatBytes;
|
|
@@ -11,6 +11,24 @@ var require$$2$2 = require('os');
|
|
|
11
11
|
|
|
12
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
13
|
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n["default"] = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
14
32
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
15
33
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
16
34
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
@@ -4790,5 +4808,84 @@ dist.CodecHash = CodecHash;
|
|
|
4790
4808
|
dist.Codecs = Codecs;
|
|
4791
4809
|
var FormatInterface_1 = dist.FormatInterface = FormatInterface;
|
|
4792
4810
|
|
|
4811
|
+
class EasyWorker {
|
|
4812
|
+
#messageEvent = 'message'
|
|
4813
|
+
#errorEvent = 'error'
|
|
4814
|
+
#isBrowser = false
|
|
4815
|
+
#isWorker = false
|
|
4816
|
+
|
|
4817
|
+
get isWorker() {
|
|
4818
|
+
return this.#isWorker
|
|
4819
|
+
}
|
|
4820
|
+
constructor(url, options) {
|
|
4821
|
+
return this.#init(url, options)
|
|
4822
|
+
}
|
|
4823
|
+
|
|
4824
|
+
#init(url, options = {}) {
|
|
4825
|
+
if (url) {
|
|
4826
|
+
if (globalThis.Worker) {
|
|
4827
|
+
this.#isBrowser = true;
|
|
4828
|
+
this.worker = new Worker(url, {...options});
|
|
4829
|
+
} else {
|
|
4830
|
+
return new Promise(async (resolve, reject) => {
|
|
4831
|
+
const {fork} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('child_process')); });
|
|
4832
|
+
this.worker = fork(url, ['easy-worker-child'], options);
|
|
4833
|
+
resolve(this);
|
|
4834
|
+
})
|
|
4835
|
+
}
|
|
4836
|
+
} else {
|
|
4837
|
+
this.#isWorker = true;
|
|
4838
|
+
if (globalThis.process?.argv[2] === 'easy-worker-child') {
|
|
4839
|
+
this.worker = process;
|
|
4840
|
+
} else {
|
|
4841
|
+
this.#isBrowser = true;
|
|
4842
|
+
this.worker = globalThis;
|
|
4843
|
+
}
|
|
4844
|
+
}
|
|
4845
|
+
|
|
4846
|
+
return this
|
|
4847
|
+
}
|
|
4848
|
+
|
|
4849
|
+
onmessage(fn) {
|
|
4850
|
+
if (this.#isBrowser) this.worker.onmessage = ({data}) => fn(data);
|
|
4851
|
+
else this.worker.on(this.#messageEvent, fn);
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4854
|
+
postMessage(message) {
|
|
4855
|
+
if (this.#isBrowser) this.worker.postMessage(message);
|
|
4856
|
+
else this.worker.send(message);
|
|
4857
|
+
}
|
|
4858
|
+
|
|
4859
|
+
terminate() {
|
|
4860
|
+
if (this.#isBrowser) this.worker.terminate();
|
|
4861
|
+
else this.worker.kill();
|
|
4862
|
+
}
|
|
4863
|
+
|
|
4864
|
+
onerror(fn) {
|
|
4865
|
+
if (this.#isBrowser) this.worker.onerror = fn;
|
|
4866
|
+
else this.worker.on(this.#errorEvent, fn);
|
|
4867
|
+
}
|
|
4868
|
+
|
|
4869
|
+
/**
|
|
4870
|
+
*
|
|
4871
|
+
* @param {*} data
|
|
4872
|
+
* @returns {Promise} resolves result onmessage & rejects on error
|
|
4873
|
+
*/
|
|
4874
|
+
once(data) {
|
|
4875
|
+
return new Promise((resolve, reject) => {
|
|
4876
|
+
this.onmessage(message => {
|
|
4877
|
+
resolve(message);
|
|
4878
|
+
this.terminate();
|
|
4879
|
+
});
|
|
4880
|
+
this.onerror(error => {
|
|
4881
|
+
reject(error);
|
|
4882
|
+
this.terminate();
|
|
4883
|
+
});
|
|
4884
|
+
this.postMessage(data);
|
|
4885
|
+
})
|
|
4886
|
+
}
|
|
4887
|
+
}
|
|
4888
|
+
|
|
4889
|
+
exports.EasyWorker = EasyWorker;
|
|
4793
4890
|
exports.FormatInterface_1 = FormatInterface_1;
|
|
4794
4891
|
exports.commonjsGlobal = commonjsGlobal;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var transactionWorker = require('./transaction-worker-
|
|
6
|
-
var blockWorker = require('./block-worker-
|
|
7
|
-
var poolWorker = require('./pool-worker-
|
|
8
|
-
var machineWorker = require('./machine-worker-
|
|
9
|
-
require('./
|
|
5
|
+
var transactionWorker = require('./transaction-worker-176a5aaa.js');
|
|
6
|
+
var blockWorker = require('./block-worker-21ad8152.js');
|
|
7
|
+
var poolWorker = require('./pool-worker-f450eeff.js');
|
|
8
|
+
var machineWorker = require('./machine-worker-13071997.js');
|
|
9
|
+
require('./worker-6ace445f.js');
|
|
10
10
|
require('stream');
|
|
11
11
|
require('events');
|
|
12
12
|
require('buffer');
|
|
@@ -15,9 +15,8 @@ require('string_decoder/');
|
|
|
15
15
|
require('fs');
|
|
16
16
|
require('path');
|
|
17
17
|
require('os');
|
|
18
|
-
require('./transaction-
|
|
19
|
-
require('./utils-
|
|
20
|
-
require('child_process');
|
|
18
|
+
require('./transaction-d7c6a8ee.js');
|
|
19
|
+
require('./utils-6e881be4.js');
|
|
21
20
|
|
|
22
21
|
const TransactionWorker = transactionWorker.transactionWorker;
|
|
23
22
|
const BlockWorker = blockWorker.blockWorker;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { E as EasyWorker } from './worker-def77c26.js';
|
|
2
|
+
import { B as BigNumber, a as BlockMessage, f as formatBytes } from './utils-ac8c68e6.js';
|
|
3
|
+
|
|
4
|
+
const worker = new EasyWorker();
|
|
5
|
+
|
|
6
|
+
globalThis.BigNumber = BigNumber;
|
|
7
|
+
|
|
8
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
9
|
+
globalThis.contracts = {};
|
|
10
|
+
|
|
11
|
+
const run = async (blocks) => {
|
|
12
|
+
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
13
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
14
|
+
|
|
15
|
+
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
16
|
+
// todo: tx worker or nah?
|
|
17
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
18
|
+
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
19
|
+
resolve(block);
|
|
20
|
+
})));
|
|
21
|
+
return blocks
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const tasks = async blocks => {
|
|
25
|
+
globalThis.peernet.codecs = {
|
|
26
|
+
'block-message': {
|
|
27
|
+
codec: parseInt('626d', 16),
|
|
28
|
+
hashAlg: 'keccak-256'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
blocks = await run(blocks);
|
|
33
|
+
worker.postMessage(blocks);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
worker.onmessage(data => tasks(data));
|
|
38
|
+
|
|
39
|
+
var blockWorker = /*#__PURE__*/Object.freeze({
|
|
40
|
+
__proto__: null
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export { blockWorker as b };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './
|
|
3
|
-
import './
|
|
4
|
-
import 'child_process';
|
|
1
|
+
import './worker-def77c26.js';
|
|
2
|
+
import './utils-ac8c68e6.js';
|
|
3
|
+
import './block-worker-414860e0.js';
|
|
5
4
|
import 'stream';
|
|
6
5
|
import 'events';
|
|
7
6
|
import 'buffer';
|