@leofcoin/workers 1.1.1 → 1.2.1
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 +4 -5
- package/dist/bundle/commonjs/{machine-worker-28ffe20b.js → machine-worker-e96e3082.js} +25 -20
- package/dist/bundle/commonjs/machine-worker.js +3 -4
- 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 +4 -5
- package/dist/bundle/module/{machine-worker-5f6457bd.js → machine-worker-e3020b69.js} +24 -19
- package/dist/bundle/module/machine-worker.js +3 -4
- 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 -4
- package/dist/commonjs/{machine-worker-5e1073c1.js → machine-worker-16dad57f.js} +28 -18
- package/dist/commonjs/machine-worker.js +3 -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 +6 -6
- package/dist/module/block-worker-f539b1b2.js +44 -0
- package/dist/module/block-worker.js +3 -4
- package/dist/module/{machine-worker-12c3eda2.js → machine-worker-a2897101.js} +24 -18
- package/dist/module/machine-worker.js +3 -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 +6 -6
- package/package.json +22 -22
- package/src/block-worker.js +13 -45
- package/src/machine-worker.js +25 -18
- package/src/pool-worker.js +7 -16
- package/src/transaction-worker.js +13 -19
- package/dist/bundle/commonjs/block-worker-81701b46.js +0 -116
- package/dist/bundle/commonjs/transaction-worker-90623101.js +0 -35
- package/dist/bundle/module/block-worker-6f72caf6.js +0 -114
- package/dist/bundle/module/transaction-worker-8afddd7e.js +0 -33
- package/dist/commonjs/block-worker-9ae351ea.js +0 -116
- package/dist/commonjs/transaction-worker-02476daf.js +0 -35
- package/dist/module/block-worker-d07e9a9f.js +0 -114
|
@@ -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,15 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
6
|
-
require('child_process');
|
|
7
|
-
require('path');
|
|
3
|
+
require('./worker-6ace445f.js');
|
|
4
|
+
require('./utils-6e881be4.js');
|
|
5
|
+
require('./block-worker-21ad8152.js');
|
|
8
6
|
require('stream');
|
|
9
7
|
require('events');
|
|
10
8
|
require('buffer');
|
|
11
9
|
require('util');
|
|
12
10
|
require('string_decoder/');
|
|
13
11
|
require('fs');
|
|
12
|
+
require('path');
|
|
14
13
|
require('os');
|
|
15
14
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var utils = require('./utils-
|
|
5
|
-
var child_process = require('child_process');
|
|
3
|
+
var worker$1 = require('./worker-6ace445f.js');
|
|
4
|
+
var utils = require('./utils-6e881be4.js');
|
|
6
5
|
var require$$1 = require('path');
|
|
7
6
|
|
|
8
7
|
var proto = `
|
|
@@ -13,7 +12,7 @@ message ContractMessage {
|
|
|
13
12
|
}
|
|
14
13
|
`;
|
|
15
14
|
|
|
16
|
-
class ContractMessage extends
|
|
15
|
+
class ContractMessage extends worker$1.FormatInterface_1 {
|
|
17
16
|
get keys() {
|
|
18
17
|
return ['creator', 'contract', 'constructorParameters']
|
|
19
18
|
}
|
|
@@ -38,6 +37,8 @@ var bytecodes = {
|
|
|
38
37
|
validators: validators
|
|
39
38
|
};
|
|
40
39
|
|
|
40
|
+
const worker = new worker$1.EasyWorker();
|
|
41
|
+
|
|
41
42
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
42
43
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
43
44
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -94,7 +95,6 @@ const execute = async (contract, method, params) => {
|
|
|
94
95
|
} else {
|
|
95
96
|
result = await contracts[contract][method](...params);
|
|
96
97
|
}
|
|
97
|
-
|
|
98
98
|
// state.put(result)
|
|
99
99
|
return result
|
|
100
100
|
} catch (e) {
|
|
@@ -142,24 +142,34 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
142
142
|
return contract
|
|
143
143
|
}));
|
|
144
144
|
|
|
145
|
-
const
|
|
145
|
+
const _worker = await new worker$1.EasyWorker(require$$1.join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
|
|
146
146
|
// worker.on('message')
|
|
147
|
-
|
|
147
|
+
_worker.once('message', async (blocks) => {
|
|
148
148
|
for (const block of blocks) {
|
|
149
149
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
150
|
-
const {from, to, method, params} = message
|
|
150
|
+
const {from, to, method, params} = message;
|
|
151
151
|
globalThis.msg = createMessage(from);
|
|
152
152
|
|
|
153
153
|
await execute(to, method, params);
|
|
154
154
|
}));
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
|
|
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();
|
|
158
168
|
|
|
159
169
|
|
|
160
170
|
|
|
161
171
|
});
|
|
162
|
-
worker.
|
|
172
|
+
worker.postMessage(blocks);
|
|
163
173
|
};
|
|
164
174
|
|
|
165
175
|
const tasks = async (e) => {
|
|
@@ -167,7 +177,7 @@ const tasks = async (e) => {
|
|
|
167
177
|
if (e.type === 'init') await _init(e.input);
|
|
168
178
|
if (e.type === 'get') {
|
|
169
179
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
170
|
-
|
|
180
|
+
worker.postMessage({
|
|
171
181
|
type: 'response',
|
|
172
182
|
id,
|
|
173
183
|
value
|
|
@@ -176,13 +186,13 @@ const tasks = async (e) => {
|
|
|
176
186
|
if (e.type === 'execute') {
|
|
177
187
|
try {
|
|
178
188
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
179
|
-
|
|
189
|
+
worker.postMessage({
|
|
180
190
|
type: 'response',
|
|
181
191
|
id,
|
|
182
192
|
value
|
|
183
193
|
});
|
|
184
194
|
} catch(e) {
|
|
185
|
-
|
|
195
|
+
worker.postMessage({
|
|
186
196
|
type: 'executionError',
|
|
187
197
|
message: e.message,
|
|
188
198
|
id
|
|
@@ -192,12 +202,7 @@ const tasks = async (e) => {
|
|
|
192
202
|
}
|
|
193
203
|
};
|
|
194
204
|
|
|
195
|
-
|
|
196
|
-
if (globalThis.process) {
|
|
197
|
-
process.on('message', tasks);
|
|
198
|
-
} else {
|
|
199
|
-
onmessage = message => tasks(message.data);
|
|
200
|
-
}
|
|
205
|
+
worker.onmessage(data => tasks(data));
|
|
201
206
|
|
|
202
207
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
203
208
|
__proto__: null
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./machine-worker-
|
|
4
|
-
require('./
|
|
5
|
-
require('./utils-
|
|
6
|
-
require('child_process');
|
|
3
|
+
require('./machine-worker-e96e3082.js');
|
|
4
|
+
require('./worker-6ace445f.js');
|
|
5
|
+
require('./utils-6e881be4.js');
|
|
7
6
|
require('path');
|
|
8
7
|
require('stream');
|
|
9
8
|
require('events');
|
|
@@ -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-e96e3082.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,12 +1,11 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './
|
|
3
|
-
import './
|
|
4
|
-
import 'child_process';
|
|
5
|
-
import 'path';
|
|
1
|
+
import './worker-def77c26.js';
|
|
2
|
+
import './utils-ac8c68e6.js';
|
|
3
|
+
import './block-worker-414860e0.js';
|
|
6
4
|
import 'stream';
|
|
7
5
|
import 'events';
|
|
8
6
|
import 'buffer';
|
|
9
7
|
import 'util';
|
|
10
8
|
import 'string_decoder/';
|
|
11
9
|
import 'fs';
|
|
10
|
+
import 'path';
|
|
12
11
|
import 'os';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { F as FormatInterface_1 } from './
|
|
2
|
-
import { B as BigNumber, f as formatBytes } from './utils-
|
|
3
|
-
import { fork } from 'child_process';
|
|
1
|
+
import { F as FormatInterface_1, E as EasyWorker } from './worker-def77c26.js';
|
|
2
|
+
import { B as BigNumber, a as BlockMessage, f as formatBytes } from './utils-ac8c68e6.js';
|
|
4
3
|
import { join } from 'path';
|
|
5
4
|
|
|
6
5
|
var proto = `
|
|
@@ -36,6 +35,8 @@ var bytecodes = {
|
|
|
36
35
|
validators: validators
|
|
37
36
|
};
|
|
38
37
|
|
|
38
|
+
const worker = new EasyWorker();
|
|
39
|
+
|
|
39
40
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
40
41
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
41
42
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -92,7 +93,6 @@ const execute = async (contract, method, params) => {
|
|
|
92
93
|
} else {
|
|
93
94
|
result = await contracts[contract][method](...params);
|
|
94
95
|
}
|
|
95
|
-
|
|
96
96
|
// state.put(result)
|
|
97
97
|
return result
|
|
98
98
|
} catch (e) {
|
|
@@ -140,24 +140,34 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
140
140
|
return contract
|
|
141
141
|
}));
|
|
142
142
|
|
|
143
|
-
const
|
|
143
|
+
const _worker = await new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced', type: 'module' });
|
|
144
144
|
// worker.on('message')
|
|
145
|
-
|
|
145
|
+
_worker.once('message', async (blocks) => {
|
|
146
146
|
for (const block of blocks) {
|
|
147
147
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
148
|
-
const {from, to, method, params} = message
|
|
148
|
+
const {from, to, method, params} = message;
|
|
149
149
|
globalThis.msg = createMessage(from);
|
|
150
150
|
|
|
151
151
|
await execute(to, method, params);
|
|
152
152
|
}));
|
|
153
153
|
}
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
let lastBlock;
|
|
155
|
+
if (blocks.length > 0) {
|
|
156
|
+
lastBlock = blocks[blocks.length - 1].decoded;
|
|
157
|
+
|
|
158
|
+
lastBlock = await new BlockMessage(lastBlock);
|
|
159
|
+
lastBlock = {
|
|
160
|
+
...lastBlock.decoded,
|
|
161
|
+
hash: await lastBlock.hash
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
worker.postMessage({type: 'machine-ready', lastBlock });
|
|
165
|
+
_worker.terminate();
|
|
156
166
|
|
|
157
167
|
|
|
158
168
|
|
|
159
169
|
});
|
|
160
|
-
worker.
|
|
170
|
+
worker.postMessage(blocks);
|
|
161
171
|
};
|
|
162
172
|
|
|
163
173
|
const tasks = async (e) => {
|
|
@@ -165,7 +175,7 @@ const tasks = async (e) => {
|
|
|
165
175
|
if (e.type === 'init') await _init(e.input);
|
|
166
176
|
if (e.type === 'get') {
|
|
167
177
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
168
|
-
|
|
178
|
+
worker.postMessage({
|
|
169
179
|
type: 'response',
|
|
170
180
|
id,
|
|
171
181
|
value
|
|
@@ -174,13 +184,13 @@ const tasks = async (e) => {
|
|
|
174
184
|
if (e.type === 'execute') {
|
|
175
185
|
try {
|
|
176
186
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
177
|
-
|
|
187
|
+
worker.postMessage({
|
|
178
188
|
type: 'response',
|
|
179
189
|
id,
|
|
180
190
|
value
|
|
181
191
|
});
|
|
182
192
|
} catch(e) {
|
|
183
|
-
|
|
193
|
+
worker.postMessage({
|
|
184
194
|
type: 'executionError',
|
|
185
195
|
message: e.message,
|
|
186
196
|
id
|
|
@@ -190,12 +200,7 @@ const tasks = async (e) => {
|
|
|
190
200
|
}
|
|
191
201
|
};
|
|
192
202
|
|
|
193
|
-
|
|
194
|
-
if (globalThis.process) {
|
|
195
|
-
process.on('message', tasks);
|
|
196
|
-
} else {
|
|
197
|
-
onmessage = message => tasks(message.data);
|
|
198
|
-
}
|
|
203
|
+
worker.onmessage(data => tasks(data));
|
|
199
204
|
|
|
200
205
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
201
206
|
__proto__: null
|