@leofcoin/workers 1.3.12 → 1.3.14

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.3.12",
3
+ "version": "1.3.14",
4
4
  "description": "Workers used in @leofcoin/chain",
5
5
  "type": "module",
6
6
  "exports": {
package/src/log-worker.ts CHANGED
@@ -23,7 +23,7 @@ declare type messageReturn = {
23
23
 
24
24
  const handlePut = async message => {
25
25
  try {
26
- await fetch(`http://localhost:8080/log/put`, {
26
+ await fetch(`http://localhost:8844/log/put`, {
27
27
  method: 'put',
28
28
  body: message
29
29
  })
@@ -34,7 +34,7 @@ const handlePut = async message => {
34
34
 
35
35
  const handleGet = async message => {
36
36
  try {
37
- await fetch(`http://localhost:8080/log/get?`, {
37
+ await fetch(`http://localhost:8844/log/get?`, {
38
38
  method: 'put',
39
39
  body: message
40
40
  })
@@ -67,7 +67,13 @@ const execute = async (contract, method, params) => {
67
67
  // state.put(result)
68
68
  return result
69
69
  } catch (e) {
70
- throw e
70
+ throw new Error(
71
+ `error: ${e.message}
72
+ contract: ${contract}
73
+ method: ${method}
74
+ params: ${JSON.stringify(params, null, '\t')}
75
+ `
76
+ )
71
77
  }
72
78
  }
73
79
 
@@ -99,7 +105,18 @@ const _init = async ({ contracts, blocks, peerid })=> {
99
105
  let lastBlock = {hash: '0x0'};
100
106
 
101
107
  if (blocks?.length > 0) {
102
- const _worker = await new EasyWorker('node_modules/@leofcoin/workers/src/block-worker.js', {serialization: 'advanced', type: 'module' })
108
+ let pre
109
+
110
+ try {
111
+ const importee = await import('url')
112
+ const url = importee.default
113
+ if (url) pre = url.fileURLToPath(new URL('.', import.meta.url));
114
+ } catch {
115
+ // browser env
116
+ pre = './'
117
+ }
118
+
119
+ const _worker = await new EasyWorker(pre + '@leofcoin/workers/block-worker.js', {serialization: 'advanced', type: 'module' })
103
120
  blocks = await _worker.once([blocks[blocks.length - 1]])
104
121
 
105
122
  // blocks = unique(globalThis.blocks ? globalThis : [], blocks)