@leofcoin/chain 1.4.20 → 1.4.22
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/CHANGELOG.md +14 -14
- package/LICENSE +88 -88
- package/README.md +4 -4
- package/demo/index.html +25 -25
- package/examples/contracts/token.js +7 -7
- package/package.json +71 -71
- package/plugins/bundle.js +18 -18
- package/src/chain.js +716 -716
- package/src/config/config.js +14 -14
- package/src/config/main.js +4 -4
- package/src/config/protocol.js +5 -5
- package/src/contract.js +51 -51
- package/src/fee/config.js +3 -3
- package/src/machine.js +215 -215
- package/src/node.js +24 -24
- package/src/protocol.js +3 -3
- package/src/state.js +31 -31
- package/src/transaction.js +233 -233
- package/src/type.index.d.ts +20 -20
- package/src/typer.js +19 -19
- package/test/chain.js +120 -109
- package/test/contracts/token.js +40 -40
- package/test/create-genesis.js +66 -66
- package/tsconfig.js +14 -14
- package/workers/block-worker.js +40 -40
- package/workers/machine-worker.js +218 -218
- package/workers/pool-worker.js +28 -28
- package/workers/transaction-worker.js +19 -19
- package/workers/workers.js +8 -8
- package/block-worker.js +0 -1
- package/demo/865.browser.js +0 -10
- package/demo/chain.browser.js +0 -66842
- package/demo/generate-account.browser.js +0 -50
- package/demo/messages.browser.js +0 -328
- package/demo/multi-wallet.browser.js +0 -15
- package/demo/node.browser.js +0 -9858
- package/demo/pako.browser.js +0 -6900
- package/demo/peernet-swarm.browser.js +0 -839
- package/demo/storage.browser.js +0 -3724
- package/demo/workers/865.js +0 -10
- package/demo/workers/block-worker.js +0 -13175
- package/demo/workers/machine-worker.js +0 -13385
- package/demo/workers/pool-worker.js +0 -8503
- package/demo/workers/transaction-worker.js +0 -8495
- package/demo/wrtc.browser.js +0 -28
- package/dist/browser/workers/865.js +0 -10
- package/dist/browser/workers/block-worker.js +0 -9460
- package/dist/browser/workers/machine-worker.js +0 -9670
- package/dist/browser/workers/pool-worker.js +0 -4608
- package/dist/browser/workers/transaction-worker.js +0 -4600
- package/dist/chain.js +0 -10128
- package/dist/client-80bc8156.js +0 -491
- package/dist/commonjs-7fe3c381.js +0 -270
- package/dist/contracts/factory.js +0 -1
- package/dist/contracts/name-service.js +0 -1
- package/dist/contracts/native-token.js +0 -1
- package/dist/contracts/validators.js +0 -1
- package/dist/generate-account-445db122.js +0 -46
- package/dist/index-57f93805.js +0 -718
- package/dist/messages-bce1b91d-81af3b00.js +0 -315
- package/dist/module/chain.js +0 -10091
- package/dist/module/client-8031ec88.js +0 -489
- package/dist/module/commonjs-9005d5c0.js +0 -268
- package/dist/module/generate-account-489552b6.js +0 -44
- package/dist/module/index-ac2285c4.js +0 -688
- package/dist/module/messages-bce1b91d-eaf75d83.js +0 -302
- package/dist/module/node.js +0 -7049
- package/dist/module/workers/block-worker.js +0 -94
- package/dist/module/workers/machine-worker.js +0 -304
- package/dist/module/workers/pool-worker.js +0 -55
- package/dist/module/workers/transaction-worker.js +0 -47
- package/dist/node.js +0 -7061
- package/dist/standards/token.js +0 -1
- package/dist/workers/machine-worker.js +0 -1
- package/dist/workers/pool-worker.js +0 -1
- package/dist/workers/transaction-worker.js +0 -1
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
import { BlockMessage, ContractMessage } from './../../messages/src/messages.js'
|
|
2
|
-
import { formatBytes, BigNumber } from './../../utils/src/utils.js'
|
|
3
|
-
import bytecodes from './../../lib/src/bytecodes.json' 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
|
-
|
|
14
|
-
globalThis.peernet = globalThis.peernet || {}
|
|
15
|
-
globalThis.contracts = {}
|
|
16
|
-
|
|
17
|
-
const unique = arr => arr.filter((el, pos, arr) => {
|
|
18
|
-
return arr.indexOf(el) == pos;
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
const get = (contract, method, params) => {
|
|
22
|
-
let result
|
|
23
|
-
if (params?.length > 0) {
|
|
24
|
-
result = contracts[contract][method](...params)
|
|
25
|
-
} else {
|
|
26
|
-
result = contracts[contract][method]
|
|
27
|
-
}
|
|
28
|
-
return result
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const runContract = async ({decoded, hash, encoded}) => {
|
|
32
|
-
const params = decoded.constructorParameters
|
|
33
|
-
try {
|
|
34
|
-
|
|
35
|
-
const func = new Function(decoded.contract)
|
|
36
|
-
const Contract = func()
|
|
37
|
-
|
|
38
|
-
globalThis.msg = createMessage(decoded.creator)
|
|
39
|
-
contracts[hash] = await new Contract(...params)
|
|
40
|
-
worker.postMessage({
|
|
41
|
-
type: 'debug',
|
|
42
|
-
messages: [
|
|
43
|
-
`loaded contract: ${hash}`,
|
|
44
|
-
`size: ${formatBytes(encoded.length)}`
|
|
45
|
-
]
|
|
46
|
-
})
|
|
47
|
-
} catch (e) {
|
|
48
|
-
console.log(e);
|
|
49
|
-
worker.postMessage({
|
|
50
|
-
type: 'contractError',
|
|
51
|
-
hash: await contractMessage.hash
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const execute = async (contract, method, params) => {
|
|
57
|
-
try {
|
|
58
|
-
let result
|
|
59
|
-
// don't execute the method on a proxy
|
|
60
|
-
if (contracts[contract].fallback) {
|
|
61
|
-
result = await contracts[contract].fallback(method, params)
|
|
62
|
-
} else {
|
|
63
|
-
result = await contracts[contract][method](...params)
|
|
64
|
-
}
|
|
65
|
-
// state.put(result)
|
|
66
|
-
return result
|
|
67
|
-
} catch (e) {
|
|
68
|
-
throw e
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const createMessage = (sender = globalThis.peerid) => {
|
|
74
|
-
return {
|
|
75
|
-
sender,
|
|
76
|
-
call: execute,
|
|
77
|
-
staticCall: get
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
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
|
-
|
|
98
|
-
globalThis.peerid = peerid
|
|
99
|
-
contracts = [
|
|
100
|
-
contractFactoryMessage,
|
|
101
|
-
nativeTokenMessage,
|
|
102
|
-
nameServiceMessage,
|
|
103
|
-
validatorsMessage
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
contracts = await Promise.all(contracts.map(async contract => {
|
|
107
|
-
contract = await new ContractMessage(new Uint8Array(contract.split(',')))
|
|
108
|
-
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash})
|
|
109
|
-
return contract
|
|
110
|
-
}))
|
|
111
|
-
|
|
112
|
-
let lastBlock = {hash: '0x0'};
|
|
113
|
-
|
|
114
|
-
if (blocks?.length > 0) {
|
|
115
|
-
const _worker = await new EasyWorker('./workers/block-worker.js', {serialization: 'advanced', type: 'module' })
|
|
116
|
-
blocks = await _worker.once([blocks[blocks.length - 1]])
|
|
117
|
-
|
|
118
|
-
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
119
|
-
// for (let i = 0; i < blocks.length; i++) {
|
|
120
|
-
|
|
121
|
-
// }
|
|
122
|
-
// for (const block of blocks) {
|
|
123
|
-
// await Promise.all(block.decoded.transactions.map(async message => {
|
|
124
|
-
// if (!block.loaded) {
|
|
125
|
-
// const {from, to, method, params} = message;
|
|
126
|
-
// globalThis.msg = createMessage(from);
|
|
127
|
-
|
|
128
|
-
// await execute(to, method, params);
|
|
129
|
-
// block.loaded = true
|
|
130
|
-
// }
|
|
131
|
-
// }));
|
|
132
|
-
// }
|
|
133
|
-
|
|
134
|
-
if (blocks.length > 0) {
|
|
135
|
-
lastBlock = blocks[blocks.length - 1].decoded;
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
worker.postMessage({type: 'machine-ready', lastBlock});
|
|
150
|
-
|
|
151
|
-
// worker.postMessage({blocks});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const tasks = async (e) => {
|
|
155
|
-
const id = e.id
|
|
156
|
-
if (e.type === 'init') {
|
|
157
|
-
try {
|
|
158
|
-
await _init(e.input)
|
|
159
|
-
} catch (e) {
|
|
160
|
-
worker.postMessage({
|
|
161
|
-
type: 'initError',
|
|
162
|
-
message: e.message,
|
|
163
|
-
id
|
|
164
|
-
})
|
|
165
|
-
}
|
|
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
|
-
}
|
|
183
|
-
if (e.type === 'get') {
|
|
184
|
-
try {
|
|
185
|
-
const value = await get(e.input.contract, e.input.method, e.input.params)
|
|
186
|
-
worker.postMessage({
|
|
187
|
-
type: 'response',
|
|
188
|
-
id,
|
|
189
|
-
value
|
|
190
|
-
})
|
|
191
|
-
} catch (e) {
|
|
192
|
-
worker.postMessage({
|
|
193
|
-
type: 'fetchError',
|
|
194
|
-
message: e.message,
|
|
195
|
-
id
|
|
196
|
-
})
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
if (e.type === 'execute') {
|
|
201
|
-
try {
|
|
202
|
-
const value = await execute(e.input.contract, e.input.method, e.input.params)
|
|
203
|
-
worker.postMessage({
|
|
204
|
-
type: 'response',
|
|
205
|
-
id,
|
|
206
|
-
value
|
|
207
|
-
})
|
|
208
|
-
} catch(e) {
|
|
209
|
-
worker.postMessage({
|
|
210
|
-
type: 'executionError',
|
|
211
|
-
message: e.message,
|
|
212
|
-
id
|
|
213
|
-
|
|
214
|
-
})
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
1
|
+
import { BlockMessage, ContractMessage } from './../../messages/src/messages.js'
|
|
2
|
+
import { formatBytes, BigNumber } from './../../utils/src/utils.js'
|
|
3
|
+
import bytecodes from './../../lib/src/bytecodes.json' 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
|
+
|
|
14
|
+
globalThis.peernet = globalThis.peernet || {}
|
|
15
|
+
globalThis.contracts = {}
|
|
16
|
+
|
|
17
|
+
const unique = arr => arr.filter((el, pos, arr) => {
|
|
18
|
+
return arr.indexOf(el) == pos;
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const get = (contract, method, params) => {
|
|
22
|
+
let result
|
|
23
|
+
if (params?.length > 0) {
|
|
24
|
+
result = contracts[contract][method](...params)
|
|
25
|
+
} else {
|
|
26
|
+
result = contracts[contract][method]
|
|
27
|
+
}
|
|
28
|
+
return result
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const runContract = async ({decoded, hash, encoded}) => {
|
|
32
|
+
const params = decoded.constructorParameters
|
|
33
|
+
try {
|
|
34
|
+
|
|
35
|
+
const func = new Function(decoded.contract)
|
|
36
|
+
const Contract = func()
|
|
37
|
+
|
|
38
|
+
globalThis.msg = createMessage(decoded.creator)
|
|
39
|
+
contracts[hash] = await new Contract(...params)
|
|
40
|
+
worker.postMessage({
|
|
41
|
+
type: 'debug',
|
|
42
|
+
messages: [
|
|
43
|
+
`loaded contract: ${hash}`,
|
|
44
|
+
`size: ${formatBytes(encoded.length)}`
|
|
45
|
+
]
|
|
46
|
+
})
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.log(e);
|
|
49
|
+
worker.postMessage({
|
|
50
|
+
type: 'contractError',
|
|
51
|
+
hash: await contractMessage.hash
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const execute = async (contract, method, params) => {
|
|
57
|
+
try {
|
|
58
|
+
let result
|
|
59
|
+
// don't execute the method on a proxy
|
|
60
|
+
if (contracts[contract].fallback) {
|
|
61
|
+
result = await contracts[contract].fallback(method, params)
|
|
62
|
+
} else {
|
|
63
|
+
result = await contracts[contract][method](...params)
|
|
64
|
+
}
|
|
65
|
+
// state.put(result)
|
|
66
|
+
return result
|
|
67
|
+
} catch (e) {
|
|
68
|
+
throw e
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
const createMessage = (sender = globalThis.peerid) => {
|
|
74
|
+
return {
|
|
75
|
+
sender,
|
|
76
|
+
call: execute,
|
|
77
|
+
staticCall: get
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
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
|
+
|
|
98
|
+
globalThis.peerid = peerid
|
|
99
|
+
contracts = [
|
|
100
|
+
contractFactoryMessage,
|
|
101
|
+
nativeTokenMessage,
|
|
102
|
+
nameServiceMessage,
|
|
103
|
+
validatorsMessage
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
contracts = await Promise.all(contracts.map(async contract => {
|
|
107
|
+
contract = await new ContractMessage(new Uint8Array(contract.split(',')))
|
|
108
|
+
await runContract({decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash})
|
|
109
|
+
return contract
|
|
110
|
+
}))
|
|
111
|
+
|
|
112
|
+
let lastBlock = {hash: '0x0'};
|
|
113
|
+
|
|
114
|
+
if (blocks?.length > 0) {
|
|
115
|
+
const _worker = await new EasyWorker('./workers/block-worker.js', {serialization: 'advanced', type: 'module' })
|
|
116
|
+
blocks = await _worker.once([blocks[blocks.length - 1]])
|
|
117
|
+
|
|
118
|
+
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
119
|
+
// for (let i = 0; i < blocks.length; i++) {
|
|
120
|
+
|
|
121
|
+
// }
|
|
122
|
+
// for (const block of blocks) {
|
|
123
|
+
// await Promise.all(block.decoded.transactions.map(async message => {
|
|
124
|
+
// if (!block.loaded) {
|
|
125
|
+
// const {from, to, method, params} = message;
|
|
126
|
+
// globalThis.msg = createMessage(from);
|
|
127
|
+
|
|
128
|
+
// await execute(to, method, params);
|
|
129
|
+
// block.loaded = true
|
|
130
|
+
// }
|
|
131
|
+
// }));
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
if (blocks.length > 0) {
|
|
135
|
+
lastBlock = blocks[blocks.length - 1].decoded;
|
|
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
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
worker.postMessage({type: 'machine-ready', lastBlock});
|
|
150
|
+
|
|
151
|
+
// worker.postMessage({blocks});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const tasks = async (e) => {
|
|
155
|
+
const id = e.id
|
|
156
|
+
if (e.type === 'init') {
|
|
157
|
+
try {
|
|
158
|
+
await _init(e.input)
|
|
159
|
+
} catch (e) {
|
|
160
|
+
worker.postMessage({
|
|
161
|
+
type: 'initError',
|
|
162
|
+
message: e.message,
|
|
163
|
+
id
|
|
164
|
+
})
|
|
165
|
+
}
|
|
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
|
+
}
|
|
183
|
+
if (e.type === 'get') {
|
|
184
|
+
try {
|
|
185
|
+
const value = await get(e.input.contract, e.input.method, e.input.params)
|
|
186
|
+
worker.postMessage({
|
|
187
|
+
type: 'response',
|
|
188
|
+
id,
|
|
189
|
+
value
|
|
190
|
+
})
|
|
191
|
+
} catch (e) {
|
|
192
|
+
worker.postMessage({
|
|
193
|
+
type: 'fetchError',
|
|
194
|
+
message: e.message,
|
|
195
|
+
id
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
if (e.type === 'execute') {
|
|
201
|
+
try {
|
|
202
|
+
const value = await execute(e.input.contract, e.input.method, e.input.params)
|
|
203
|
+
worker.postMessage({
|
|
204
|
+
type: 'response',
|
|
205
|
+
id,
|
|
206
|
+
value
|
|
207
|
+
})
|
|
208
|
+
} catch(e) {
|
|
209
|
+
worker.postMessage({
|
|
210
|
+
type: 'executionError',
|
|
211
|
+
message: e.message,
|
|
212
|
+
id
|
|
213
|
+
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
219
|
worker.onmessage(data => tasks(data))
|
package/workers/pool-worker.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { TransactionMessage } from './../../messages/src/messages.js'
|
|
2
|
-
|
|
3
|
-
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
4
|
-
|
|
5
|
-
globalThis.peernet = globalThis.peernet || {}
|
|
6
|
-
globalThis.contracts = {}
|
|
7
|
-
|
|
8
|
-
const worker = new EasyWorker()
|
|
9
|
-
|
|
10
|
-
const tasks = async transactions => {
|
|
11
|
-
|
|
12
|
-
globalThis.peernet.codecs = {
|
|
13
|
-
'transaction-message': {
|
|
14
|
-
codec: parseInt('746d', 16),
|
|
15
|
-
hashAlg: 'keccak-256'
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
transactions = await Promise.all(transactions.map(async message => {
|
|
20
|
-
message = await new TransactionMessage(message)
|
|
21
|
-
|
|
22
|
-
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
23
|
-
}))
|
|
24
|
-
|
|
25
|
-
worker.postMessage(transactions)
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
worker.onmessage(data => tasks(data))
|
|
1
|
+
import { TransactionMessage } from './../../messages/src/messages.js'
|
|
2
|
+
|
|
3
|
+
import EasyWorker from '@vandeurenglenn/easy-worker'
|
|
4
|
+
|
|
5
|
+
globalThis.peernet = globalThis.peernet || {}
|
|
6
|
+
globalThis.contracts = {}
|
|
7
|
+
|
|
8
|
+
const worker = new EasyWorker()
|
|
9
|
+
|
|
10
|
+
const tasks = async transactions => {
|
|
11
|
+
|
|
12
|
+
globalThis.peernet.codecs = {
|
|
13
|
+
'transaction-message': {
|
|
14
|
+
codec: parseInt('746d', 16),
|
|
15
|
+
hashAlg: 'keccak-256'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
transactions = await Promise.all(transactions.map(async message => {
|
|
20
|
+
message = await new TransactionMessage(message)
|
|
21
|
+
|
|
22
|
+
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
worker.postMessage(transactions)
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
worker.onmessage(data => tasks(data))
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { TransactionMessage } from './../../messages/src/messages.js'
|
|
2
|
-
|
|
3
|
-
globalThis.peernet = globalThis.peernet || {}
|
|
4
|
-
globalThis.contracts = {}
|
|
5
|
-
|
|
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
|
-
}
|
|
16
|
-
}
|
|
17
|
-
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)))
|
|
18
|
-
|
|
19
|
-
worker.postMessage(transactions)
|
|
1
|
+
import { TransactionMessage } from './../../messages/src/messages.js'
|
|
2
|
+
|
|
3
|
+
globalThis.peernet = globalThis.peernet || {}
|
|
4
|
+
globalThis.contracts = {}
|
|
5
|
+
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
transactions = await Promise.all(transactions.map(async message => new TransactionMessage(message)))
|
|
18
|
+
|
|
19
|
+
worker.postMessage(transactions)
|
|
20
20
|
})
|
package/workers/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
|
|
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
9
|
export const MachineWorker = machineWorker
|
package/block-worker.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@leofcoin/codec-format-interface"),r=require("@ethersproject/bignumber");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@ethersproject/units"),require("randombytes");var a=s(require("@vandeurenglenn/easy-worker"));class BlockMessage extends e.FormatInterface{get keys(){return["index","previousHash","timestamp","reward","fees","transactions","validators"]}get messageName(){return"BlockMessage"}constructor(e){super(e,"\nmessage ValidatorMessage {\n required string address = 1;\n required string reward = 2;\n}\n\nmessage Transaction {\n required string hash = 1;\n required uint64 timestamp = 2;\n required string from = 3;\n required string to = 4;\n required uint64 nonce = 5;\n required string method = 6;\n repeated string params = 7;\n}\n\nmessage BlockMessage {\n required uint64 index = 1;\n required string previousHash = 3;\n required uint64 timestamp = 4;\n required uint64 reward = 5;\n required string fees = 6;\n repeated Transaction transactions = 7;\n repeated ValidatorMessage validators = 8;\n}\n",{name:"block-message"})}}const n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],t=new a.default;globalThis.BigNumber=r.BigNumber,globalThis.peernet=globalThis.peernet||{},globalThis.contracts={};const i=async e=>(e=(e=await Promise.all(e.map((e=>new BlockMessage(e))))).sort(((e,r)=>e.decoded.timestamp-r.decoded.timestamp)),e=await Promise.all(e.map((e=>new Promise((async(r,s)=>{const a=e.encoded.length||e.encoded.byteLength;console.log(`loaded block: ${await e.hash} @${e.decoded.index} ${((e,r=2)=>{if(0===e)return"0 Bytes";r<0&&(r=0);const s=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,s)).toFixed(r))} ${n[s]}`})(a)}`),r(e)}))))));t.onmessage((e=>(async e=>{globalThis.peernet.codecs={"block-message":{codec:parseInt("626d",16),hashAlg:"keccak-256"}},e=await i(e),t.postMessage(e)})(e)));
|