@leofcoin/workers 1.4.10 → 1.4.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/workers",
3
- "version": "1.4.10",
3
+ "version": "1.4.12",
4
4
  "description": "Workers used in @leofcoin/chain",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,7 +21,6 @@ const run = async (blocks) => {
21
21
  const size = block.encoded.length || block.encoded.byteLength
22
22
  const hash = await block.hash()
23
23
  const index = block.decoded.index
24
- console.log(`loaded block: ${hash} @${index} ${formatBytes(size)}`)
25
24
  resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } })
26
25
  })
27
26
  )
@@ -28,7 +28,7 @@ const _ = {}
28
28
 
29
29
  globalThis.BigNumber = BigNumber
30
30
 
31
- let lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' }
31
+ let lastBlock = { index: -1, hash: '0x0', previousHash: '0x0' }
32
32
 
33
33
  const unique = (arr) =>
34
34
  arr.filter((el, pos, arr) => {
@@ -131,17 +131,22 @@ const _executeTransaction = async (transaction) => {
131
131
  }
132
132
 
133
133
  _.init = async (message) => {
134
- let { contracts, peerid } = message
134
+ let { contracts, peerid, fromState, states } = message
135
+ console.log({ states })
136
+
135
137
  globalThis.peerid = peerid
136
- contracts = [contractFactoryMessage, nativeTokenMessage, nameServiceMessage, validatorsMessage]
138
+ if (fromState) {
139
+ } else {
140
+ contracts = [contractFactoryMessage, nativeTokenMessage, nameServiceMessage, validatorsMessage]
137
141
 
138
- contracts = await Promise.all(
139
- contracts.map(async (contract) => {
140
- contract = await new ContractMessage(new Uint8Array(contract.split(',')))
141
- await _.runContract({ decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash() })
142
- return contract
143
- })
144
- )
142
+ contracts = await Promise.all(
143
+ contracts.map(async (contract) => {
144
+ contract = await new ContractMessage(new Uint8Array(contract.split(',')))
145
+ await _.runContract({ decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash() })
146
+ return contract
147
+ })
148
+ )
149
+ }
145
150
 
146
151
  if (message.blocks?.length > 0) {
147
152
  let pre
@@ -176,7 +181,7 @@ _.init = async (message) => {
176
181
  latestTransactions.splice(-(transactionCount - 1), latestTransactions.length)
177
182
  }
178
183
 
179
- if (!block.loaded) {
184
+ if (!block.loaded && !fromState) {
180
185
  const priority = block.transactions.filter((transaction) => transaction.priority)
181
186
  if (priority.length > 0)
182
187
  await Promise.all(
@@ -281,7 +286,7 @@ worker.onmessage(({ id, type, input }) => {
281
286
  respond(id, blocks[input - 1])
282
287
  break
283
288
  case 'lastBlock':
284
- respond(id, blocks[blocks.length - 1])
289
+ respond(id, blocks[blocks.length - 1] || lastBlock)
285
290
  break
286
291
  case 'latestTransactions':
287
292
  respond(id, latestTransactions)