@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
|
@@ -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,19 @@
|
|
|
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('
|
|
17
|
+
require('path');
|
|
17
18
|
|
|
18
19
|
const TransactionWorker = transactionWorker.transactionWorker;
|
|
19
20
|
const BlockWorker = blockWorker.blockWorker;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import '@leofcoin/codec-format-interface';
|
|
2
|
+
import { B as BigNumber, a as BlockMessage, f as formatBytes } from './utils-e87bc63d.js';
|
|
3
|
+
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
4
|
+
|
|
5
|
+
const worker = new EasyWorker();
|
|
6
|
+
|
|
7
|
+
globalThis.BigNumber = BigNumber;
|
|
8
|
+
|
|
9
|
+
globalThis.peernet = globalThis.peernet || {};
|
|
10
|
+
globalThis.contracts = {};
|
|
11
|
+
|
|
12
|
+
const run = async (blocks) => {
|
|
13
|
+
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
14
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
15
|
+
|
|
16
|
+
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
17
|
+
// todo: tx worker or nah?
|
|
18
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
19
|
+
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
20
|
+
resolve(block);
|
|
21
|
+
})));
|
|
22
|
+
return blocks
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const tasks = async blocks => {
|
|
26
|
+
globalThis.peernet.codecs = {
|
|
27
|
+
'block-message': {
|
|
28
|
+
codec: parseInt('626d', 16),
|
|
29
|
+
hashAlg: 'keccak-256'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
blocks = await run(blocks);
|
|
34
|
+
worker.postMessage(blocks);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
worker.onmessage(data => tasks(data));
|
|
39
|
+
|
|
40
|
+
var blockWorker = /*#__PURE__*/Object.freeze({
|
|
41
|
+
__proto__: null
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export { blockWorker as b };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '@leofcoin/codec-format-interface';
|
|
2
|
-
import './
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
2
|
+
import './utils-e87bc63d.js';
|
|
3
|
+
import '@vandeurenglenn/easy-worker';
|
|
4
|
+
import './block-worker-f539b1b2.js';
|
|
5
5
|
import 'bn.js';
|
|
6
6
|
import '@ethersproject/bytes';
|
|
7
7
|
import '@ethersproject/logger';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FormatInterface } from '@leofcoin/codec-format-interface';
|
|
2
|
-
import { B as BigNumber, f as formatBytes } from './utils-
|
|
3
|
-
import {
|
|
2
|
+
import { B as BigNumber, a as BlockMessage, f as formatBytes } from './utils-e87bc63d.js';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
4
5
|
|
|
5
6
|
var proto = `
|
|
6
7
|
message ContractMessage {
|
|
@@ -35,6 +36,8 @@ var bytecodes = {
|
|
|
35
36
|
validators: validators
|
|
36
37
|
};
|
|
37
38
|
|
|
39
|
+
const worker = new EasyWorker();
|
|
40
|
+
|
|
38
41
|
const contractFactoryMessage = bytecodes.contractFactory;
|
|
39
42
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
40
43
|
const nameServiceMessage = bytecodes.nameService;
|
|
@@ -45,6 +48,7 @@ globalThis.BigNumber = BigNumber;
|
|
|
45
48
|
globalThis.peernet = globalThis.peernet || {};
|
|
46
49
|
globalThis.contracts = {};
|
|
47
50
|
|
|
51
|
+
|
|
48
52
|
const get = (contract, method, params) => {
|
|
49
53
|
let result;
|
|
50
54
|
if (params?.length > 0) {
|
|
@@ -90,7 +94,6 @@ const execute = async (contract, method, params) => {
|
|
|
90
94
|
} else {
|
|
91
95
|
result = await contracts[contract][method](...params);
|
|
92
96
|
}
|
|
93
|
-
|
|
94
97
|
// state.put(result)
|
|
95
98
|
return result
|
|
96
99
|
} catch (e) {
|
|
@@ -108,6 +111,22 @@ const createMessage = (sender = globalThis.peerid) => {
|
|
|
108
111
|
};
|
|
109
112
|
|
|
110
113
|
const _init = async ({ contracts, blocks, peerid })=> {
|
|
114
|
+
|
|
115
|
+
globalThis.peernet.codecs = {
|
|
116
|
+
'contract-message': {
|
|
117
|
+
codec: parseInt('63636d', 16),
|
|
118
|
+
hashAlg: 'keccak-256'
|
|
119
|
+
},
|
|
120
|
+
'transaction-message': {
|
|
121
|
+
codec: parseInt('746d', 16),
|
|
122
|
+
hashAlg: 'keccak-256'
|
|
123
|
+
},
|
|
124
|
+
'block-message': {
|
|
125
|
+
codec: parseInt('626d', 16),
|
|
126
|
+
hashAlg: 'keccak-256'
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
111
130
|
globalThis.peerid = peerid;
|
|
112
131
|
contracts = [
|
|
113
132
|
contractFactoryMessage,
|
|
@@ -122,19 +141,29 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
122
141
|
return contract
|
|
123
142
|
}));
|
|
124
143
|
|
|
125
|
-
const
|
|
144
|
+
const _worker = new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced'});
|
|
126
145
|
// worker.on('message')
|
|
127
|
-
|
|
146
|
+
_worker.once('message', async (blocks) => {
|
|
128
147
|
for (const block of blocks) {
|
|
129
148
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
130
|
-
const {from, to, method, params} = message
|
|
149
|
+
const {from, to, method, params} = message;
|
|
131
150
|
globalThis.msg = createMessage(from);
|
|
132
151
|
|
|
133
152
|
await execute(to, method, params);
|
|
134
153
|
}));
|
|
135
154
|
}
|
|
136
|
-
|
|
137
|
-
|
|
155
|
+
let lastBlock;
|
|
156
|
+
if (blocks.length > 0) {
|
|
157
|
+
lastBlock = blocks[blocks.length - 1].decoded;
|
|
158
|
+
|
|
159
|
+
lastBlock = await new BlockMessage(lastBlock);
|
|
160
|
+
lastBlock = {
|
|
161
|
+
...lastBlock.decoded,
|
|
162
|
+
hash: await lastBlock.hash
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
worker.postMessage({type: 'machine-ready', lastBlock });
|
|
166
|
+
_worker.terminate();
|
|
138
167
|
|
|
139
168
|
|
|
140
169
|
|
|
@@ -143,54 +172,36 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
143
172
|
};
|
|
144
173
|
|
|
145
174
|
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
|
-
};
|
|
175
|
+
const id = e.id;
|
|
160
176
|
if (e.type === 'init') await _init(e.input);
|
|
161
177
|
if (e.type === 'get') {
|
|
162
178
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
163
|
-
|
|
179
|
+
worker.postMessage({
|
|
164
180
|
type: 'response',
|
|
165
|
-
id
|
|
181
|
+
id,
|
|
166
182
|
value
|
|
167
183
|
});
|
|
168
184
|
}
|
|
169
185
|
if (e.type === 'execute') {
|
|
170
186
|
try {
|
|
171
187
|
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
172
|
-
|
|
188
|
+
worker.postMessage({
|
|
173
189
|
type: 'response',
|
|
174
|
-
id
|
|
190
|
+
id,
|
|
175
191
|
value
|
|
176
192
|
});
|
|
177
193
|
} catch(e) {
|
|
178
|
-
|
|
194
|
+
worker.postMessage({
|
|
179
195
|
type: 'executionError',
|
|
180
|
-
message: e,
|
|
181
|
-
id
|
|
196
|
+
message: e.message,
|
|
197
|
+
id
|
|
182
198
|
|
|
183
199
|
});
|
|
184
200
|
}
|
|
185
201
|
}
|
|
186
202
|
};
|
|
187
203
|
|
|
188
|
-
|
|
189
|
-
if (globalThis.process) {
|
|
190
|
-
process.on('message', tasks);
|
|
191
|
-
} else {
|
|
192
|
-
onmessage = message => tasks(message.data);
|
|
193
|
-
}
|
|
204
|
+
worker.onmessage(data => tasks(data));
|
|
194
205
|
|
|
195
206
|
var machineWorker = /*#__PURE__*/Object.freeze({
|
|
196
207
|
__proto__: null
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import './machine-worker-
|
|
1
|
+
import './machine-worker-e7d98549.js';
|
|
2
2
|
import '@leofcoin/codec-format-interface';
|
|
3
|
-
import './utils-
|
|
4
|
-
import '
|
|
3
|
+
import './utils-e87bc63d.js';
|
|
4
|
+
import 'path';
|
|
5
|
+
import '@vandeurenglenn/easy-worker';
|
|
5
6
|
import 'bn.js';
|
|
6
7
|
import '@ethersproject/bytes';
|
|
7
8
|
import '@ethersproject/logger';
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import '@leofcoin/codec-format-interface';
|
|
2
2
|
import { T as TransactionMessage } from './transaction-d06dc6c4.js';
|
|
3
|
+
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
3
4
|
|
|
4
5
|
globalThis.peernet = globalThis.peernet || {};
|
|
5
6
|
globalThis.contracts = {};
|
|
6
7
|
|
|
8
|
+
const worker = new EasyWorker();
|
|
9
|
+
|
|
7
10
|
const tasks = async transactions => {
|
|
8
11
|
|
|
9
12
|
globalThis.peernet.codecs = {
|
|
10
|
-
'contract-message': {
|
|
11
|
-
codec: parseInt('63636d', 16),
|
|
12
|
-
hashAlg: 'keccak-256'
|
|
13
|
-
},
|
|
14
13
|
'transaction-message': {
|
|
15
14
|
codec: parseInt('746d', 16),
|
|
16
15
|
hashAlg: 'keccak-256'
|
|
17
|
-
},
|
|
18
|
-
'block-message': {
|
|
19
|
-
codec: parseInt('626d', 16),
|
|
20
|
-
hashAlg: 'keccak-256'
|
|
21
16
|
}
|
|
22
17
|
};
|
|
23
18
|
|
|
@@ -27,15 +22,10 @@ const tasks = async transactions => {
|
|
|
27
22
|
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
28
23
|
}));
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
worker.postMessage(transactions);
|
|
31
26
|
|
|
32
27
|
};
|
|
33
|
-
|
|
34
|
-
if (globalThis.process) {
|
|
35
|
-
process.on('message', tasks);
|
|
36
|
-
} else {
|
|
37
|
-
onmessage = message => tasks(message.data);
|
|
38
|
-
}
|
|
28
|
+
worker.onmessage(data => tasks(data));
|
|
39
29
|
|
|
40
30
|
var poolWorker = /*#__PURE__*/Object.freeze({
|
|
41
31
|
__proto__: null
|
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import '@leofcoin/codec-format-interface';
|
|
2
2
|
import { T as TransactionMessage } from './transaction-d06dc6c4.js';
|
|
3
|
+
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
3
4
|
|
|
4
5
|
globalThis.peernet = globalThis.peernet || {};
|
|
5
6
|
globalThis.contracts = {};
|
|
6
|
-
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
hashAlg: 'keccak-256'
|
|
18
|
-
},
|
|
19
|
-
'block-message': {
|
|
20
|
-
codec: parseInt('626d', 16),
|
|
21
|
-
hashAlg: 'keccak-256'
|
|
22
|
-
}
|
|
23
|
-
};
|
|
8
|
+
const worker = new EasyWorker();
|
|
9
|
+
|
|
10
|
+
worker.onmessage(async (transactions) => {
|
|
11
|
+
globalThis.peernet.codecs = {
|
|
12
|
+
'transaction-message': {
|
|
13
|
+
codec: parseInt('746d', 16),
|
|
14
|
+
hashAlg: 'keccak-256'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
24
17
|
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)));
|
|
25
18
|
|
|
26
|
-
|
|
19
|
+
worker.postMessage(transactions);
|
|
27
20
|
});
|
|
28
21
|
|
|
29
22
|
var transactionWorker = /*#__PURE__*/Object.freeze({
|
|
@@ -1,8 +1,51 @@
|
|
|
1
|
+
import { FormatInterface } from '@leofcoin/codec-format-interface';
|
|
1
2
|
import _BN from 'bn.js';
|
|
2
3
|
import { isBytes, hexlify, isHexString } from '@ethersproject/bytes';
|
|
3
4
|
import { Logger } from '@ethersproject/logger';
|
|
4
5
|
import '@ethersproject/bignumber';
|
|
5
6
|
|
|
7
|
+
var proto = `
|
|
8
|
+
message ValidatorMessage {
|
|
9
|
+
required string address = 1;
|
|
10
|
+
required string reward = 2;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
message Transaction {
|
|
14
|
+
required string hash = 1;
|
|
15
|
+
required uint64 timestamp = 2;
|
|
16
|
+
required string from = 3;
|
|
17
|
+
required string to = 4;
|
|
18
|
+
required uint64 nonce = 5;
|
|
19
|
+
required string method = 6;
|
|
20
|
+
repeated string params = 7;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
message BlockMessage {
|
|
24
|
+
required uint64 index = 1;
|
|
25
|
+
required string previousHash = 3;
|
|
26
|
+
required uint64 timestamp = 4;
|
|
27
|
+
required uint64 reward = 5;
|
|
28
|
+
required string fees = 6;
|
|
29
|
+
repeated Transaction transactions = 7;
|
|
30
|
+
repeated ValidatorMessage validators = 8;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
class BlockMessage extends FormatInterface {
|
|
35
|
+
get keys() {
|
|
36
|
+
return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get messageName() {
|
|
40
|
+
return 'BlockMessage'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
constructor(buffer) {
|
|
44
|
+
const name = 'block-message';
|
|
45
|
+
super(buffer, proto, {name});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
6
49
|
const version$1 = "bignumber/5.6.2";
|
|
7
50
|
|
|
8
51
|
var BN = _BN.BN;
|
|
@@ -298,4 +341,4 @@ const formatBytes = (bytes, decimals = 2) => {
|
|
|
298
341
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`
|
|
299
342
|
};
|
|
300
343
|
|
|
301
|
-
export { BigNumber as B, formatBytes as f };
|
|
344
|
+
export { BigNumber as B, BlockMessage as a, formatBytes as f };
|
package/dist/module/workers.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
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-
|
|
1
|
+
import { t as transactionWorker } from './transaction-worker-105deaa8.js';
|
|
2
|
+
import { b as blockWorker } from './block-worker-f539b1b2.js';
|
|
3
|
+
import { p as poolWorker } from './pool-worker-f65671d7.js';
|
|
4
|
+
import { m as machineWorker } from './machine-worker-e7d98549.js';
|
|
5
5
|
import '@leofcoin/codec-format-interface';
|
|
6
6
|
import './transaction-d06dc6c4.js';
|
|
7
|
-
import '
|
|
7
|
+
import '@vandeurenglenn/easy-worker';
|
|
8
|
+
import './utils-e87bc63d.js';
|
|
8
9
|
import 'bn.js';
|
|
9
10
|
import '@ethersproject/bytes';
|
|
10
11
|
import '@ethersproject/logger';
|
|
11
12
|
import '@ethersproject/bignumber';
|
|
12
|
-
import '
|
|
13
|
+
import 'path';
|
|
13
14
|
|
|
14
15
|
const TransactionWorker = transactionWorker;
|
|
15
16
|
const BlockWorker = blockWorker;
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@leofcoin/workers",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"module": "src/workers.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "rollup -c",
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
-
},
|
|
10
|
-
"keywords": [],
|
|
11
|
-
"author": "",
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@rollup/plugin-commonjs": "^22.0.2",
|
|
15
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
16
|
-
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
17
|
-
"rollup": "^2.79.1"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@leofcoin/messages": "^1.2.0"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@leofcoin/workers",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"module": "src/workers.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rollup -c",
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@rollup/plugin-commonjs": "^22.0.2",
|
|
15
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
16
|
+
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
17
|
+
"rollup": "^2.79.1"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@leofcoin/messages": "^1.2.0"
|
|
21
|
+
}
|
|
22
|
+
}
|