@leofcoin/workers 1.3.4 → 1.3.6
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/{machine-worker-51023882.js → machine-worker-70f71351.js} +24 -10
- package/dist/bundle/commonjs/machine-worker.js +2 -2
- package/dist/bundle/commonjs/workers.js +1 -1
- package/dist/bundle/module/{machine-worker-b1412cf2.js → machine-worker-5896ac08.js} +25 -11
- package/dist/bundle/module/machine-worker.js +2 -2
- package/dist/bundle/module/workers.js +1 -1
- package/dist/commonjs/{machine-worker-cb614eb0.js → machine-worker-b46cac38.js} +24 -10
- package/dist/commonjs/machine-worker.js +1 -2
- package/dist/commonjs/workers.js +1 -2
- package/dist/module/{machine-worker-8e58ffb3.js → machine-worker-da95e492.js} +25 -11
- package/dist/module/machine-worker.js +1 -2
- package/dist/module/workers.js +1 -2
- package/package.json +10 -9
- package/src/block-worker.js +3 -3
- package/src/machine-worker.js +29 -16
- package/src/pool-worker.js +2 -2
- package/src/transaction-worker.js +1 -1
- package/src/workers.js +4 -4
- package/rollup.config.js +0 -40
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var worker$1 = require('./worker-6ace445f.js');
|
|
4
4
|
var utils = require('./utils-6e881be4.js');
|
|
5
|
-
require('path');
|
|
6
5
|
|
|
7
6
|
var proto = `
|
|
8
7
|
message ContractMessage {
|
|
@@ -59,21 +58,20 @@ const get = (contract, method, params) => {
|
|
|
59
58
|
return result
|
|
60
59
|
};
|
|
61
60
|
|
|
62
|
-
const runContract = async (
|
|
63
|
-
const params =
|
|
61
|
+
const runContract = async ({decoded, hash, encoded}) => {
|
|
62
|
+
const params = decoded.constructorParameters;
|
|
64
63
|
try {
|
|
65
64
|
|
|
66
|
-
const func = new Function(
|
|
65
|
+
const func = new Function(decoded.contract);
|
|
67
66
|
const Contract = func();
|
|
68
67
|
|
|
69
|
-
globalThis.msg = createMessage(
|
|
70
|
-
|
|
71
|
-
contracts[await contractMessage.hash] = await new Contract(...params);
|
|
68
|
+
globalThis.msg = createMessage(decoded.creator);
|
|
69
|
+
contracts[hash] = await new Contract(...params);
|
|
72
70
|
worker.postMessage({
|
|
73
71
|
type: 'debug',
|
|
74
72
|
messages: [
|
|
75
|
-
`loaded contract: ${
|
|
76
|
-
`size: ${utils.formatBytes(
|
|
73
|
+
`loaded contract: ${hash}`,
|
|
74
|
+
`size: ${utils.formatBytes(encoded.length)}`
|
|
77
75
|
]
|
|
78
76
|
});
|
|
79
77
|
} catch (e) {
|
|
@@ -137,7 +135,7 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
137
135
|
|
|
138
136
|
contracts = await Promise.all(contracts.map(async contract => {
|
|
139
137
|
contract = await new ContractMessage(new Uint8Array(contract.split(',')));
|
|
140
|
-
await runContract(contract);
|
|
138
|
+
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash});
|
|
141
139
|
return contract
|
|
142
140
|
}));
|
|
143
141
|
|
|
@@ -196,6 +194,22 @@ const tasks = async (e) => {
|
|
|
196
194
|
});
|
|
197
195
|
}
|
|
198
196
|
}
|
|
197
|
+
if (e.type === 'run') {
|
|
198
|
+
try {
|
|
199
|
+
const value = await runContract(e.input);
|
|
200
|
+
worker.postMessage({
|
|
201
|
+
type: 'response',
|
|
202
|
+
id,
|
|
203
|
+
value
|
|
204
|
+
});
|
|
205
|
+
} catch (e) {
|
|
206
|
+
worker.postMessage({
|
|
207
|
+
type: 'fetchError',
|
|
208
|
+
message: e.message,
|
|
209
|
+
id
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
199
213
|
if (e.type === 'get') {
|
|
200
214
|
try {
|
|
201
215
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./machine-worker-
|
|
3
|
+
require('./machine-worker-70f71351.js');
|
|
4
4
|
require('./worker-6ace445f.js');
|
|
5
5
|
require('./utils-6e881be4.js');
|
|
6
|
-
require('path');
|
|
7
6
|
require('stream');
|
|
8
7
|
require('events');
|
|
9
8
|
require('buffer');
|
|
10
9
|
require('util');
|
|
11
10
|
require('string_decoder/');
|
|
12
11
|
require('fs');
|
|
12
|
+
require('path');
|
|
13
13
|
require('os');
|
|
14
14
|
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var transactionWorker = require('./transaction-worker-176a5aaa.js');
|
|
6
6
|
var blockWorker = require('./block-worker-21ad8152.js');
|
|
7
7
|
var poolWorker = require('./pool-worker-f450eeff.js');
|
|
8
|
-
var machineWorker = require('./machine-worker-
|
|
8
|
+
var machineWorker = require('./machine-worker-70f71351.js');
|
|
9
9
|
require('./worker-6ace445f.js');
|
|
10
10
|
require('stream');
|
|
11
11
|
require('events');
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { F as FormatInterface_1, E as EasyWorker } from './worker-def77c26.js';
|
|
2
|
-
import { B as BigNumber,
|
|
3
|
-
import 'path';
|
|
2
|
+
import { B as BigNumber, f as formatBytes, a as BlockMessage } from './utils-ac8c68e6.js';
|
|
4
3
|
|
|
5
4
|
var proto = `
|
|
6
5
|
message ContractMessage {
|
|
@@ -57,21 +56,20 @@ const get = (contract, method, params) => {
|
|
|
57
56
|
return result
|
|
58
57
|
};
|
|
59
58
|
|
|
60
|
-
const runContract = async (
|
|
61
|
-
const params =
|
|
59
|
+
const runContract = async ({decoded, hash, encoded}) => {
|
|
60
|
+
const params = decoded.constructorParameters;
|
|
62
61
|
try {
|
|
63
62
|
|
|
64
|
-
const func = new Function(
|
|
63
|
+
const func = new Function(decoded.contract);
|
|
65
64
|
const Contract = func();
|
|
66
65
|
|
|
67
|
-
globalThis.msg = createMessage(
|
|
68
|
-
|
|
69
|
-
contracts[await contractMessage.hash] = await new Contract(...params);
|
|
66
|
+
globalThis.msg = createMessage(decoded.creator);
|
|
67
|
+
contracts[hash] = await new Contract(...params);
|
|
70
68
|
worker.postMessage({
|
|
71
69
|
type: 'debug',
|
|
72
70
|
messages: [
|
|
73
|
-
`loaded contract: ${
|
|
74
|
-
`size: ${formatBytes(
|
|
71
|
+
`loaded contract: ${hash}`,
|
|
72
|
+
`size: ${formatBytes(encoded.length)}`
|
|
75
73
|
]
|
|
76
74
|
});
|
|
77
75
|
} catch (e) {
|
|
@@ -135,7 +133,7 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
135
133
|
|
|
136
134
|
contracts = await Promise.all(contracts.map(async contract => {
|
|
137
135
|
contract = await new ContractMessage(new Uint8Array(contract.split(',')));
|
|
138
|
-
await runContract(contract);
|
|
136
|
+
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash});
|
|
139
137
|
return contract
|
|
140
138
|
}));
|
|
141
139
|
|
|
@@ -194,6 +192,22 @@ const tasks = async (e) => {
|
|
|
194
192
|
});
|
|
195
193
|
}
|
|
196
194
|
}
|
|
195
|
+
if (e.type === 'run') {
|
|
196
|
+
try {
|
|
197
|
+
const value = await runContract(e.input);
|
|
198
|
+
worker.postMessage({
|
|
199
|
+
type: 'response',
|
|
200
|
+
id,
|
|
201
|
+
value
|
|
202
|
+
});
|
|
203
|
+
} catch (e) {
|
|
204
|
+
worker.postMessage({
|
|
205
|
+
type: 'fetchError',
|
|
206
|
+
message: e.message,
|
|
207
|
+
id
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
197
211
|
if (e.type === 'get') {
|
|
198
212
|
try {
|
|
199
213
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import './machine-worker-
|
|
1
|
+
import './machine-worker-5896ac08.js';
|
|
2
2
|
import './worker-def77c26.js';
|
|
3
3
|
import './utils-ac8c68e6.js';
|
|
4
|
-
import 'path';
|
|
5
4
|
import 'stream';
|
|
6
5
|
import 'events';
|
|
7
6
|
import 'buffer';
|
|
8
7
|
import 'util';
|
|
9
8
|
import 'string_decoder/';
|
|
10
9
|
import 'fs';
|
|
10
|
+
import 'path';
|
|
11
11
|
import 'os';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as transactionWorker } from './transaction-worker-548cd200.js';
|
|
2
2
|
import { b as blockWorker } from './block-worker-414860e0.js';
|
|
3
3
|
import { p as poolWorker } from './pool-worker-0d927e3c.js';
|
|
4
|
-
import { m as machineWorker } from './machine-worker-
|
|
4
|
+
import { m as machineWorker } from './machine-worker-5896ac08.js';
|
|
5
5
|
import './worker-def77c26.js';
|
|
6
6
|
import 'stream';
|
|
7
7
|
import 'events';
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
4
|
var utils = require('./utils-1dc37f72.js');
|
|
5
|
-
require('path');
|
|
6
5
|
var EasyWorker = require('@vandeurenglenn/easy-worker');
|
|
7
6
|
|
|
8
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -64,21 +63,20 @@ const get = (contract, method, params) => {
|
|
|
64
63
|
return result
|
|
65
64
|
};
|
|
66
65
|
|
|
67
|
-
const runContract = async (
|
|
68
|
-
const params =
|
|
66
|
+
const runContract = async ({decoded, hash, encoded}) => {
|
|
67
|
+
const params = decoded.constructorParameters;
|
|
69
68
|
try {
|
|
70
69
|
|
|
71
|
-
const func = new Function(
|
|
70
|
+
const func = new Function(decoded.contract);
|
|
72
71
|
const Contract = func();
|
|
73
72
|
|
|
74
|
-
globalThis.msg = createMessage(
|
|
75
|
-
|
|
76
|
-
contracts[await contractMessage.hash] = await new Contract(...params);
|
|
73
|
+
globalThis.msg = createMessage(decoded.creator);
|
|
74
|
+
contracts[hash] = await new Contract(...params);
|
|
77
75
|
worker.postMessage({
|
|
78
76
|
type: 'debug',
|
|
79
77
|
messages: [
|
|
80
|
-
`loaded contract: ${
|
|
81
|
-
`size: ${utils.formatBytes(
|
|
78
|
+
`loaded contract: ${hash}`,
|
|
79
|
+
`size: ${utils.formatBytes(encoded.length)}`
|
|
82
80
|
]
|
|
83
81
|
});
|
|
84
82
|
} catch (e) {
|
|
@@ -142,7 +140,7 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
142
140
|
|
|
143
141
|
contracts = await Promise.all(contracts.map(async contract => {
|
|
144
142
|
contract = await new ContractMessage(new Uint8Array(contract.split(',')));
|
|
145
|
-
await runContract(contract);
|
|
143
|
+
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash});
|
|
146
144
|
return contract
|
|
147
145
|
}));
|
|
148
146
|
|
|
@@ -201,6 +199,22 @@ const tasks = async (e) => {
|
|
|
201
199
|
});
|
|
202
200
|
}
|
|
203
201
|
}
|
|
202
|
+
if (e.type === 'run') {
|
|
203
|
+
try {
|
|
204
|
+
const value = await runContract(e.input);
|
|
205
|
+
worker.postMessage({
|
|
206
|
+
type: 'response',
|
|
207
|
+
id,
|
|
208
|
+
value
|
|
209
|
+
});
|
|
210
|
+
} catch (e) {
|
|
211
|
+
worker.postMessage({
|
|
212
|
+
type: 'fetchError',
|
|
213
|
+
message: e.message,
|
|
214
|
+
id
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
204
218
|
if (e.type === 'get') {
|
|
205
219
|
try {
|
|
206
220
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./machine-worker-
|
|
3
|
+
require('./machine-worker-b46cac38.js');
|
|
4
4
|
require('@leofcoin/codec-format-interface');
|
|
5
5
|
require('./utils-1dc37f72.js');
|
|
6
|
-
require('path');
|
|
7
6
|
require('@vandeurenglenn/easy-worker');
|
|
8
7
|
require('bn.js');
|
|
9
8
|
require('@ethersproject/bytes');
|
package/dist/commonjs/workers.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var transactionWorker = require('./transaction-worker-8eecc7a1.js');
|
|
6
6
|
var blockWorker = require('./block-worker-60e4cfa3.js');
|
|
7
7
|
var poolWorker = require('./pool-worker-81e8b4c0.js');
|
|
8
|
-
var machineWorker = require('./machine-worker-
|
|
8
|
+
var machineWorker = require('./machine-worker-b46cac38.js');
|
|
9
9
|
require('@leofcoin/codec-format-interface');
|
|
10
10
|
require('./transaction-220a3a15.js');
|
|
11
11
|
require('@vandeurenglenn/easy-worker');
|
|
@@ -14,7 +14,6 @@ require('bn.js');
|
|
|
14
14
|
require('@ethersproject/bytes');
|
|
15
15
|
require('@ethersproject/logger');
|
|
16
16
|
require('@ethersproject/bignumber');
|
|
17
|
-
require('path');
|
|
18
17
|
|
|
19
18
|
const TransactionWorker = transactionWorker.transactionWorker;
|
|
20
19
|
const BlockWorker = blockWorker.blockWorker;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FormatInterface } from '@leofcoin/codec-format-interface';
|
|
2
|
-
import { B as BigNumber,
|
|
3
|
-
import 'path';
|
|
2
|
+
import { B as BigNumber, f as formatBytes, a as BlockMessage } from './utils-e87bc63d.js';
|
|
4
3
|
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
5
4
|
|
|
6
5
|
var proto = `
|
|
@@ -58,21 +57,20 @@ const get = (contract, method, params) => {
|
|
|
58
57
|
return result
|
|
59
58
|
};
|
|
60
59
|
|
|
61
|
-
const runContract = async (
|
|
62
|
-
const params =
|
|
60
|
+
const runContract = async ({decoded, hash, encoded}) => {
|
|
61
|
+
const params = decoded.constructorParameters;
|
|
63
62
|
try {
|
|
64
63
|
|
|
65
|
-
const func = new Function(
|
|
64
|
+
const func = new Function(decoded.contract);
|
|
66
65
|
const Contract = func();
|
|
67
66
|
|
|
68
|
-
globalThis.msg = createMessage(
|
|
69
|
-
|
|
70
|
-
contracts[await contractMessage.hash] = await new Contract(...params);
|
|
67
|
+
globalThis.msg = createMessage(decoded.creator);
|
|
68
|
+
contracts[hash] = await new Contract(...params);
|
|
71
69
|
worker.postMessage({
|
|
72
70
|
type: 'debug',
|
|
73
71
|
messages: [
|
|
74
|
-
`loaded contract: ${
|
|
75
|
-
`size: ${formatBytes(
|
|
72
|
+
`loaded contract: ${hash}`,
|
|
73
|
+
`size: ${formatBytes(encoded.length)}`
|
|
76
74
|
]
|
|
77
75
|
});
|
|
78
76
|
} catch (e) {
|
|
@@ -136,7 +134,7 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
136
134
|
|
|
137
135
|
contracts = await Promise.all(contracts.map(async contract => {
|
|
138
136
|
contract = await new ContractMessage(new Uint8Array(contract.split(',')));
|
|
139
|
-
await runContract(contract);
|
|
137
|
+
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash});
|
|
140
138
|
return contract
|
|
141
139
|
}));
|
|
142
140
|
|
|
@@ -195,6 +193,22 @@ const tasks = async (e) => {
|
|
|
195
193
|
});
|
|
196
194
|
}
|
|
197
195
|
}
|
|
196
|
+
if (e.type === 'run') {
|
|
197
|
+
try {
|
|
198
|
+
const value = await runContract(e.input);
|
|
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
|
+
}
|
|
198
212
|
if (e.type === 'get') {
|
|
199
213
|
try {
|
|
200
214
|
const value = await get(e.input.contract, e.input.method, e.input.params);
|
package/dist/module/workers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as transactionWorker } from './transaction-worker-105deaa8.js';
|
|
2
2
|
import { b as blockWorker } from './block-worker-f539b1b2.js';
|
|
3
3
|
import { p as poolWorker } from './pool-worker-f65671d7.js';
|
|
4
|
-
import { m as machineWorker } from './machine-worker-
|
|
4
|
+
import { m as machineWorker } from './machine-worker-da95e492.js';
|
|
5
5
|
import '@leofcoin/codec-format-interface';
|
|
6
6
|
import './transaction-d06dc6c4.js';
|
|
7
7
|
import '@vandeurenglenn/easy-worker';
|
|
@@ -10,7 +10,6 @@ import 'bn.js';
|
|
|
10
10
|
import '@ethersproject/bytes';
|
|
11
11
|
import '@ethersproject/logger';
|
|
12
12
|
import '@ethersproject/bignumber';
|
|
13
|
-
import 'path';
|
|
14
13
|
|
|
15
14
|
const TransactionWorker = transactionWorker;
|
|
16
15
|
const BlockWorker = blockWorker;
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/workers",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "1.3.6",
|
|
4
|
+
"description": "Workers used in @leofcoin/chain",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/workers.js",
|
|
8
|
+
"./machine-worker": "./src/machine-worker.js",
|
|
9
|
+
"./block-worker": "./src/block-worker.js",
|
|
10
|
+
"./transaction-worker": "./src/transaction-worker.js",
|
|
11
|
+
"./pool-worker": "./src/pool-worker.js"
|
|
12
|
+
},
|
|
6
13
|
"scripts": {
|
|
7
14
|
"build": "rollup -c",
|
|
8
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -10,12 +17,6 @@
|
|
|
10
17
|
"keywords": [],
|
|
11
18
|
"author": "",
|
|
12
19
|
"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
20
|
"dependencies": {
|
|
20
21
|
"@leofcoin/messages": "^1.2.0"
|
|
21
22
|
}
|
package/src/block-worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BlockMessage } from '
|
|
2
|
-
import { formatBytes, BigNumber } from '
|
|
1
|
+
import { BlockMessage } from '@leofcoin/messages'
|
|
2
|
+
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
3
|
|
|
4
4
|
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ const run = async (blocks) => {
|
|
|
17
17
|
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
18
18
|
// todo: tx worker or nah?
|
|
19
19
|
const size = block.encoded.length || block.encoded.byteLength
|
|
20
|
-
console.log(`loaded block: ${await block.hash} @${block.decoded.index} ${formatBytes(size)}`);
|
|
20
|
+
console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`);
|
|
21
21
|
resolve(block)
|
|
22
22
|
})))
|
|
23
23
|
return blocks
|
package/src/machine-worker.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { BlockMessage, ContractMessage } from '
|
|
2
|
-
import { formatBytes, BigNumber } from '
|
|
3
|
-
import bytecodes from '
|
|
4
|
-
import { join } from 'path'
|
|
5
|
-
|
|
1
|
+
import { BlockMessage, ContractMessage } from '@leofcoin/messages'
|
|
2
|
+
import { formatBytes, BigNumber } from '@leofcoin/utils'
|
|
3
|
+
import bytecodes from '@leofcoin/lib/bytecodes.json' assert {type: 'json'}
|
|
6
4
|
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
7
5
|
const worker = new EasyWorker()
|
|
8
6
|
|
|
@@ -30,28 +28,27 @@ const get = (contract, method, params) => {
|
|
|
30
28
|
return result
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
const runContract = async (
|
|
34
|
-
const params =
|
|
31
|
+
const runContract = async ({decoded, hash, encoded}) => {
|
|
32
|
+
const params = decoded.constructorParameters
|
|
35
33
|
try {
|
|
36
34
|
|
|
37
|
-
const func = new Function(
|
|
35
|
+
const func = new Function(decoded.contract)
|
|
38
36
|
const Contract = func()
|
|
39
37
|
|
|
40
|
-
globalThis.msg = createMessage(
|
|
41
|
-
|
|
42
|
-
contracts[await contractMessage.hash] = await new Contract(...params)
|
|
38
|
+
globalThis.msg = createMessage(decoded.creator)
|
|
39
|
+
contracts[hash] = await new Contract(...params)
|
|
43
40
|
worker.postMessage({
|
|
44
41
|
type: 'debug',
|
|
45
42
|
messages: [
|
|
46
|
-
`loaded contract: ${
|
|
47
|
-
`size: ${formatBytes(
|
|
43
|
+
`loaded contract: ${hash}`,
|
|
44
|
+
`size: ${formatBytes(encoded.length)}`
|
|
48
45
|
]
|
|
49
46
|
})
|
|
50
47
|
} catch (e) {
|
|
51
48
|
console.log(e);
|
|
52
49
|
worker.postMessage({
|
|
53
50
|
type: 'contractError',
|
|
54
|
-
hash: await contractMessage.hash
|
|
51
|
+
hash: await contractMessage.hash()
|
|
55
52
|
})
|
|
56
53
|
}
|
|
57
54
|
}
|
|
@@ -108,7 +105,7 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
108
105
|
|
|
109
106
|
contracts = await Promise.all(contracts.map(async contract => {
|
|
110
107
|
contract = await new ContractMessage(new Uint8Array(contract.split(',')))
|
|
111
|
-
await runContract(contract)
|
|
108
|
+
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash()})
|
|
112
109
|
return contract
|
|
113
110
|
}))
|
|
114
111
|
|
|
@@ -140,7 +137,7 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
140
137
|
|
|
141
138
|
lastBlock = {
|
|
142
139
|
...lastBlock.decoded,
|
|
143
|
-
hash: await lastBlock.hash
|
|
140
|
+
hash: await lastBlock.hash()
|
|
144
141
|
};
|
|
145
142
|
}
|
|
146
143
|
globalThis.blocks = blocks
|
|
@@ -167,6 +164,22 @@ const tasks = async (e) => {
|
|
|
167
164
|
})
|
|
168
165
|
}
|
|
169
166
|
}
|
|
167
|
+
if (e.type === 'run') {
|
|
168
|
+
try {
|
|
169
|
+
const value = await runContract(e.input)
|
|
170
|
+
worker.postMessage({
|
|
171
|
+
type: 'response',
|
|
172
|
+
id,
|
|
173
|
+
value
|
|
174
|
+
})
|
|
175
|
+
} catch (e) {
|
|
176
|
+
worker.postMessage({
|
|
177
|
+
type: 'runError',
|
|
178
|
+
message: e.message,
|
|
179
|
+
id
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
}
|
|
170
183
|
if (e.type === 'get') {
|
|
171
184
|
try {
|
|
172
185
|
const value = await get(e.input.contract, e.input.method, e.input.params)
|
package/src/pool-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransactionMessage } from '
|
|
1
|
+
import { TransactionMessage } from '@leofcoin/messages'
|
|
2
2
|
|
|
3
3
|
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ const tasks = async transactions => {
|
|
|
19
19
|
transactions = await Promise.all(transactions.map(async message => {
|
|
20
20
|
message = await new TransactionMessage(message)
|
|
21
21
|
|
|
22
|
-
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
22
|
+
return {...message.decoded, hash: await message.hash(), size: message.encoded.length}
|
|
23
23
|
}))
|
|
24
24
|
|
|
25
25
|
worker.postMessage(transactions)
|
package/src/workers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as transactionWorker from './transaction-worker'
|
|
2
|
-
import * as blockWorker from './block-worker'
|
|
3
|
-
import * as poolWorker from './pool-worker'
|
|
4
|
-
import * as machineWorker from './machine-worker'
|
|
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
5
|
|
|
6
6
|
export const TransactionWorker = transactionWorker
|
|
7
7
|
export const BlockWorker = blockWorker
|
package/rollup.config.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
2
|
-
import json from '@rollup/plugin-json'
|
|
3
|
-
import resolve from '@rollup/plugin-node-resolve'
|
|
4
|
-
|
|
5
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
6
|
-
try {
|
|
7
|
-
execSync(`rm -rf ./dist/**`)
|
|
8
|
-
|
|
9
|
-
} catch (e) {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export default [{
|
|
13
|
-
input: ['./src/workers.js', './src/transaction-worker.js', './src/block-worker.js', './src/pool-worker.js', './src/machine-worker.js'],
|
|
14
|
-
|
|
15
|
-
plugins: [
|
|
16
|
-
json()
|
|
17
|
-
],
|
|
18
|
-
output: [{
|
|
19
|
-
dir: './dist/commonjs',
|
|
20
|
-
format: 'cjs'
|
|
21
|
-
}, {
|
|
22
|
-
dir: './dist/module',
|
|
23
|
-
format: 'es'
|
|
24
|
-
}]
|
|
25
|
-
}, {
|
|
26
|
-
input: ['./src/workers.js', './src/transaction-worker.js', './src/block-worker.js', './src/pool-worker.js', './src/machine-worker.js'],
|
|
27
|
-
|
|
28
|
-
plugins: [
|
|
29
|
-
json(),
|
|
30
|
-
commonjs(),
|
|
31
|
-
resolve()
|
|
32
|
-
],
|
|
33
|
-
output: [{
|
|
34
|
-
dir: './dist/bundle/commonjs',
|
|
35
|
-
format: 'cjs'
|
|
36
|
-
}, {
|
|
37
|
-
dir: './dist/bundle/module',
|
|
38
|
-
format: 'es'
|
|
39
|
-
}]
|
|
40
|
-
}]
|