@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
package/src/block-worker.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { BlockMessage } from '
|
|
2
|
-
import { formatBytes, BigNumber } from '
|
|
3
|
-
import bytecodes from '../../lib/src/bytecodes.json'
|
|
4
|
-
import { fork } from 'child_process'
|
|
1
|
+
import { BlockMessage } from './../../messages/src/messages'
|
|
2
|
+
import { formatBytes, BigNumber } from './../../utils/src/utils'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const validatorsMessage = bytecodes.validators
|
|
4
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
+
|
|
6
|
+
const worker = new EasyWorker()
|
|
10
7
|
|
|
11
8
|
globalThis.BigNumber = BigNumber
|
|
12
9
|
|
|
@@ -18,42 +15,16 @@ const run = async (blocks) => {
|
|
|
18
15
|
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp)
|
|
19
16
|
|
|
20
17
|
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
block.decoded.transactions = transactions
|
|
26
|
-
const size = block.encoded.length || block.encoded.byteLength
|
|
27
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
28
|
-
resolve(block)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
worker.send(block.decoded.transactions)
|
|
32
|
-
} else {
|
|
33
|
-
const worker = new Worker('./workers/transaction-worker.js')
|
|
34
|
-
worker.onmessage = async message => {
|
|
35
|
-
const transactions = message.data
|
|
36
|
-
block.decoded.transactions = transactions
|
|
37
|
-
const size = block.encoded.length || block.encoded.byteLength
|
|
38
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
39
|
-
resolve(block)
|
|
40
|
-
}
|
|
41
|
-
worker.postMessage(block.decoded.transactions)
|
|
42
|
-
}
|
|
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} ${formatBytes(size)}`);
|
|
21
|
+
resolve(block)
|
|
43
22
|
})))
|
|
44
23
|
return blocks
|
|
45
24
|
}
|
|
46
25
|
|
|
47
26
|
const tasks = async blocks => {
|
|
48
27
|
globalThis.peernet.codecs = {
|
|
49
|
-
'contract-message': {
|
|
50
|
-
codec: parseInt('63636d', 16),
|
|
51
|
-
hashAlg: 'keccak-256'
|
|
52
|
-
},
|
|
53
|
-
'transaction-message': {
|
|
54
|
-
codec: parseInt('746d', 16),
|
|
55
|
-
hashAlg: 'keccak-256'
|
|
56
|
-
},
|
|
57
28
|
'block-message': {
|
|
58
29
|
codec: parseInt('626d', 16),
|
|
59
30
|
hashAlg: 'keccak-256'
|
|
@@ -61,11 +32,9 @@ const tasks = async blocks => {
|
|
|
61
32
|
}
|
|
62
33
|
|
|
63
34
|
blocks = await run(blocks)
|
|
64
|
-
|
|
35
|
+
worker.postMessage(blocks)
|
|
65
36
|
}
|
|
66
37
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
onmessage = message => tasks(message.data)
|
|
71
|
-
}
|
|
38
|
+
|
|
39
|
+
worker.onmessage(data => tasks(data))
|
|
40
|
+
|
package/src/machine-worker.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BlockMessage, ContractMessage, TransactionMessage } from './../../messages/src/messages'
|
|
2
2
|
import { formatBytes, BigNumber } from './../../utils/src/utils'
|
|
3
3
|
import bytecodes from './../../lib/src/bytecodes.json'
|
|
4
|
-
import {
|
|
4
|
+
import { join } from 'path'
|
|
5
|
+
|
|
6
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
7
|
+
const worker = new EasyWorker()
|
|
8
|
+
|
|
5
9
|
const contractFactoryMessage = bytecodes.contractFactory
|
|
6
10
|
const nativeTokenMessage = bytecodes.nativeToken
|
|
7
11
|
const nameServiceMessage = bytecodes.nameService
|
|
@@ -12,6 +16,7 @@ globalThis.BigNumber = BigNumber
|
|
|
12
16
|
globalThis.peernet = globalThis.peernet || {}
|
|
13
17
|
globalThis.contracts = {}
|
|
14
18
|
|
|
19
|
+
|
|
15
20
|
const get = (contract, method, params) => {
|
|
16
21
|
let result
|
|
17
22
|
if (params?.length > 0) {
|
|
@@ -57,7 +62,6 @@ const execute = async (contract, method, params) => {
|
|
|
57
62
|
} else {
|
|
58
63
|
result = await contracts[contract][method](...params)
|
|
59
64
|
}
|
|
60
|
-
|
|
61
65
|
// state.put(result)
|
|
62
66
|
return result
|
|
63
67
|
} catch (e) {
|
|
@@ -75,6 +79,22 @@ const createMessage = (sender = globalThis.peerid) => {
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
const _init = async ({ contracts, blocks, peerid })=> {
|
|
82
|
+
|
|
83
|
+
globalThis.peernet.codecs = {
|
|
84
|
+
'contract-message': {
|
|
85
|
+
codec: parseInt('63636d', 16),
|
|
86
|
+
hashAlg: 'keccak-256'
|
|
87
|
+
},
|
|
88
|
+
'transaction-message': {
|
|
89
|
+
codec: parseInt('746d', 16),
|
|
90
|
+
hashAlg: 'keccak-256'
|
|
91
|
+
},
|
|
92
|
+
'block-message': {
|
|
93
|
+
codec: parseInt('626d', 16),
|
|
94
|
+
hashAlg: 'keccak-256'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
78
98
|
globalThis.peerid = peerid
|
|
79
99
|
contracts = [
|
|
80
100
|
contractFactoryMessage,
|
|
@@ -89,19 +109,29 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
89
109
|
return contract
|
|
90
110
|
}))
|
|
91
111
|
|
|
92
|
-
const
|
|
112
|
+
const _worker = new EasyWorker(join(__dirname, './block-worker.js'), {serialization: 'advanced'})
|
|
93
113
|
// worker.on('message')
|
|
94
|
-
|
|
114
|
+
_worker.once('message', async (blocks) => {
|
|
95
115
|
for (const block of blocks) {
|
|
96
116
|
await Promise.all(block.decoded.transactions.map(async message => {
|
|
97
|
-
const {from, to, method, params} = message
|
|
117
|
+
const {from, to, method, params} = message
|
|
98
118
|
globalThis.msg = createMessage(from)
|
|
99
119
|
|
|
100
120
|
await execute(to, method, params)
|
|
101
121
|
}))
|
|
102
122
|
}
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
let lastBlock
|
|
124
|
+
if (blocks.length > 0) {
|
|
125
|
+
lastBlock = blocks[blocks.length - 1].decoded
|
|
126
|
+
|
|
127
|
+
lastBlock = await new BlockMessage(lastBlock)
|
|
128
|
+
lastBlock = {
|
|
129
|
+
...lastBlock.decoded,
|
|
130
|
+
hash: await lastBlock.hash
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
worker.postMessage({type: 'machine-ready', lastBlock })
|
|
134
|
+
_worker.terminate()
|
|
105
135
|
|
|
106
136
|
|
|
107
137
|
|
|
@@ -110,51 +140,33 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
110
140
|
}
|
|
111
141
|
|
|
112
142
|
const tasks = async (e) => {
|
|
113
|
-
|
|
114
|
-
'contract-message': {
|
|
115
|
-
codec: parseInt('63636d', 16),
|
|
116
|
-
hashAlg: 'keccak-256'
|
|
117
|
-
},
|
|
118
|
-
'transaction-message': {
|
|
119
|
-
codec: parseInt('746d', 16),
|
|
120
|
-
hashAlg: 'keccak-256'
|
|
121
|
-
},
|
|
122
|
-
'block-message': {
|
|
123
|
-
codec: parseInt('626d', 16),
|
|
124
|
-
hashAlg: 'keccak-256'
|
|
125
|
-
}
|
|
126
|
-
}
|
|
143
|
+
const id = e.id
|
|
127
144
|
if (e.type === 'init') await _init(e.input)
|
|
128
145
|
if (e.type === 'get') {
|
|
129
146
|
const value = await get(e.input.contract, e.input.method, e.input.params)
|
|
130
|
-
|
|
147
|
+
worker.postMessage({
|
|
131
148
|
type: 'response',
|
|
132
|
-
id
|
|
149
|
+
id,
|
|
133
150
|
value
|
|
134
151
|
})
|
|
135
152
|
}
|
|
136
153
|
if (e.type === 'execute') {
|
|
137
154
|
try {
|
|
138
155
|
const value = await execute(e.input.contract, e.input.method, e.input.params)
|
|
139
|
-
|
|
156
|
+
worker.postMessage({
|
|
140
157
|
type: 'response',
|
|
141
|
-
id
|
|
158
|
+
id,
|
|
142
159
|
value
|
|
143
160
|
})
|
|
144
161
|
} catch(e) {
|
|
145
|
-
|
|
162
|
+
worker.postMessage({
|
|
146
163
|
type: 'executionError',
|
|
147
|
-
message: e,
|
|
148
|
-
id
|
|
164
|
+
message: e.message,
|
|
165
|
+
id
|
|
149
166
|
|
|
150
167
|
})
|
|
151
168
|
}
|
|
152
169
|
}
|
|
153
170
|
}
|
|
154
171
|
|
|
155
|
-
|
|
156
|
-
if (globalThis.process) {
|
|
157
|
-
process.on('message', tasks)
|
|
158
|
-
} else {
|
|
159
|
-
onmessage = message => tasks(message.data)
|
|
160
|
-
}
|
|
172
|
+
worker.onmessage(data => tasks(data))
|
package/src/pool-worker.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { TransactionMessage } from '
|
|
1
|
+
import { TransactionMessage } from './../../messages/src/messages'
|
|
2
|
+
|
|
3
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
2
4
|
|
|
3
5
|
globalThis.peernet = globalThis.peernet || {}
|
|
4
6
|
globalThis.contracts = {}
|
|
5
7
|
|
|
8
|
+
const worker = new EasyWorker()
|
|
9
|
+
|
|
6
10
|
const tasks = async transactions => {
|
|
7
11
|
|
|
8
12
|
globalThis.peernet.codecs = {
|
|
9
|
-
'contract-message': {
|
|
10
|
-
codec: parseInt('63636d', 16),
|
|
11
|
-
hashAlg: 'keccak-256'
|
|
12
|
-
},
|
|
13
13
|
'transaction-message': {
|
|
14
14
|
codec: parseInt('746d', 16),
|
|
15
15
|
hashAlg: 'keccak-256'
|
|
16
|
-
},
|
|
17
|
-
'block-message': {
|
|
18
|
-
codec: parseInt('626d', 16),
|
|
19
|
-
hashAlg: 'keccak-256'
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
18
|
|
|
@@ -26,12 +22,7 @@ const tasks = async transactions => {
|
|
|
26
22
|
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
27
23
|
}))
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
worker.postMessage(transactions)
|
|
30
26
|
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
if (globalThis.process) {
|
|
34
|
-
process.on('message', tasks)
|
|
35
|
-
} else {
|
|
36
|
-
onmessage = message => tasks(message.data)
|
|
37
|
-
}
|
|
28
|
+
worker.onmessage(data => tasks(data))
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import { TransactionMessage } from '
|
|
1
|
+
import { TransactionMessage } from './../../messages/src/messages.js'
|
|
2
2
|
|
|
3
3
|
globalThis.peernet = globalThis.peernet || {}
|
|
4
4
|
globalThis.contracts = {}
|
|
5
|
-
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
'block-message': {
|
|
19
|
-
codec: parseInt('626d', 16),
|
|
20
|
-
hashAlg: 'keccak-256'
|
|
6
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
7
|
+
|
|
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
|
+
}
|
|
21
16
|
}
|
|
22
|
-
}
|
|
23
17
|
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)))
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
})
|
|
19
|
+
worker.postMessage(transactions)
|
|
20
|
+
})
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-f77ba3de.js');
|
|
4
|
-
var utils = require('./utils-6a02b156.js');
|
|
5
|
-
var child_process = require('child_process');
|
|
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 index.FormatInterface_1 {
|
|
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
|
-
|
|
49
|
-
globalThis.BigNumber = utils.BigNumber;
|
|
50
|
-
|
|
51
|
-
globalThis.peernet = globalThis.peernet || {};
|
|
52
|
-
globalThis.contracts = {};
|
|
53
|
-
|
|
54
|
-
const run = async (blocks) => {
|
|
55
|
-
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
56
|
-
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
57
|
-
|
|
58
|
-
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
59
|
-
if (globalThis.process) {
|
|
60
|
-
const worker = child_process.fork('./workers/transaction-worker.js', {serialization: 'advanced'});
|
|
61
|
-
|
|
62
|
-
worker.once('message', async transactions => {
|
|
63
|
-
block.decoded.transactions = transactions;
|
|
64
|
-
const size = block.encoded.length || block.encoded.byteLength;
|
|
65
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${utils.formatBytes(size)}`);
|
|
66
|
-
resolve(block);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
worker.send(block.decoded.transactions);
|
|
70
|
-
} else {
|
|
71
|
-
const worker = new Worker('./workers/transaction-worker.js');
|
|
72
|
-
worker.onmessage = async message => {
|
|
73
|
-
const transactions = message.data;
|
|
74
|
-
block.decoded.transactions = transactions;
|
|
75
|
-
const size = block.encoded.length || block.encoded.byteLength;
|
|
76
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${utils.formatBytes(size)}`);
|
|
77
|
-
resolve(block);
|
|
78
|
-
};
|
|
79
|
-
worker.postMessage(block.decoded.transactions);
|
|
80
|
-
}
|
|
81
|
-
})));
|
|
82
|
-
return blocks
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const tasks = async blocks => {
|
|
86
|
-
globalThis.peernet.codecs = {
|
|
87
|
-
'contract-message': {
|
|
88
|
-
codec: parseInt('63636d', 16),
|
|
89
|
-
hashAlg: 'keccak-256'
|
|
90
|
-
},
|
|
91
|
-
'transaction-message': {
|
|
92
|
-
codec: parseInt('746d', 16),
|
|
93
|
-
hashAlg: 'keccak-256'
|
|
94
|
-
},
|
|
95
|
-
'block-message': {
|
|
96
|
-
codec: parseInt('626d', 16),
|
|
97
|
-
hashAlg: 'keccak-256'
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
blocks = await run(blocks);
|
|
102
|
-
globalThis.process ? process.send(blocks) : postMessage(blocks);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (globalThis.process) {
|
|
106
|
-
process.on('message', tasks);
|
|
107
|
-
} else {
|
|
108
|
-
onmessage = message => tasks(message.data);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
var blockWorker = /*#__PURE__*/Object.freeze({
|
|
112
|
-
__proto__: null
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
exports.blockWorker = blockWorker;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('./index-f77ba3de.js');
|
|
4
|
-
var transaction = require('./transaction-6a24c91e.js');
|
|
5
|
-
|
|
6
|
-
globalThis.peernet = globalThis.peernet || {};
|
|
7
|
-
globalThis.contracts = {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
process.on('message', async (transactions) => {
|
|
11
|
-
|
|
12
|
-
globalThis.peernet.codecs = {
|
|
13
|
-
'contract-message': {
|
|
14
|
-
codec: parseInt('63636d', 16),
|
|
15
|
-
hashAlg: 'keccak-256'
|
|
16
|
-
},
|
|
17
|
-
'transaction-message': {
|
|
18
|
-
codec: parseInt('746d', 16),
|
|
19
|
-
hashAlg: 'keccak-256'
|
|
20
|
-
},
|
|
21
|
-
'block-message': {
|
|
22
|
-
codec: parseInt('626d', 16),
|
|
23
|
-
hashAlg: 'keccak-256'
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
transactions = await Promise.all(transactions.map(async message => new transaction.TransactionMessage(message)));
|
|
27
|
-
|
|
28
|
-
process.send(transactions);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
var transactionWorker = /*#__PURE__*/Object.freeze({
|
|
32
|
-
__proto__: null
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
exports.transactionWorker = transactionWorker;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { F as FormatInterface_1 } from './index-6715242b.js';
|
|
2
|
-
import { B as BigNumber, f as formatBytes } from './utils-d240ed61.js';
|
|
3
|
-
import { fork } from 'child_process';
|
|
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 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
|
-
}
|
|
46
|
-
|
|
47
|
-
globalThis.BigNumber = BigNumber;
|
|
48
|
-
|
|
49
|
-
globalThis.peernet = globalThis.peernet || {};
|
|
50
|
-
globalThis.contracts = {};
|
|
51
|
-
|
|
52
|
-
const run = async (blocks) => {
|
|
53
|
-
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
54
|
-
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
55
|
-
|
|
56
|
-
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
57
|
-
if (globalThis.process) {
|
|
58
|
-
const worker = fork('./workers/transaction-worker.js', {serialization: 'advanced'});
|
|
59
|
-
|
|
60
|
-
worker.once('message', async transactions => {
|
|
61
|
-
block.decoded.transactions = transactions;
|
|
62
|
-
const size = block.encoded.length || block.encoded.byteLength;
|
|
63
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
64
|
-
resolve(block);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
worker.send(block.decoded.transactions);
|
|
68
|
-
} else {
|
|
69
|
-
const worker = new Worker('./workers/transaction-worker.js');
|
|
70
|
-
worker.onmessage = async message => {
|
|
71
|
-
const transactions = message.data;
|
|
72
|
-
block.decoded.transactions = transactions;
|
|
73
|
-
const size = block.encoded.length || block.encoded.byteLength;
|
|
74
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
75
|
-
resolve(block);
|
|
76
|
-
};
|
|
77
|
-
worker.postMessage(block.decoded.transactions);
|
|
78
|
-
}
|
|
79
|
-
})));
|
|
80
|
-
return blocks
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const tasks = async blocks => {
|
|
84
|
-
globalThis.peernet.codecs = {
|
|
85
|
-
'contract-message': {
|
|
86
|
-
codec: parseInt('63636d', 16),
|
|
87
|
-
hashAlg: 'keccak-256'
|
|
88
|
-
},
|
|
89
|
-
'transaction-message': {
|
|
90
|
-
codec: parseInt('746d', 16),
|
|
91
|
-
hashAlg: 'keccak-256'
|
|
92
|
-
},
|
|
93
|
-
'block-message': {
|
|
94
|
-
codec: parseInt('626d', 16),
|
|
95
|
-
hashAlg: 'keccak-256'
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
blocks = await run(blocks);
|
|
100
|
-
globalThis.process ? process.send(blocks) : postMessage(blocks);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
if (globalThis.process) {
|
|
104
|
-
process.on('message', tasks);
|
|
105
|
-
} else {
|
|
106
|
-
onmessage = message => tasks(message.data);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
var blockWorker = /*#__PURE__*/Object.freeze({
|
|
110
|
-
__proto__: null
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
export { blockWorker as b };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import './index-6715242b.js';
|
|
2
|
-
import { T as TransactionMessage } from './transaction-e9126d7b.js';
|
|
3
|
-
|
|
4
|
-
globalThis.peernet = globalThis.peernet || {};
|
|
5
|
-
globalThis.contracts = {};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
process.on('message', async (transactions) => {
|
|
9
|
-
|
|
10
|
-
globalThis.peernet.codecs = {
|
|
11
|
-
'contract-message': {
|
|
12
|
-
codec: parseInt('63636d', 16),
|
|
13
|
-
hashAlg: 'keccak-256'
|
|
14
|
-
},
|
|
15
|
-
'transaction-message': {
|
|
16
|
-
codec: parseInt('746d', 16),
|
|
17
|
-
hashAlg: 'keccak-256'
|
|
18
|
-
},
|
|
19
|
-
'block-message': {
|
|
20
|
-
codec: parseInt('626d', 16),
|
|
21
|
-
hashAlg: 'keccak-256'
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)));
|
|
25
|
-
|
|
26
|
-
process.send(transactions);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
var transactionWorker = /*#__PURE__*/Object.freeze({
|
|
30
|
-
__proto__: null
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export { transactionWorker as t };
|