@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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { F as FormatInterface_1 } from './
|
|
2
|
-
import { B as BigNumber, f as formatBytes } from './utils-
|
|
3
|
-
import {
|
|
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';
|
|
3
|
+
import { join } from 'path';
|
|
4
4
|
|
|
5
5
|
var proto = `
|
|
6
6
|
message ContractMessage {
|
|
@@ -35,6 +35,8 @@ var bytecodes = {
|
|
|
35
35
|
validators: validators
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
const worker = new EasyWorker();
|
|
39
|
+
|
|
38
40
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
39
41
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
40
42
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -45,6 +47,7 @@ globalThis.BigNumber = BigNumber;
|
|
|
45
47
|
globalThis.peernet = globalThis.peernet || {};
|
|
46
48
|
globalThis.contracts = {};
|
|
47
49
|
|
|
50
|
+
|
|
48
51
|
const get = (contract, method, params) => {
|
|
49
52
|
let result;
|
|
50
53
|
if (params?.length > 0) {
|
|
@@ -90,7 +93,6 @@ const execute = async (contract, method, params) => {
|
|
|
90
93
|
} else {
|
|
91
94
|
result = await contracts[contract][method](...params);
|
|
92
95
|
}
|
|
93
|
-
|
|
94
96
|
// state.put(result)
|
|
95
97
|
return result
|
|
96
98
|
} catch (e) {
|
|
@@ -108,6 +110,22 @@ const createMessage = (sender = globalThis.peerid) => {
|
|
|
108
110
|
};
|
|
109
111
|
|
|
110
112
|
const _init = async ({ contracts, blocks, peerid })=> {
|
|
113
|
+
|
|
114
|
+
globalThis.peernet.codecs = {
|
|
115
|
+
'contract-message': {
|
|
116
|
+
codec: parseInt('63636d', 16),
|
|
117
|
+
hashAlg: 'keccak-256'
|
|
118
|
+
},
|
|
119
|
+
'transaction-message': {
|
|
120
|
+
codec: parseInt('746d', 16),
|
|
121
|
+
hashAlg: 'keccak-256'
|
|
122
|
+
},
|
|
123
|
+
'block-message': {
|
|
124
|
+
codec: parseInt('626d', 16),
|
|
125
|
+
hashAlg: 'keccak-256'
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
111
129
|
globalThis.peerid = peerid;
|
|
112
130
|
contracts = [
|
|
113
131
|
contractFactoryMessage,
|
|
@@ -122,19 +140,29 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
122
140
|
return contract
|
|
123
141
|
}));
|
|
124
142
|
|
|
125
|
-
const
|
|
143
|
+
const _worker = new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced'});
|
|
126
144
|
// worker.on('message')
|
|
127
|
-
|
|
145
|
+
_worker.once('message', async (blocks) => {
|
|
128
146
|
for (const block of blocks) {
|
|
129
147
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
130
|
-
const {from, to, method, params} = message
|
|
148
|
+
const {from, to, method, params} = message;
|
|
131
149
|
globalThis.msg = createMessage(from);
|
|
132
150
|
|
|
133
151
|
await execute(to, method, params);
|
|
134
152
|
}));
|
|
135
153
|
}
|
|
136
|
-
|
|
137
|
-
|
|
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();
|
|
138
166
|
|
|
139
167
|
|
|
140
168
|
|
|
@@ -143,54 +171,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
143
171
|
};
|
|
144
172
|
|
|
145
173
|
const tasks = async (e) => {
|
|
146
|
-
|
|
147
|
-
'contract-message': {
|
|
148
|
-
codec: parseInt('63636d', 16),
|
|
149
|
-
hashAlg: 'keccak-256'
|
|
150
|
-
},
|
|
151
|
-
'transaction-message': {
|
|
152
|
-
codec: parseInt('746d', 16),
|
|
153
|
-
hashAlg: 'keccak-256'
|
|
154
|
-
},
|
|
155
|
-
'block-message': {
|
|
156
|
-
codec: parseInt('626d', 16),
|
|
157
|
-
hashAlg: 'keccak-256'
|
|
158
|
-
}
|
|
159
|
-
};
|
|
174
|
+
const id = e.id;
|
|
160
175
|
if (e.type === 'init') await _init(e.input);
|
|
161
176
|
if (e.type === 'get') {
|
|
162
177
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
163
|
-
|
|
178
|
+
worker.postMessage({
|
|
164
179
|
type: 'response',
|
|
165
|
-
id
|
|
180
|
+
id,
|
|
166
181
|
value
|
|
167
182
|
});
|
|
168
183
|
}
|
|
169
184
|
if (e.type === 'execute') {
|
|
170
185
|
try {
|
|
171
186
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
172
|
-
|
|
187
|
+
worker.postMessage({
|
|
173
188
|
type: 'response',
|
|
174
|
-
id
|
|
189
|
+
id,
|
|
175
190
|
value
|
|
176
191
|
});
|
|
177
192
|
} catch(e) {
|
|
178
|
-
|
|
193
|
+
worker.postMessage({
|
|
179
194
|
type: 'executionError',
|
|
180
|
-
message: e,
|
|
181
|
-
id
|
|
195
|
+
message: e.message,
|
|
196
|
+
id
|
|
182
197
|
|
|
183
198
|
});
|
|
184
199
|
}
|
|
185
200
|
}
|
|
186
201
|
};
|
|
187
202
|
|
|
188
|
-
|
|
189
|
-
if (globalThis.process) {
|
|
190
|
-
process.on('message', tasks);
|
|
191
|
-
} else {
|
|
192
|
-
onmessage = message => tasks(message.data);
|
|
193
|
-
}
|
|
203
|
+
worker.onmessage(data => tasks(data));
|
|
194
204
|
|
|
195
205
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
196
206
|
__proto__: null
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import './machine-worker-
|
|
2
|
-
import './
|
|
3
|
-
import './utils-
|
|
4
|
-
import '
|
|
1
|
+
import './machine-worker-421324a1.js';
|
|
2
|
+
import './worker-def77c26.js';
|
|
3
|
+
import './utils-ac8c68e6.js';
|
|
4
|
+
import 'path';
|
|
5
5
|
import 'stream';
|
|
6
6
|
import 'events';
|
|
7
7
|
import 'buffer';
|
|
8
8
|
import 'util';
|
|
9
9
|
import 'string_decoder/';
|
|
10
10
|
import 'fs';
|
|
11
|
-
import 'path';
|
|
12
11
|
import 'os';
|
|
@@ -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,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('@leofcoin/codec-format-interface');
|
|
4
|
-
require('./
|
|
5
|
-
require('
|
|
6
|
-
require('
|
|
4
|
+
require('./utils-1dc37f72.js');
|
|
5
|
+
require('@vandeurenglenn/easy-worker');
|
|
6
|
+
require('./block-worker-60e4cfa3.js');
|
|
7
7
|
require('bn.js');
|
|
8
8
|
require('@ethersproject/bytes');
|
|
9
9
|
require('@ethersproject/logger');
|
package/dist/{bundle/commonjs/machine-worker-b376daef.js → commonjs/machine-worker-696e3b91.js}
RENAMED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var utils = require('./utils-
|
|
5
|
-
var
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
+
var utils = require('./utils-1dc37f72.js');
|
|
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);
|
|
6
11
|
|
|
7
12
|
var proto = `
|
|
8
13
|
message ContractMessage {
|
|
@@ -12,7 +17,7 @@ message ContractMessage {
|
|
|
12
17
|
}
|
|
13
18
|
`;
|
|
14
19
|
|
|
15
|
-
class ContractMessage extends
|
|
20
|
+
class ContractMessage extends codecFormatInterface.FormatInterface {
|
|
16
21
|
get keys() {
|
|
17
22
|
return ['creator', 'contract', 'constructorParameters']
|
|
18
23
|
}
|
|
@@ -37,6 +42,8 @@ var bytecodes = {
|
|
|
37
42
|
validators: validators
|
|
38
43
|
};
|
|
39
44
|
|
|
45
|
+
const worker = new EasyWorker__default["default"]();
|
|
46
|
+
|
|
40
47
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
41
48
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
42
49
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -47,6 +54,7 @@ globalThis.BigNumber = utils.BigNumber;
|
|
|
47
54
|
globalThis.peernet = globalThis.peernet || {};
|
|
48
55
|
globalThis.contracts = {};
|
|
49
56
|
|
|
57
|
+
|
|
50
58
|
const get = (contract, method, params) => {
|
|
51
59
|
let result;
|
|
52
60
|
if (params?.length > 0) {
|
|
@@ -92,7 +100,6 @@ const execute = async (contract, method, params) => {
|
|
|
92
100
|
} else {
|
|
93
101
|
result = await contracts[contract][method](...params);
|
|
94
102
|
}
|
|
95
|
-
|
|
96
103
|
// state.put(result)
|
|
97
104
|
return result
|
|
98
105
|
} catch (e) {
|
|
@@ -110,6 +117,22 @@ const createMessage = (sender = globalThis.peerid) => {
|
|
|
110
117
|
};
|
|
111
118
|
|
|
112
119
|
const _init = async ({ contracts, blocks, peerid })=> {
|
|
120
|
+
|
|
121
|
+
globalThis.peernet.codecs = {
|
|
122
|
+
'contract-message': {
|
|
123
|
+
codec: parseInt('63636d', 16),
|
|
124
|
+
hashAlg: 'keccak-256'
|
|
125
|
+
},
|
|
126
|
+
'transaction-message': {
|
|
127
|
+
codec: parseInt('746d', 16),
|
|
128
|
+
hashAlg: 'keccak-256'
|
|
129
|
+
},
|
|
130
|
+
'block-message': {
|
|
131
|
+
codec: parseInt('626d', 16),
|
|
132
|
+
hashAlg: 'keccak-256'
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
113
136
|
globalThis.peerid = peerid;
|
|
114
137
|
contracts = [
|
|
115
138
|
contractFactoryMessage,
|
|
@@ -124,19 +147,29 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
124
147
|
return contract
|
|
125
148
|
}));
|
|
126
149
|
|
|
127
|
-
const
|
|
150
|
+
const _worker = new EasyWorker__default["default"](path.join(__dirname, './block-worker.js'), {serialization: 'advanced'});
|
|
128
151
|
// worker.on('message')
|
|
129
|
-
|
|
152
|
+
_worker.once('message', async (blocks) => {
|
|
130
153
|
for (const block of blocks) {
|
|
131
154
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
132
|
-
const {from, to, method, params} = message
|
|
155
|
+
const {from, to, method, params} = message;
|
|
133
156
|
globalThis.msg = createMessage(from);
|
|
134
157
|
|
|
135
158
|
await execute(to, method, params);
|
|
136
159
|
}));
|
|
137
160
|
}
|
|
138
|
-
|
|
139
|
-
|
|
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();
|
|
140
173
|
|
|
141
174
|
|
|
142
175
|
|
|
@@ -145,54 +178,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
145
178
|
};
|
|
146
179
|
|
|
147
180
|
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
|
-
};
|
|
181
|
+
const id = e.id;
|
|
162
182
|
if (e.type === 'init') await _init(e.input);
|
|
163
183
|
if (e.type === 'get') {
|
|
164
184
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
165
|
-
|
|
185
|
+
worker.postMessage({
|
|
166
186
|
type: 'response',
|
|
167
|
-
id
|
|
187
|
+
id,
|
|
168
188
|
value
|
|
169
189
|
});
|
|
170
190
|
}
|
|
171
191
|
if (e.type === 'execute') {
|
|
172
192
|
try {
|
|
173
193
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
174
|
-
|
|
194
|
+
worker.postMessage({
|
|
175
195
|
type: 'response',
|
|
176
|
-
id
|
|
196
|
+
id,
|
|
177
197
|
value
|
|
178
198
|
});
|
|
179
199
|
} catch(e) {
|
|
180
|
-
|
|
200
|
+
worker.postMessage({
|
|
181
201
|
type: 'executionError',
|
|
182
|
-
message: e,
|
|
183
|
-
id
|
|
202
|
+
message: e.message,
|
|
203
|
+
id
|
|
184
204
|
|
|
185
205
|
});
|
|
186
206
|
}
|
|
187
207
|
}
|
|
188
208
|
};
|
|
189
209
|
|
|
190
|
-
|
|
191
|
-
if (globalThis.process) {
|
|
192
|
-
process.on('message', tasks);
|
|
193
|
-
} else {
|
|
194
|
-
onmessage = message => tasks(message.data);
|
|
195
|
-
}
|
|
210
|
+
worker.onmessage(data => tasks(data));
|
|
196
211
|
|
|
197
212
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
198
213
|
__proto__: null
|
|
@@ -1,9 +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('
|
|
5
|
+
require('./utils-1dc37f72.js');
|
|
6
|
+
require('path');
|
|
7
|
+
require('@vandeurenglenn/easy-worker');
|
|
7
8
|
require('bn.js');
|
|
8
9
|
require('@ethersproject/bytes');
|
|
9
10
|
require('@ethersproject/logger');
|