@leofcoin/chain 1.3.12 → 1.4.1
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/block-worker.js +1 -1
- package/dist/browser/workers/block-worker.js +1977 -5692
- package/dist/browser/workers/machine-worker.js +1955 -5670
- package/dist/browser/workers/pool-worker.js +1636 -5531
- package/dist/browser/workers/transaction-worker.js +1626 -5521
- package/dist/chain.js +9865 -1196
- package/dist/client-80bc8156.js +491 -0
- package/dist/commonjs-7fe3c381.js +270 -0
- package/dist/generate-account-445db122.js +46 -0
- package/dist/index-57f93805.js +718 -0
- package/dist/{messages.browser.js → messages-bce1b91d-81af3b00.js} +26 -39
- package/dist/module/chain.js +9821 -1179
- package/dist/module/client-8031ec88.js +489 -0
- package/dist/module/commonjs-9005d5c0.js +268 -0
- package/dist/module/generate-account-489552b6.js +44 -0
- package/dist/module/index-ac2285c4.js +688 -0
- package/dist/module/messages-bce1b91d-eaf75d83.js +302 -0
- package/dist/module/node.js +6833 -2
- package/dist/module/workers/block-worker.js +3 -287
- package/dist/module/workers/machine-worker.js +3 -287
- package/dist/node.js +6845 -8
- package/dist/workers/machine-worker.js +1 -1
- package/package.json +15 -20
- package/src/chain.js +5 -12
- package/src/contract.js +2 -2
- package/src/machine.js +10 -7
- package/src/node.js +2 -2
- package/src/transaction.js +5 -5
- package/test/chain.js +5 -7
- package/test/index.js +1 -3
- package/tsconfig.js +15 -0
- package/workers/block-worker.js +40 -0
- package/workers/machine-worker.js +219 -0
- package/workers/pool-worker.js +28 -0
- package/workers/transaction-worker.js +20 -0
- package/workers/workers.js +9 -0
- package/dist/865.browser.js +0 -10
- package/dist/chain.browser.js +0 -66842
- package/dist/generate-account.browser.js +0 -50
- package/dist/multi-wallet.browser.js +0 -15
- package/dist/node.browser.js +0 -9858
- package/dist/pako.browser.js +0 -6900
- package/dist/peernet-swarm.browser.js +0 -839
- package/dist/storage.browser.js +0 -3724
- package/dist/wrtc.browser.js +0 -28
- package/rollup.config.js +0 -229
- package/src/standards/initializer.js +0 -10
- package/webpack.config.js +0 -109
|
@@ -0,0 +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
|
+
|
|
219
|
+
worker.onmessage(data => tasks(data))
|
|
@@ -0,0 +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))
|
|
@@ -0,0 +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)
|
|
20
|
+
})
|
|
@@ -0,0 +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
|