@leofcoin/workers 1.3.16 → 1.3.18
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/package.json +2 -1
- package/src/block-worker.js +36 -33
- package/src/log-worker.ts +50 -51
- package/src/machine-worker.js +230 -240
- package/src/pool-worker.js +19 -19
- package/src/transaction-worker.js +12 -12
- package/src/workers.js +9 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/workers",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.18",
|
|
4
4
|
"description": "Workers used in @leofcoin/chain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"./pool-worker": "./src/pool-worker.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
+
"prettier": "prettier src --config ./../../.prettierrc --write",
|
|
14
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
16
|
},
|
|
16
17
|
"keywords": [],
|
package/src/block-worker.js
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import { BlockMessage } from '@leofcoin/messages'
|
|
2
|
-
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
-
|
|
4
|
-
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
-
|
|
6
|
-
const worker = new EasyWorker()
|
|
7
|
-
|
|
8
|
-
globalThis.BigNumber = BigNumber
|
|
9
|
-
globalThis.contracts = {}
|
|
10
|
-
|
|
11
|
-
const run = async (blocks) => {
|
|
12
|
-
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)))
|
|
13
|
-
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp)
|
|
14
|
-
|
|
15
|
-
blocks = await Promise.all(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { BlockMessage } from '@leofcoin/messages'
|
|
2
|
+
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
+
|
|
4
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
+
|
|
6
|
+
const worker = new EasyWorker()
|
|
7
|
+
|
|
8
|
+
globalThis.BigNumber = BigNumber
|
|
9
|
+
globalThis.contracts = {}
|
|
10
|
+
|
|
11
|
+
const run = async (blocks) => {
|
|
12
|
+
blocks = await Promise.all(blocks.map((block) => new BlockMessage(block)))
|
|
13
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp)
|
|
14
|
+
|
|
15
|
+
blocks = await Promise.all(
|
|
16
|
+
blocks.map(
|
|
17
|
+
(block) =>
|
|
18
|
+
new Promise(async (resolve, reject) => {
|
|
19
|
+
// todo: tx worker or nah?
|
|
20
|
+
await block.encode()
|
|
21
|
+
const size = block.encoded.length || block.encoded.byteLength
|
|
22
|
+
console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`)
|
|
23
|
+
// todo we don't want this, need shared state
|
|
24
|
+
resolve(block.decoded)
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
return blocks
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const tasks = async (blocks) => {
|
|
32
|
+
blocks = await run(blocks)
|
|
33
|
+
worker.postMessage(blocks)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
worker.onmessage((data) => tasks(data))
|
package/src/log-worker.ts
CHANGED
|
@@ -1,51 +1,50 @@
|
|
|
1
|
-
import { BlockMessage } from '@leofcoin/messages'
|
|
2
|
-
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
-
|
|
4
|
-
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
-
import Storage from '@leofcoin/storage'
|
|
6
|
-
const worker = new EasyWorker()
|
|
7
|
-
const logStore = new Storage('log')
|
|
8
|
-
await logStore.init()
|
|
9
|
-
|
|
10
|
-
declare type messageType = 'put' | 'get'
|
|
11
|
-
|
|
12
|
-
declare type message = {
|
|
13
|
-
type: messageType
|
|
14
|
-
input: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare type messageReturn = {
|
|
18
|
-
type: messageType
|
|
19
|
-
result?: string
|
|
20
|
-
message?: string
|
|
21
|
-
error?: Error
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const handlePut = async message => {
|
|
25
|
-
try {
|
|
26
|
-
await fetch(`http://localhost:8844/log/put`, {
|
|
27
|
-
method: 'put',
|
|
28
|
-
body: message
|
|
29
|
-
})
|
|
30
|
-
} catch (error) {
|
|
31
|
-
worker.postMessage({ type: 'logError', message, error })
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const handleGet = async message => {
|
|
36
|
-
try {
|
|
37
|
-
await fetch(`http://localhost:8844/log/get?`, {
|
|
38
|
-
method: 'put',
|
|
39
|
-
body: message
|
|
40
|
-
})
|
|
41
|
-
} catch (error) {
|
|
42
|
-
worker.postMessage({ type: 'logError', message, error })
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
worker.onmessage((message: message) => {
|
|
47
|
-
if (!message.type) message.type = 'put'
|
|
48
|
-
if (message.type === 'put') handlePut(message.input)
|
|
49
|
-
else handleGet(message.input)
|
|
50
|
-
})
|
|
51
|
-
|
|
1
|
+
import { BlockMessage } from '@leofcoin/messages'
|
|
2
|
+
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
+
|
|
4
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
+
import Storage from '@leofcoin/storage'
|
|
6
|
+
const worker = new EasyWorker()
|
|
7
|
+
const logStore = new Storage('log')
|
|
8
|
+
await logStore.init()
|
|
9
|
+
|
|
10
|
+
declare type messageType = 'put' | 'get'
|
|
11
|
+
|
|
12
|
+
declare type message = {
|
|
13
|
+
type: messageType
|
|
14
|
+
input: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare type messageReturn = {
|
|
18
|
+
type: messageType
|
|
19
|
+
result?: string
|
|
20
|
+
message?: string
|
|
21
|
+
error?: Error
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const handlePut = async (message) => {
|
|
25
|
+
try {
|
|
26
|
+
await fetch(`http://localhost:8844/log/put`, {
|
|
27
|
+
method: 'put',
|
|
28
|
+
body: message
|
|
29
|
+
})
|
|
30
|
+
} catch (error) {
|
|
31
|
+
worker.postMessage({ type: 'logError', message, error })
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const handleGet = async (message) => {
|
|
36
|
+
try {
|
|
37
|
+
await fetch(`http://localhost:8844/log/get?`, {
|
|
38
|
+
method: 'put',
|
|
39
|
+
body: message
|
|
40
|
+
})
|
|
41
|
+
} catch (error) {
|
|
42
|
+
worker.postMessage({ type: 'logError', message, error })
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
worker.onmessage((message: message) => {
|
|
47
|
+
if (!message.type) message.type = 'put'
|
|
48
|
+
if (message.type === 'put') handlePut(message.input)
|
|
49
|
+
else handleGet(message.input)
|
|
50
|
+
})
|
package/src/machine-worker.js
CHANGED
|
@@ -1,240 +1,230 @@
|
|
|
1
|
-
import { BlockMessage, ContractMessage } from '@leofcoin/messages'
|
|
2
|
-
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
-
import bytecodes
|
|
4
|
-
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
-
const worker = new EasyWorker()
|
|
6
|
-
|
|
7
|
-
const contractFactoryMessage = bytecodes.contractFactory
|
|
8
|
-
const nativeTokenMessage = bytecodes.nativeToken
|
|
9
|
-
const nameServiceMessage = bytecodes.nameService
|
|
10
|
-
const validatorsMessage = bytecodes.validators
|
|
11
|
-
|
|
12
|
-
globalThis.BigNumber = BigNumber
|
|
13
|
-
globalThis.contracts = {}
|
|
14
|
-
|
|
15
|
-
const unique =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const func = new Function(new TextDecoder().decode(decoded.contract))
|
|
38
|
-
const Contract = func()
|
|
39
|
-
|
|
40
|
-
globalThis.msg = createMessage(decoded.creator)
|
|
41
|
-
contracts[hash] = await new Contract(...params)
|
|
42
|
-
worker.postMessage({
|
|
43
|
-
type: 'debug',
|
|
44
|
-
messages: [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
type: 'executionError',
|
|
232
|
-
message: e.message,
|
|
233
|
-
id
|
|
234
|
-
|
|
235
|
-
})
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
worker.onmessage(data => tasks(data))
|
|
1
|
+
import { BlockMessage, ContractMessage } from '@leofcoin/messages'
|
|
2
|
+
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
+
import bytecodes from '@leofcoin/lib/bytecodes' assert { type: 'json' }
|
|
4
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
+
const worker = new EasyWorker()
|
|
6
|
+
|
|
7
|
+
const contractFactoryMessage = bytecodes.contractFactory
|
|
8
|
+
const nativeTokenMessage = bytecodes.nativeToken
|
|
9
|
+
const nameServiceMessage = bytecodes.nameService
|
|
10
|
+
const validatorsMessage = bytecodes.validators
|
|
11
|
+
|
|
12
|
+
globalThis.BigNumber = BigNumber
|
|
13
|
+
globalThis.contracts = {}
|
|
14
|
+
|
|
15
|
+
const unique = (arr) =>
|
|
16
|
+
arr.filter((el, pos, arr) => {
|
|
17
|
+
return arr.indexOf(el) == pos
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const has = (address) => {
|
|
21
|
+
return contracts[address] ? true : false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const get = (contract, method, params) => {
|
|
25
|
+
let result
|
|
26
|
+
if (params?.length > 0) {
|
|
27
|
+
result = contracts[contract][method](...params)
|
|
28
|
+
} else {
|
|
29
|
+
result = contracts[contract][method]
|
|
30
|
+
}
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const runContract = async ({ decoded, hash, encoded }) => {
|
|
35
|
+
const params = decoded.constructorParameters
|
|
36
|
+
try {
|
|
37
|
+
const func = new Function(new TextDecoder().decode(decoded.contract))
|
|
38
|
+
const Contract = func()
|
|
39
|
+
|
|
40
|
+
globalThis.msg = createMessage(decoded.creator)
|
|
41
|
+
contracts[hash] = await new Contract(...params)
|
|
42
|
+
worker.postMessage({
|
|
43
|
+
type: 'debug',
|
|
44
|
+
messages: [`loaded contract: ${hash}`, `size: ${formatBytes(encoded.length)}`]
|
|
45
|
+
})
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.log(e)
|
|
48
|
+
worker.postMessage({
|
|
49
|
+
type: 'contractError',
|
|
50
|
+
hash: await contractMessage.hash()
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const execute = async (contract, method, params) => {
|
|
56
|
+
try {
|
|
57
|
+
let result
|
|
58
|
+
// don't execute the method on a proxy
|
|
59
|
+
if (contracts[contract].fallback) {
|
|
60
|
+
result = await contracts[contract].fallback(method, params)
|
|
61
|
+
} else {
|
|
62
|
+
result = await contracts[contract][method](...params)
|
|
63
|
+
}
|
|
64
|
+
// state.put(result)
|
|
65
|
+
return result
|
|
66
|
+
} catch (e) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`error: ${e.message}
|
|
69
|
+
contract: ${contract}
|
|
70
|
+
method: ${method}
|
|
71
|
+
params: ${JSON.stringify(params, null, '\t')}
|
|
72
|
+
`
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const createMessage = (sender = globalThis.peerid) => {
|
|
78
|
+
return {
|
|
79
|
+
sender,
|
|
80
|
+
call: execute,
|
|
81
|
+
staticCall: get
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const _init = async ({ contracts, blocks, peerid }) => {
|
|
86
|
+
globalThis.peerid = peerid
|
|
87
|
+
contracts = [contractFactoryMessage, nativeTokenMessage, nameServiceMessage, validatorsMessage]
|
|
88
|
+
|
|
89
|
+
contracts = await Promise.all(
|
|
90
|
+
contracts.map(async (contract) => {
|
|
91
|
+
contract = await new ContractMessage(new Uint8Array(contract.split(',')))
|
|
92
|
+
await runContract({ decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash() })
|
|
93
|
+
return contract
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
let lastBlock = { hash: '0x0' }
|
|
98
|
+
|
|
99
|
+
if (blocks?.length > 0) {
|
|
100
|
+
let pre
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const importee = await import('url')
|
|
104
|
+
const url = importee.default
|
|
105
|
+
if (url) pre = url.fileURLToPath(new URL('.', import.meta.url))
|
|
106
|
+
} catch {
|
|
107
|
+
// browser env
|
|
108
|
+
pre = './'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const _worker = await new EasyWorker(pre + '@leofcoin/workers/block-worker.js', {
|
|
112
|
+
serialization: 'advanced',
|
|
113
|
+
type: 'module'
|
|
114
|
+
})
|
|
115
|
+
blocks = await _worker.once([blocks[blocks.length - 1]])
|
|
116
|
+
|
|
117
|
+
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
118
|
+
// for (let i = 0; i < blocks.length; i++) {
|
|
119
|
+
|
|
120
|
+
// }
|
|
121
|
+
// for (const block of blocks) {
|
|
122
|
+
// await Promise.all(block.decoded.transactions.map(async message => {
|
|
123
|
+
// if (!block.loaded) {
|
|
124
|
+
// const {from, to, method, params} = message;
|
|
125
|
+
// globalThis.msg = createMessage(from);
|
|
126
|
+
|
|
127
|
+
// await execute(to, method, params);
|
|
128
|
+
// block.loaded = true
|
|
129
|
+
// }
|
|
130
|
+
// }));
|
|
131
|
+
// }
|
|
132
|
+
|
|
133
|
+
if (blocks.length > 0) {
|
|
134
|
+
lastBlock = blocks[blocks.length - 1]
|
|
135
|
+
// todo blocks already loaded as blockmessage so use it!
|
|
136
|
+
lastBlock = await new BlockMessage(lastBlock)
|
|
137
|
+
|
|
138
|
+
lastBlock = {
|
|
139
|
+
...lastBlock.decoded,
|
|
140
|
+
hash: await lastBlock.hash()
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
globalThis.blocks = blocks
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
worker.postMessage({ type: 'machine-ready', lastBlock })
|
|
147
|
+
|
|
148
|
+
// worker.postMessage({blocks});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const tasks = async (e) => {
|
|
152
|
+
const id = e.id
|
|
153
|
+
if (e.type === 'init') {
|
|
154
|
+
try {
|
|
155
|
+
await _init(e.input)
|
|
156
|
+
} catch (e) {
|
|
157
|
+
worker.postMessage({
|
|
158
|
+
type: 'initError',
|
|
159
|
+
message: e.message,
|
|
160
|
+
id
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (e.type === 'has') {
|
|
165
|
+
try {
|
|
166
|
+
const value = await has(e.input.address)
|
|
167
|
+
worker.postMessage({
|
|
168
|
+
type: 'response',
|
|
169
|
+
id,
|
|
170
|
+
value
|
|
171
|
+
})
|
|
172
|
+
} catch (error) {
|
|
173
|
+
worker.postMessage({
|
|
174
|
+
type: 'hasError',
|
|
175
|
+
message: error.message,
|
|
176
|
+
id
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (e.type === 'run') {
|
|
181
|
+
try {
|
|
182
|
+
const value = await runContract(e.input)
|
|
183
|
+
worker.postMessage({
|
|
184
|
+
type: 'response',
|
|
185
|
+
id,
|
|
186
|
+
value
|
|
187
|
+
})
|
|
188
|
+
} catch (e) {
|
|
189
|
+
worker.postMessage({
|
|
190
|
+
type: 'runError',
|
|
191
|
+
message: e.message,
|
|
192
|
+
id
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (e.type === 'get') {
|
|
197
|
+
try {
|
|
198
|
+
const value = await get(e.input.contract, e.input.method, e.input.params)
|
|
199
|
+
worker.postMessage({
|
|
200
|
+
type: 'response',
|
|
201
|
+
id,
|
|
202
|
+
value
|
|
203
|
+
})
|
|
204
|
+
} catch (e) {
|
|
205
|
+
worker.postMessage({
|
|
206
|
+
type: 'fetchError',
|
|
207
|
+
message: e.message,
|
|
208
|
+
id
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (e.type === 'execute') {
|
|
213
|
+
try {
|
|
214
|
+
const value = await execute(e.input.contract, e.input.method, e.input.params)
|
|
215
|
+
worker.postMessage({
|
|
216
|
+
type: 'response',
|
|
217
|
+
id,
|
|
218
|
+
value
|
|
219
|
+
})
|
|
220
|
+
} catch (e) {
|
|
221
|
+
worker.postMessage({
|
|
222
|
+
type: 'executionError',
|
|
223
|
+
message: e.message,
|
|
224
|
+
id
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
worker.onmessage((data) => tasks(data))
|
package/src/pool-worker.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { TransactionMessage } from '@leofcoin/messages'
|
|
2
|
-
|
|
3
|
-
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
4
|
-
globalThis.contracts = {}
|
|
5
|
-
|
|
6
|
-
const worker = new EasyWorker()
|
|
7
|
-
|
|
8
|
-
const tasks = async transactions => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
import { TransactionMessage } from '@leofcoin/messages'
|
|
2
|
+
|
|
3
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
4
|
+
globalThis.contracts = {}
|
|
5
|
+
|
|
6
|
+
const worker = new EasyWorker()
|
|
7
|
+
|
|
8
|
+
const tasks = async (transactions) => {
|
|
9
|
+
transactions = await Promise.all(
|
|
10
|
+
transactions.map(async (message) => {
|
|
11
|
+
message = await new TransactionMessage(message)
|
|
12
|
+
|
|
13
|
+
return { ...message.decoded, hash: await message.hash(), size: message.encoded.length }
|
|
14
|
+
})
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
worker.postMessage(transactions)
|
|
18
|
+
}
|
|
19
|
+
worker.onmessage((data) => tasks(data))
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { TransactionMessage } from '@leofcoin/messages'
|
|
2
|
-
globalThis.contracts = {}
|
|
3
|
-
|
|
4
|
-
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
-
|
|
6
|
-
const worker = new EasyWorker()
|
|
7
|
-
|
|
8
|
-
worker.onmessage(async (transactions) => {
|
|
9
|
-
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)))
|
|
10
|
-
|
|
11
|
-
worker.postMessage(transactions)
|
|
12
|
-
})
|
|
1
|
+
import { TransactionMessage } from '@leofcoin/messages'
|
|
2
|
+
globalThis.contracts = {}
|
|
3
|
+
|
|
4
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
|
+
|
|
6
|
+
const worker = new EasyWorker()
|
|
7
|
+
|
|
8
|
+
worker.onmessage(async (transactions) => {
|
|
9
|
+
transactions = await Promise.all(transactions.map(async (message) => new TransactionMessage(message)))
|
|
10
|
+
|
|
11
|
+
worker.postMessage(transactions)
|
|
12
|
+
})
|
package/src/workers.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as transactionWorker from './transaction-worker.js'
|
|
2
|
-
import * as blockWorker from './block-worker.js'
|
|
3
|
-
import * as poolWorker from './pool-worker.js'
|
|
4
|
-
import * as machineWorker from './machine-worker.js'
|
|
5
|
-
|
|
6
|
-
export const TransactionWorker = transactionWorker
|
|
7
|
-
export const BlockWorker = blockWorker
|
|
8
|
-
export const PoolWorker = poolWorker
|
|
9
|
-
export const MachineWorker = machineWorker
|
|
1
|
+
import * as transactionWorker from './transaction-worker.js'
|
|
2
|
+
import * as blockWorker from './block-worker.js'
|
|
3
|
+
import * as poolWorker from './pool-worker.js'
|
|
4
|
+
import * as machineWorker from './machine-worker.js'
|
|
5
|
+
|
|
6
|
+
export const TransactionWorker = transactionWorker
|
|
7
|
+
export const BlockWorker = blockWorker
|
|
8
|
+
export const PoolWorker = poolWorker
|
|
9
|
+
export const MachineWorker = machineWorker
|