@leofcoin/workers 1.1.1 → 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 +4 -5
- package/dist/bundle/commonjs/{machine-worker-28ffe20b.js → machine-worker-13071997.js} +24 -19
- 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-421324a1.js} +23 -18
- 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-696e3b91.js} +27 -17
- 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-e7d98549.js} +23 -17
- 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 +23 -16
- 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
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import { T as TransactionMessage } from './transaction-
|
|
1
|
+
import { E as EasyWorker } from './worker-def77c26.js';
|
|
2
|
+
import { T as TransactionMessage } from './transaction-cec98ce8.js';
|
|
3
3
|
|
|
4
4
|
globalThis.peernet = globalThis.peernet || {};
|
|
5
5
|
globalThis.contracts = {};
|
|
6
6
|
|
|
7
|
+
const worker = new EasyWorker();
|
|
8
|
+
|
|
7
9
|
const tasks = async transactions => {
|
|
8
10
|
|
|
9
11
|
globalThis.peernet.codecs = {
|
|
10
|
-
'contract-message': {
|
|
11
|
-
codec: parseInt('63636d', 16),
|
|
12
|
-
hashAlg: 'keccak-256'
|
|
13
|
-
},
|
|
14
12
|
'transaction-message': {
|
|
15
13
|
codec: parseInt('746d', 16),
|
|
16
14
|
hashAlg: 'keccak-256'
|
|
17
|
-
},
|
|
18
|
-
'block-message': {
|
|
19
|
-
codec: parseInt('626d', 16),
|
|
20
|
-
hashAlg: 'keccak-256'
|
|
21
15
|
}
|
|
22
16
|
};
|
|
23
17
|
|
|
@@ -27,15 +21,10 @@ const tasks = async transactions => {
|
|
|
27
21
|
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
28
22
|
}));
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
worker.postMessage(transactions);
|
|
31
25
|
|
|
32
26
|
};
|
|
33
|
-
|
|
34
|
-
if (globalThis.process) {
|
|
35
|
-
process.on('message', tasks);
|
|
36
|
-
} else {
|
|
37
|
-
onmessage = message => tasks(message.data);
|
|
38
|
-
}
|
|
27
|
+
worker.onmessage(data => tasks(data));
|
|
39
28
|
|
|
40
29
|
var poolWorker = /*#__PURE__*/Object.freeze({
|
|
41
30
|
__proto__: null
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './transaction-
|
|
3
|
-
import './pool-worker-
|
|
1
|
+
import './worker-def77c26.js';
|
|
2
|
+
import './transaction-cec98ce8.js';
|
|
3
|
+
import './pool-worker-0d927e3c.js';
|
|
4
4
|
import 'stream';
|
|
5
5
|
import 'events';
|
|
6
6
|
import 'buffer';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { E as EasyWorker } from './worker-def77c26.js';
|
|
2
|
+
import { T as TransactionMessage } from './transaction-cec98ce8.js';
|
|
3
|
+
|
|
4
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
5
|
+
globalThis.contracts = {};
|
|
6
|
+
|
|
7
|
+
const worker = new EasyWorker();
|
|
8
|
+
|
|
9
|
+
worker.onmessage(async (transactions) => {
|
|
10
|
+
globalThis.peernet.codecs = {
|
|
11
|
+
'transaction-message': {
|
|
12
|
+
codec: parseInt('746d', 16),
|
|
13
|
+
hashAlg: 'keccak-256'
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)));
|
|
17
|
+
|
|
18
|
+
worker.postMessage(transactions);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var transactionWorker = /*#__PURE__*/Object.freeze({
|
|
22
|
+
__proto__: null
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { transactionWorker as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './transaction-
|
|
3
|
-
import './transaction-worker-
|
|
1
|
+
import './worker-def77c26.js';
|
|
2
|
+
import './transaction-cec98ce8.js';
|
|
3
|
+
import './transaction-worker-548cd200.js';
|
|
4
4
|
import 'stream';
|
|
5
5
|
import 'events';
|
|
6
6
|
import 'buffer';
|
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
import { c as commonjsGlobal } from './
|
|
1
|
+
import { F as FormatInterface_1, c as commonjsGlobal } from './worker-def77c26.js';
|
|
2
|
+
|
|
3
|
+
var proto = `
|
|
4
|
+
message ValidatorMessage {
|
|
5
|
+
required string address = 1;
|
|
6
|
+
required string reward = 2;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
message Transaction {
|
|
10
|
+
required string hash = 1;
|
|
11
|
+
required uint64 timestamp = 2;
|
|
12
|
+
required string from = 3;
|
|
13
|
+
required string to = 4;
|
|
14
|
+
required uint64 nonce = 5;
|
|
15
|
+
required string method = 6;
|
|
16
|
+
repeated string params = 7;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
message BlockMessage {
|
|
20
|
+
required uint64 index = 1;
|
|
21
|
+
required string previousHash = 3;
|
|
22
|
+
required uint64 timestamp = 4;
|
|
23
|
+
required uint64 reward = 5;
|
|
24
|
+
required string fees = 6;
|
|
25
|
+
repeated Transaction transactions = 7;
|
|
26
|
+
repeated ValidatorMessage validators = 8;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
class BlockMessage extends FormatInterface_1 {
|
|
31
|
+
get keys() {
|
|
32
|
+
return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get messageName() {
|
|
36
|
+
return 'BlockMessage'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
constructor(buffer) {
|
|
40
|
+
const name = 'block-message';
|
|
41
|
+
super(buffer, proto, {name});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
2
44
|
|
|
3
45
|
var bn = {exports: {}};
|
|
4
46
|
|
|
@@ -4090,4 +4132,4 @@ const formatBytes = (bytes, decimals = 2) => {
|
|
|
4090
4132
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`
|
|
4091
4133
|
};
|
|
4092
4134
|
|
|
4093
|
-
export { BigNumber as B, formatBytes as f };
|
|
4135
|
+
export { BigNumber as B, BlockMessage as a, formatBytes as f };
|
|
@@ -4777,4 +4777,82 @@ dist.CodecHash = CodecHash;
|
|
|
4777
4777
|
dist.Codecs = Codecs;
|
|
4778
4778
|
var FormatInterface_1 = dist.FormatInterface = FormatInterface;
|
|
4779
4779
|
|
|
4780
|
-
|
|
4780
|
+
class EasyWorker {
|
|
4781
|
+
#messageEvent = 'message'
|
|
4782
|
+
#errorEvent = 'error'
|
|
4783
|
+
#isBrowser = false
|
|
4784
|
+
#isWorker = false
|
|
4785
|
+
|
|
4786
|
+
get isWorker() {
|
|
4787
|
+
return this.#isWorker
|
|
4788
|
+
}
|
|
4789
|
+
constructor(url, options) {
|
|
4790
|
+
return this.#init(url, options)
|
|
4791
|
+
}
|
|
4792
|
+
|
|
4793
|
+
#init(url, options = {}) {
|
|
4794
|
+
if (url) {
|
|
4795
|
+
if (globalThis.Worker) {
|
|
4796
|
+
this.#isBrowser = true;
|
|
4797
|
+
this.worker = new Worker(url, {...options});
|
|
4798
|
+
} else {
|
|
4799
|
+
return new Promise(async (resolve, reject) => {
|
|
4800
|
+
const {fork} = await import('child_process');
|
|
4801
|
+
this.worker = fork(url, ['easy-worker-child'], options);
|
|
4802
|
+
resolve(this);
|
|
4803
|
+
})
|
|
4804
|
+
}
|
|
4805
|
+
} else {
|
|
4806
|
+
this.#isWorker = true;
|
|
4807
|
+
if (globalThis.process?.argv[2] === 'easy-worker-child') {
|
|
4808
|
+
this.worker = process;
|
|
4809
|
+
} else {
|
|
4810
|
+
this.#isBrowser = true;
|
|
4811
|
+
this.worker = globalThis;
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4815
|
+
return this
|
|
4816
|
+
}
|
|
4817
|
+
|
|
4818
|
+
onmessage(fn) {
|
|
4819
|
+
if (this.#isBrowser) this.worker.onmessage = ({data}) => fn(data);
|
|
4820
|
+
else this.worker.on(this.#messageEvent, fn);
|
|
4821
|
+
}
|
|
4822
|
+
|
|
4823
|
+
postMessage(message) {
|
|
4824
|
+
if (this.#isBrowser) this.worker.postMessage(message);
|
|
4825
|
+
else this.worker.send(message);
|
|
4826
|
+
}
|
|
4827
|
+
|
|
4828
|
+
terminate() {
|
|
4829
|
+
if (this.#isBrowser) this.worker.terminate();
|
|
4830
|
+
else this.worker.kill();
|
|
4831
|
+
}
|
|
4832
|
+
|
|
4833
|
+
onerror(fn) {
|
|
4834
|
+
if (this.#isBrowser) this.worker.onerror = fn;
|
|
4835
|
+
else this.worker.on(this.#errorEvent, fn);
|
|
4836
|
+
}
|
|
4837
|
+
|
|
4838
|
+
/**
|
|
4839
|
+
*
|
|
4840
|
+
* @param {*} data
|
|
4841
|
+
* @returns {Promise} resolves result onmessage & rejects on error
|
|
4842
|
+
*/
|
|
4843
|
+
once(data) {
|
|
4844
|
+
return new Promise((resolve, reject) => {
|
|
4845
|
+
this.onmessage(message => {
|
|
4846
|
+
resolve(message);
|
|
4847
|
+
this.terminate();
|
|
4848
|
+
});
|
|
4849
|
+
this.onerror(error => {
|
|
4850
|
+
reject(error);
|
|
4851
|
+
this.terminate();
|
|
4852
|
+
});
|
|
4853
|
+
this.postMessage(data);
|
|
4854
|
+
})
|
|
4855
|
+
}
|
|
4856
|
+
}
|
|
4857
|
+
|
|
4858
|
+
export { EasyWorker as E, FormatInterface_1 as F, commonjsGlobal as c };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as transactionWorker } from './transaction-worker-
|
|
2
|
-
import { b as blockWorker } from './block-worker-
|
|
3
|
-
import { p as poolWorker } from './pool-worker-
|
|
4
|
-
import { m as machineWorker } from './machine-worker-
|
|
5
|
-
import './
|
|
1
|
+
import { t as transactionWorker } from './transaction-worker-548cd200.js';
|
|
2
|
+
import { b as blockWorker } from './block-worker-414860e0.js';
|
|
3
|
+
import { p as poolWorker } from './pool-worker-0d927e3c.js';
|
|
4
|
+
import { m as machineWorker } from './machine-worker-421324a1.js';
|
|
5
|
+
import './worker-def77c26.js';
|
|
6
6
|
import 'stream';
|
|
7
7
|
import 'events';
|
|
8
8
|
import 'buffer';
|
|
@@ -11,9 +11,8 @@ import 'string_decoder/';
|
|
|
11
11
|
import 'fs';
|
|
12
12
|
import 'path';
|
|
13
13
|
import 'os';
|
|
14
|
-
import './transaction-
|
|
15
|
-
import './utils-
|
|
16
|
-
import 'child_process';
|
|
14
|
+
import './transaction-cec98ce8.js';
|
|
15
|
+
import './utils-ac8c68e6.js';
|
|
17
16
|
|
|
18
17
|
const TransactionWorker = transactionWorker;
|
|
19
18
|
const BlockWorker = blockWorker;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@leofcoin/codec-format-interface');
|
|
4
|
+
var utils = require('./utils-1dc37f72.js');
|
|
5
|
+
var EasyWorker = require('@vandeurenglenn/easy-worker');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var EasyWorker__default = /*#__PURE__*/_interopDefaultLegacy(EasyWorker);
|
|
10
|
+
|
|
11
|
+
const worker = new EasyWorker__default["default"]();
|
|
12
|
+
|
|
13
|
+
globalThis.BigNumber = utils.BigNumber;
|
|
14
|
+
|
|
15
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
16
|
+
globalThis.contracts = {};
|
|
17
|
+
|
|
18
|
+
const run = async (blocks) => {
|
|
19
|
+
blocks = await Promise.all(blocks.map(block => new utils.BlockMessage(block)));
|
|
20
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
21
|
+
|
|
22
|
+
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
23
|
+
// todo: tx worker or nah?
|
|
24
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
25
|
+
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${utils.formatBytes(size)}`);
|
|
26
|
+
resolve(block);
|
|
27
|
+
})));
|
|
28
|
+
return blocks
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const tasks = async blocks => {
|
|
32
|
+
globalThis.peernet.codecs = {
|
|
33
|
+
'block-message': {
|
|
34
|
+
codec: parseInt('626d', 16),
|
|
35
|
+
hashAlg: 'keccak-256'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
blocks = await run(blocks);
|
|
40
|
+
worker.postMessage(blocks);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
worker.onmessage(data => tasks(data));
|
|
45
|
+
|
|
46
|
+
var blockWorker = /*#__PURE__*/Object.freeze({
|
|
47
|
+
__proto__: null
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
exports.blockWorker = blockWorker;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('@leofcoin/codec-format-interface');
|
|
4
|
-
require('./
|
|
5
|
-
require('
|
|
6
|
-
require('
|
|
7
|
-
require('path');
|
|
4
|
+
require('./utils-1dc37f72.js');
|
|
5
|
+
require('@vandeurenglenn/easy-worker');
|
|
6
|
+
require('./block-worker-60e4cfa3.js');
|
|
8
7
|
require('bn.js');
|
|
9
8
|
require('@ethersproject/bytes');
|
|
10
9
|
require('@ethersproject/logger');
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
-
var utils = require('./utils-
|
|
5
|
-
var child_process = require('child_process');
|
|
4
|
+
var utils = require('./utils-1dc37f72.js');
|
|
6
5
|
var path = require('path');
|
|
6
|
+
var EasyWorker = require('@vandeurenglenn/easy-worker');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var EasyWorker__default = /*#__PURE__*/_interopDefaultLegacy(EasyWorker);
|
|
7
11
|
|
|
8
12
|
var proto = `
|
|
9
13
|
message ContractMessage {
|
|
@@ -38,6 +42,8 @@ var bytecodes = {
|
|
|
38
42
|
validators: validators
|
|
39
43
|
};
|
|
40
44
|
|
|
45
|
+
const worker = new EasyWorker__default["default"]();
|
|
46
|
+
|
|
41
47
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
42
48
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
43
49
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -94,7 +100,6 @@ const execute = async (contract, method, params) => {
|
|
|
94
100
|
} else {
|
|
95
101
|
result = await contracts[contract][method](...params);
|
|
96
102
|
}
|
|
97
|
-
|
|
98
103
|
// state.put(result)
|
|
99
104
|
return result
|
|
100
105
|
} catch (e) {
|
|
@@ -142,19 +147,29 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
142
147
|
return contract
|
|
143
148
|
}));
|
|
144
149
|
|
|
145
|
-
const
|
|
150
|
+
const _worker = new EasyWorker__default["default"](path.join(__dirname, './block-worker.js'), {serialization: 'advanced'});
|
|
146
151
|
// worker.on('message')
|
|
147
|
-
|
|
152
|
+
_worker.once('message', async (blocks) => {
|
|
148
153
|
for (const block of blocks) {
|
|
149
154
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
150
|
-
const {from, to, method, params} = message
|
|
155
|
+
const {from, to, method, params} = message;
|
|
151
156
|
globalThis.msg = createMessage(from);
|
|
152
157
|
|
|
153
158
|
await execute(to, method, params);
|
|
154
159
|
}));
|
|
155
160
|
}
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
let lastBlock;
|
|
162
|
+
if (blocks.length > 0) {
|
|
163
|
+
lastBlock = blocks[blocks.length - 1].decoded;
|
|
164
|
+
|
|
165
|
+
lastBlock = await new utils.BlockMessage(lastBlock);
|
|
166
|
+
lastBlock = {
|
|
167
|
+
...lastBlock.decoded,
|
|
168
|
+
hash: await lastBlock.hash
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
worker.postMessage({type: 'machine-ready', lastBlock });
|
|
172
|
+
_worker.terminate();
|
|
158
173
|
|
|
159
174
|
|
|
160
175
|
|
|
@@ -167,7 +182,7 @@ const tasks = async (e) => {
|
|
|
167
182
|
if (e.type === 'init') await _init(e.input);
|
|
168
183
|
if (e.type === 'get') {
|
|
169
184
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
170
|
-
|
|
185
|
+
worker.postMessage({
|
|
171
186
|
type: 'response',
|
|
172
187
|
id,
|
|
173
188
|
value
|
|
@@ -176,13 +191,13 @@ const tasks = async (e) => {
|
|
|
176
191
|
if (e.type === 'execute') {
|
|
177
192
|
try {
|
|
178
193
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
179
|
-
|
|
194
|
+
worker.postMessage({
|
|
180
195
|
type: 'response',
|
|
181
196
|
id,
|
|
182
197
|
value
|
|
183
198
|
});
|
|
184
199
|
} catch(e) {
|
|
185
|
-
|
|
200
|
+
worker.postMessage({
|
|
186
201
|
type: 'executionError',
|
|
187
202
|
message: e.message,
|
|
188
203
|
id
|
|
@@ -192,12 +207,7 @@ const tasks = async (e) => {
|
|
|
192
207
|
}
|
|
193
208
|
};
|
|
194
209
|
|
|
195
|
-
|
|
196
|
-
if (globalThis.process) {
|
|
197
|
-
process.on('message', tasks);
|
|
198
|
-
} else {
|
|
199
|
-
onmessage = message => tasks(message.data);
|
|
200
|
-
}
|
|
210
|
+
worker.onmessage(data => tasks(data));
|
|
201
211
|
|
|
202
212
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
203
213
|
__proto__: null
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./machine-worker-
|
|
3
|
+
require('./machine-worker-696e3b91.js');
|
|
4
4
|
require('@leofcoin/codec-format-interface');
|
|
5
|
-
require('./utils-
|
|
6
|
-
require('child_process');
|
|
5
|
+
require('./utils-1dc37f72.js');
|
|
7
6
|
require('path');
|
|
7
|
+
require('@vandeurenglenn/easy-worker');
|
|
8
8
|
require('bn.js');
|
|
9
9
|
require('@ethersproject/bytes');
|
|
10
10
|
require('@ethersproject/logger');
|
|
@@ -2,24 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
require('@leofcoin/codec-format-interface');
|
|
4
4
|
var transaction = require('./transaction-220a3a15.js');
|
|
5
|
+
var EasyWorker = require('@vandeurenglenn/easy-worker');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var EasyWorker__default = /*#__PURE__*/_interopDefaultLegacy(EasyWorker);
|
|
5
10
|
|
|
6
11
|
globalThis.peernet = globalThis.peernet || {};
|
|
7
12
|
globalThis.contracts = {};
|
|
8
13
|
|
|
14
|
+
const worker = new EasyWorker__default["default"]();
|
|
15
|
+
|
|
9
16
|
const tasks = async transactions => {
|
|
10
17
|
|
|
11
18
|
globalThis.peernet.codecs = {
|
|
12
|
-
'contract-message': {
|
|
13
|
-
codec: parseInt('63636d', 16),
|
|
14
|
-
hashAlg: 'keccak-256'
|
|
15
|
-
},
|
|
16
19
|
'transaction-message': {
|
|
17
20
|
codec: parseInt('746d', 16),
|
|
18
21
|
hashAlg: 'keccak-256'
|
|
19
|
-
},
|
|
20
|
-
'block-message': {
|
|
21
|
-
codec: parseInt('626d', 16),
|
|
22
|
-
hashAlg: 'keccak-256'
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
24
|
|
|
@@ -29,15 +28,10 @@ const tasks = async transactions => {
|
|
|
29
28
|
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
30
29
|
}));
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
worker.postMessage(transactions);
|
|
33
32
|
|
|
34
33
|
};
|
|
35
|
-
|
|
36
|
-
if (globalThis.process) {
|
|
37
|
-
process.on('message', tasks);
|
|
38
|
-
} else {
|
|
39
|
-
onmessage = message => tasks(message.data);
|
|
40
|
-
}
|
|
34
|
+
worker.onmessage(data => tasks(data));
|
|
41
35
|
|
|
42
36
|
var poolWorker = /*#__PURE__*/Object.freeze({
|
|
43
37
|
__proto__: null
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@leofcoin/codec-format-interface');
|
|
4
|
+
var transaction = require('./transaction-220a3a15.js');
|
|
5
|
+
var EasyWorker = require('@vandeurenglenn/easy-worker');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var EasyWorker__default = /*#__PURE__*/_interopDefaultLegacy(EasyWorker);
|
|
10
|
+
|
|
11
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
12
|
+
globalThis.contracts = {};
|
|
13
|
+
|
|
14
|
+
const worker = new EasyWorker__default["default"]();
|
|
15
|
+
|
|
16
|
+
worker.onmessage(async (transactions) => {
|
|
17
|
+
globalThis.peernet.codecs = {
|
|
18
|
+
'transaction-message': {
|
|
19
|
+
codec: parseInt('746d', 16),
|
|
20
|
+
hashAlg: 'keccak-256'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
transactions = await Promise.all(transactions.map(async message => new transaction.TransactionMessage(message)));
|
|
24
|
+
|
|
25
|
+
worker.postMessage(transactions);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
var transactionWorker = /*#__PURE__*/Object.freeze({
|
|
29
|
+
__proto__: null
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
exports.transactionWorker = transactionWorker;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
3
4
|
var _BN = require('bn.js');
|
|
4
5
|
var bytes = require('@ethersproject/bytes');
|
|
5
6
|
var logger$1 = require('@ethersproject/logger');
|
|
@@ -9,6 +10,48 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
10
|
|
|
10
11
|
var _BN__default = /*#__PURE__*/_interopDefaultLegacy(_BN);
|
|
11
12
|
|
|
13
|
+
var proto = `
|
|
14
|
+
message ValidatorMessage {
|
|
15
|
+
required string address = 1;
|
|
16
|
+
required string reward = 2;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
message Transaction {
|
|
20
|
+
required string hash = 1;
|
|
21
|
+
required uint64 timestamp = 2;
|
|
22
|
+
required string from = 3;
|
|
23
|
+
required string to = 4;
|
|
24
|
+
required uint64 nonce = 5;
|
|
25
|
+
required string method = 6;
|
|
26
|
+
repeated string params = 7;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
message BlockMessage {
|
|
30
|
+
required uint64 index = 1;
|
|
31
|
+
required string previousHash = 3;
|
|
32
|
+
required uint64 timestamp = 4;
|
|
33
|
+
required uint64 reward = 5;
|
|
34
|
+
required string fees = 6;
|
|
35
|
+
repeated Transaction transactions = 7;
|
|
36
|
+
repeated ValidatorMessage validators = 8;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
class BlockMessage extends codecFormatInterface.FormatInterface {
|
|
41
|
+
get keys() {
|
|
42
|
+
return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get messageName() {
|
|
46
|
+
return 'BlockMessage'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
constructor(buffer) {
|
|
50
|
+
const name = 'block-message';
|
|
51
|
+
super(buffer, proto, {name});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
12
55
|
const version$1 = "bignumber/5.6.2";
|
|
13
56
|
|
|
14
57
|
var BN = _BN__default["default"].BN;
|
|
@@ -305,4 +348,5 @@ const formatBytes = (bytes, decimals = 2) => {
|
|
|
305
348
|
};
|
|
306
349
|
|
|
307
350
|
exports.BigNumber = BigNumber;
|
|
351
|
+
exports.BlockMessage = BlockMessage;
|
|
308
352
|
exports.formatBytes = formatBytes;
|
package/dist/commonjs/workers.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
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-
|
|
5
|
+
var transactionWorker = require('./transaction-worker-8eecc7a1.js');
|
|
6
|
+
var blockWorker = require('./block-worker-60e4cfa3.js');
|
|
7
|
+
var poolWorker = require('./pool-worker-81e8b4c0.js');
|
|
8
|
+
var machineWorker = require('./machine-worker-696e3b91.js');
|
|
9
9
|
require('@leofcoin/codec-format-interface');
|
|
10
10
|
require('./transaction-220a3a15.js');
|
|
11
|
-
require('
|
|
11
|
+
require('@vandeurenglenn/easy-worker');
|
|
12
|
+
require('./utils-1dc37f72.js');
|
|
12
13
|
require('bn.js');
|
|
13
14
|
require('@ethersproject/bytes');
|
|
14
15
|
require('@ethersproject/logger');
|
|
15
16
|
require('@ethersproject/bignumber');
|
|
16
|
-
require('child_process');
|
|
17
17
|
require('path');
|
|
18
18
|
|
|
19
19
|
const TransactionWorker = transactionWorker.transactionWorker;
|