@leofcoin/chain 1.5.62 → 1.5.64
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/exports/browser/{_polyfill-node.child_process-JsWeMPst.js → _polyfill-node.child_process-rc1HO9Xs.js} +46 -47
- package/exports/browser/{_polyfill-node.url-0PWARF9f.js → _polyfill-node.url-1q06MepH.js} +1 -1
- package/exports/browser/{browser-dc41c03f-8RoAu8QY.js → browser-1GyRaZxg-C9SpI6hG.js} +2 -2
- package/exports/browser/chain.js +98 -62
- package/exports/browser/{client-f193279c-xoTAp1Bg.js → client-UOCjJBGl-pbv-pTHd.js} +18 -14
- package/exports/browser/{index-fd97ecae-DMIypRPM.js → index-K4Kwju30-vS3fNpxy.js} +2 -2
- package/exports/browser/{index-81687e93-rKzKdyEa.js → index-ub31QSed-EMPr2oeb.js} +2 -2
- package/exports/browser/{messages-cccb78db-bQaa1gST.js → messages-guyZfse6-JeAlT5Nb.js} +2 -2
- package/exports/browser/{node-browser-cqEqYlW7.js → node-browser-0Ly80awM.js} +625 -609
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +1 -4
- package/exports/browser/workers/machine-worker.js +61 -34
- package/exports/browser/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
- package/exports/chain.d.ts +1 -0
- package/exports/chain.js +63 -52
- package/exports/workers/block-worker.js +1 -4
- package/exports/workers/machine-worker.js +61 -34
- package/exports/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
- package/package.json +4 -3
- /package/exports/browser/{browser-2c73e2ef-AyxSBUXj.js → browser-AyxSBUXj-AyxSBUXj.js} +0 -0
- /package/exports/browser/{qr-scanner-worker.min-c002e984-RaSiJc_R.js → qr-scanner-worker.min-RaSiJc_R-RaSiJc_R.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
2
|
-
import './_polyfill-node.child_process-
|
|
1
|
+
export { N as default } from './node-browser-0Ly80awM.js';
|
|
2
|
+
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EasyWorker, B as BigNumber, a as BlockMessage
|
|
1
|
+
import { E as EasyWorker, B as BigNumber, a as BlockMessage } from './worker-hbo9s9AT.js';
|
|
2
2
|
|
|
3
3
|
const worker = new EasyWorker();
|
|
4
4
|
|
|
@@ -18,9 +18,6 @@ const run = async (blocks) => {
|
|
|
18
18
|
const size = block.encoded.length || block.encoded.byteLength;
|
|
19
19
|
const hash = await block.hash();
|
|
20
20
|
const index = block.decoded.index;
|
|
21
|
-
console.log(`loaded block: ${hash} @${index} ${formatBytes(size)}`);
|
|
22
|
-
// todo we don't want this, need shared state
|
|
23
|
-
block.decoded.transactions = block.decoded.transactions.sort((a, b) => a.nonce - b.nonce);
|
|
24
21
|
resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } });
|
|
25
22
|
})
|
|
26
23
|
)
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import { E as EasyWorker, B as BigNumber,
|
|
1
|
+
import { E as EasyWorker, B as BigNumber, C as ContractMessage, T as TransactionMessage } from './worker-hbo9s9AT.js';
|
|
2
|
+
|
|
3
|
+
const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
4
|
+
const formatBytes = (bytes, decimals = 2) => {
|
|
5
|
+
if (bytes === 0)
|
|
6
|
+
return '0 Bytes';
|
|
7
|
+
if (decimals < 0)
|
|
8
|
+
decimals = 0;
|
|
9
|
+
const k = 1024;
|
|
10
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
11
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`;
|
|
12
|
+
};
|
|
2
13
|
|
|
3
14
|
var contractFactory = "237,198,141,3,53,89,84,113,122,116,99,109,98,57,68,110,99,114,50,116,116,57,77,100,50,104,77,84,106,107,102,72,56,50,68,57,116,118,119,76,106,76,55,78,98,117,67,118,72,111,100,51,114,98,115,70,71,117,173,5,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,48,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,105,115,82,101,103,105,115,116,101,114,101,100,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,34,104,97,115,82,111,108,101,34,44,91,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,93,41,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,2,91,93";
|
|
4
15
|
var nativeToken$2 = "237,198,141,3,53,89,84,113,122,116,99,109,98,57,68,110,99,114,50,116,116,57,77,100,50,104,77,84,106,107,102,72,56,50,68,57,116,118,119,76,106,76,55,78,98,117,67,118,72,111,100,51,114,98,115,70,71,117,163,26,99,108,97,115,115,32,82,111,108,101,115,123,35,114,111,108,101,115,61,123,79,87,78,69,82,58,91,93,44,77,73,78,84,58,91,93,44,66,85,82,78,58,91,93,125,59,99,111,110,115,116,114,117,99,116,111,114,40,114,111,108,101,115,41,123,105,102,40,114,111,108,101,115,41,123,105,102,40,33,40,114,111,108,101,115,32,105,110,115,116,97,110,99,101,111,102,32,79,98,106,101,99,116,41,41,116,104,114,111,119,32,110,101,119,32,84,121,112,101,69,114,114,111,114,40,34,101,120,112,101,99,116,101,100,32,114,111,108,101,115,32,116,111,32,98,101,32,97,110,32,111,98,106,101,99,116,34,41,59,116,104,105,115,46,35,114,111,108,101,115,61,123,46,46,46,114,111,108,101,115,44,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,101,108,115,101,32,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,114,111,108,101,115,58,116,104,105,115,46,114,111,108,101,115,125,125,103,101,116,32,114,111,108,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,114,101,116,117,114,110,33,33,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,38,38,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,103,114,97,110,116,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,114,101,118,111,107,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,105,102,40,34,79,87,78,69,82,34,61,61,61,114,111,108,101,38,38,49,61,61,61,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,108,101,110,103,116,104,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,116,108,101,97,115,116,32,111,110,101,32,111,119,110,101,114,32,105,115,32,110,101,101,100,101,100,33,34,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,115,112,108,105,99,101,40,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,100,101,120,79,102,40,97,100,100,114,101,115,115,41,41,125,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,34,79,87,78,69,82,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,78,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,125,99,108,97,115,115,32,84,111,107,101,110,32,101,120,116,101,110,100,115,32,82,111,108,101,115,123,35,110,97,109,101,59,35,115,121,109,98,111,108,59,35,104,111,108,100,101,114,115,61,48,59,35,98,97,108,97,110,99,101,115,61,123,125,59,35,97,112,112,114,111,118,97,108,115,61,123,125,59,35,100,101,99,105,109,97,108,115,61,49,56,59,35,116,111,116,97,108,83,117,112,112,108,121,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,59,99,111,110,115,116,114,117,99,116,111,114,40,110,97,109,101,44,115,121,109,98,111,108,44,100,101,99,105,109,97,108,115,61,49,56,44,115,116,97,116,101,41,123,105,102,40,33,110,97,109,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,97,109,101,32,117,110,100,101,102,105,110,101,100,34,41,59,105,102,40,33,115,121,109,98,111,108,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,115,121,109,98,111,108,32,117,110,100,101,102,105,110,101,100,34,41,59,115,117,112,101,114,40,115,116,97,116,101,63,46,114,111,108,101,115,41,44,116,104,105,115,46,35,110,97,109,101,61,110,97,109,101,44,116,104,105,115,46,35,115,121,109,98,111,108,61,115,121,109,98,111,108,44,116,104,105,115,46,35,100,101,99,105,109,97,108,115,61,100,101,99,105,109,97,108,115,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,104,111,108,100,101,114,115,58,116,104,105,115,46,104,111,108,100,101,114,115,44,98,97,108,97,110,99,101,115,58,116,104,105,115,46,98,97,108,97,110,99,101,115,44,97,112,112,114,111,118,97,108,115,58,123,46,46,46,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,125,44,116,111,116,97,108,83,117,112,112,108,121,58,116,104,105,115,46,116,111,116,97,108,83,117,112,112,108,121,125,125,103,101,116,32,116,111,116,97,108,83,117,112,112,108,121,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,115,121,109,98,111,108,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,115,121,109,98,111,108,125,103,101,116,32,104,111,108,100,101,114,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,104,111,108,100,101,114,115,125,103,101,116,32,98,97,108,97,110,99,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,98,97,108,97,110,99,101,115,125,125,109,105,110,116,40,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,77,73,78,84,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,61,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,46,97,100,100,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,98,117,114,110,40,102,114,111,109,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,34,66,85,82,78,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,110,111,116,32,97,108,108,111,119,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,61,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,46,115,117,98,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,102,114,111,109,44,97,109,111,117,110,116,41,125,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,124,124,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,60,97,109,111,117,110,116,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,109,111,117,110,116,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,34,41,125,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,123,34,48,120,48,48,34,61,61,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,116,111,72,101,120,83,116,114,105,110,103,40,41,63,116,104,105,115,46,35,104,111,108,100,101,114,115,45,61,49,58,34,48,120,48,48,34,33,61,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,116,111,72,101,120,83,116,114,105,110,103,40,41,38,38,34,48,120,48,48,34,61,61,61,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,46,116,111,72,101,120,83,116,114,105,110,103,40,41,38,38,40,116,104,105,115,46,35,104,111,108,100,101,114,115,43,61,49,41,125,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,97,100,100,114,101,115,115,44,97,109,111,117,110,116,41,123,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,124,124,40,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,41,59,99,111,110,115,116,32,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,59,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,97,100,100,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,125,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,97,100,100,114,101,115,115,44,97,109,111,117,110,116,41,123,99,111,110,115,116,32,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,59,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,115,117,98,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,125,98,97,108,97,110,99,101,79,102,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,125,115,101,116,65,112,112,114,111,118,97,108,40,111,112,101,114,97,116,111,114,44,97,109,111,117,110,116,41,123,99,111,110,115,116,32,111,119,110,101,114,61,109,115,103,46,115,101,110,100,101,114,59,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,124,124,40,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,61,123,125,41,44,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,91,111,112,101,114,97,116,111,114,93,61,97,109,111,117,110,116,125,97,112,112,114,111,118,101,100,40,111,119,110,101,114,44,111,112,101,114,97,116,111,114,44,97,109,111,117,110,116,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,91,111,112,101,114,97,116,111,114,93,61,61,61,97,109,111,117,110,116,125,116,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,97,109,111,117,110,116,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,44,116,104,105,115,46,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,102,114,111,109,44,97,109,111,117,110,116,41,44,116,104,105,115,46,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,125,99,108,97,115,115,32,65,114,116,79,110,108,105,110,101,32,101,120,116,101,110,100,115,32,84,111,107,101,110,123,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,117,112,101,114,40,34,65,114,116,79,110,108,105,110,101,34,44,34,65,82,84,34,44,49,56,44,115,116,97,116,101,41,125,125,114,101,116,117,114,110,32,65,114,116,79,110,108,105,110,101,59,2,91,93";
|
|
@@ -36,6 +47,7 @@ let nativeCalls = 0;
|
|
|
36
47
|
let nativeBurns = 0;
|
|
37
48
|
let nativeMints = 0;
|
|
38
49
|
let nativeTransfers = 0;
|
|
50
|
+
let totalTransactions = 0;
|
|
39
51
|
|
|
40
52
|
let blocks = [];
|
|
41
53
|
let contracts = {};
|
|
@@ -43,7 +55,7 @@ const _ = {};
|
|
|
43
55
|
|
|
44
56
|
globalThis.BigNumber = BigNumber;
|
|
45
57
|
|
|
46
|
-
let lastBlock = { index:
|
|
58
|
+
let lastBlock = { index: -1, hash: '0x0', previousHash: '0x0' };
|
|
47
59
|
|
|
48
60
|
const has = (address) => {
|
|
49
61
|
return contracts[address] ? true : false
|
|
@@ -111,6 +123,35 @@ const createMessage = (sender = globalThis.peerid) => {
|
|
|
111
123
|
}
|
|
112
124
|
};
|
|
113
125
|
|
|
126
|
+
const _executeTransaction = async (transaction) => {
|
|
127
|
+
const hash = await new TransactionMessage(transaction).hash();
|
|
128
|
+
if (latestTransactions.includes(hash)) {
|
|
129
|
+
throw new Error(`double transaction found: ${hash} in block ${block.index}`)
|
|
130
|
+
} else {
|
|
131
|
+
latestTransactions.push(hash);
|
|
132
|
+
const { from, to, method, params, nonce } = transaction;
|
|
133
|
+
globalThis.msg = createMessage(from);
|
|
134
|
+
|
|
135
|
+
await _.execute({ contract: to, method, params });
|
|
136
|
+
if (to === nativeToken) {
|
|
137
|
+
nativeCalls += 1;
|
|
138
|
+
if (method === 'burn') nativeBurns += 1;
|
|
139
|
+
if (method === 'mint') nativeMints += 1;
|
|
140
|
+
if (method === 'transfer') nativeTransfers += 1;
|
|
141
|
+
}
|
|
142
|
+
totalTransactions += 1;
|
|
143
|
+
|
|
144
|
+
worker.postMessage({
|
|
145
|
+
type: 'transactionLoaded',
|
|
146
|
+
result: {
|
|
147
|
+
hash,
|
|
148
|
+
from,
|
|
149
|
+
nonce: String(nonce)
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
114
155
|
_.init = async (message) => {
|
|
115
156
|
let { contracts, peerid } = message;
|
|
116
157
|
globalThis.peerid = peerid;
|
|
@@ -156,37 +197,20 @@ _.init = async (message) => {
|
|
|
156
197
|
const transactionCount = blocks[block.index - 1].transactions.length;
|
|
157
198
|
latestTransactions.splice(-(transactionCount - 1), latestTransactions.length);
|
|
158
199
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (method === 'burn') nativeBurns += 1;
|
|
174
|
-
if (method === 'mint') nativeMints += 1;
|
|
175
|
-
if (method === 'transfer') nativeTransfers += 1;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
worker.postMessage({
|
|
179
|
-
type: 'transactionLoaded',
|
|
180
|
-
result: {
|
|
181
|
-
hash,
|
|
182
|
-
from,
|
|
183
|
-
nonce: String(nonce)
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
})
|
|
189
|
-
);
|
|
200
|
+
|
|
201
|
+
if (!block.loaded) {
|
|
202
|
+
const priority = block.transactions.filter((transaction) => transaction.priority);
|
|
203
|
+
if (priority.length > 0)
|
|
204
|
+
await Promise.all(
|
|
205
|
+
priority.sort((a, b) => a.nonce - b.nonce).map((transaction) => _executeTransaction(transaction))
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
await Promise.all(
|
|
209
|
+
block.transactions
|
|
210
|
+
.filter((transaction) => !transaction.priority)
|
|
211
|
+
.map(async (transaction) => _executeTransaction(transaction))
|
|
212
|
+
);
|
|
213
|
+
}
|
|
190
214
|
block.loaded = true;
|
|
191
215
|
worker.postMessage({
|
|
192
216
|
type: 'debug',
|
|
@@ -279,11 +303,14 @@ worker.onmessage(({ id, type, input }) => {
|
|
|
279
303
|
respond(id, blocks[input - 1]);
|
|
280
304
|
break
|
|
281
305
|
case 'lastBlock':
|
|
282
|
-
respond(id, blocks[blocks.length - 1]);
|
|
306
|
+
respond(id, blocks[blocks.length - 1] || lastBlock);
|
|
283
307
|
break
|
|
284
308
|
case 'latestTransactions':
|
|
285
309
|
respond(id, latestTransactions);
|
|
286
310
|
break
|
|
311
|
+
case 'totalTransactions':
|
|
312
|
+
respond(id, totalTransactions);
|
|
313
|
+
break
|
|
287
314
|
case 'has':
|
|
288
315
|
respond(id, has(input.address));
|
|
289
316
|
break
|
|
@@ -4127,17 +4127,6 @@ function throwFault(fault, operation, value) {
|
|
|
4127
4127
|
return logger.throwError(fault, Logger.errors.NUMERIC_FAULT, params);
|
|
4128
4128
|
}
|
|
4129
4129
|
|
|
4130
|
-
const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
4131
|
-
const formatBytes = (bytes, decimals = 2) => {
|
|
4132
|
-
if (bytes === 0)
|
|
4133
|
-
return '0 Bytes';
|
|
4134
|
-
if (decimals < 0)
|
|
4135
|
-
decimals = 0;
|
|
4136
|
-
const k = 1024;
|
|
4137
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
4138
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`;
|
|
4139
|
-
};
|
|
4140
|
-
|
|
4141
4130
|
// base-x encoding / decoding
|
|
4142
4131
|
// Copyright (c) 2018 base-x contributors
|
|
4143
4132
|
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
@@ -12441,56 +12430,55 @@ class ValidatorMessage extends FormatInterface {
|
|
|
12441
12430
|
}
|
|
12442
12431
|
|
|
12443
12432
|
var proto$1 = {
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12448
|
-
|
|
12449
|
-
|
|
12450
|
-
|
|
12433
|
+
index: Number(),
|
|
12434
|
+
previousHash: String(),
|
|
12435
|
+
timestamp: Number(),
|
|
12436
|
+
reward: BigNumber.from(0),
|
|
12437
|
+
fees: BigNumber.from(0),
|
|
12438
|
+
transactions: new Uint8Array(),
|
|
12439
|
+
validators: new Uint8Array()
|
|
12451
12440
|
};
|
|
12452
12441
|
|
|
12453
12442
|
class BlockMessage extends FormatInterface {
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
}
|
|
12443
|
+
get messageName() {
|
|
12444
|
+
return 'BlockMessage'
|
|
12445
|
+
}
|
|
12446
|
+
constructor(buffer) {
|
|
12447
|
+
if (buffer instanceof BlockMessage) return buffer
|
|
12448
|
+
const name = 'block-message';
|
|
12449
|
+
super(buffer, proto$1, { name });
|
|
12450
|
+
}
|
|
12451
|
+
encode(decoded) {
|
|
12452
|
+
decoded = decoded || this.decoded;
|
|
12453
|
+
const validators = [];
|
|
12454
|
+
const transactions = [];
|
|
12455
|
+
for (const validator of decoded.validators) {
|
|
12456
|
+
if (validator instanceof ValidatorMessage) validators.push(validator.encode());
|
|
12457
|
+
else validators.push(new ValidatorMessage(validator).encode());
|
|
12458
|
+
}
|
|
12459
|
+
for (const transaction of decoded.transactions) {
|
|
12460
|
+
if (transaction instanceof TransactionMessage) transactions.push(transaction.encode());
|
|
12461
|
+
else transactions.push(new TransactionMessage(transaction).encode());
|
|
12462
|
+
}
|
|
12463
|
+
return super.encode({
|
|
12464
|
+
...decoded,
|
|
12465
|
+
validators: index$5(validators),
|
|
12466
|
+
transactions: index$5(transactions)
|
|
12467
|
+
})
|
|
12468
|
+
}
|
|
12469
|
+
decode(encoded) {
|
|
12470
|
+
encoded = encoded || this.encoded;
|
|
12471
|
+
super.decode(encoded);
|
|
12472
|
+
// @ts-ignore
|
|
12473
|
+
this.decoded.transactions = index$4(this.decoded.transactions).map(
|
|
12474
|
+
(transaction) => new TransactionMessage(transaction).decoded
|
|
12475
|
+
);
|
|
12476
|
+
// @ts-ignore
|
|
12477
|
+
this.decoded.validators = index$4(this.decoded.validators).map(
|
|
12478
|
+
(validator) => new ValidatorMessage(validator).decoded
|
|
12479
|
+
);
|
|
12480
|
+
return this.decoded
|
|
12481
|
+
}
|
|
12494
12482
|
}
|
|
12495
12483
|
|
|
12496
12484
|
var proto = {
|
|
@@ -12597,4 +12585,4 @@ class EasyWorker {
|
|
|
12597
12585
|
}
|
|
12598
12586
|
}
|
|
12599
12587
|
|
|
12600
|
-
export { BigNumber as B, ContractMessage as C, EasyWorker as E, TransactionMessage as T, BlockMessage as a
|
|
12588
|
+
export { BigNumber as B, ContractMessage as C, EasyWorker as E, TransactionMessage as T, BlockMessage as a };
|
package/exports/chain.d.ts
CHANGED
package/exports/chain.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import '@vandeurenglenn/debug';
|
|
1
2
|
import { formatBytes, BigNumber, formatUnits, parseUnits } from '@leofcoin/utils';
|
|
2
3
|
import { TransactionMessage, BlockMessage, ContractMessage, BWMessage, BWRequestMessage } from '@leofcoin/messages';
|
|
3
4
|
import addresses, { contractFactory, nativeToken, validators, nameService } from '@leofcoin/addresses';
|
|
@@ -270,6 +271,7 @@ class Contract extends Transaction {
|
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
// import State from './state'
|
|
274
|
+
const debug$2 = globalThis.createDebugger('leofcoin/machine');
|
|
273
275
|
class Machine {
|
|
274
276
|
#contracts = {};
|
|
275
277
|
#nonces = {};
|
|
@@ -309,7 +311,7 @@ class Machine {
|
|
|
309
311
|
break;
|
|
310
312
|
}
|
|
311
313
|
case 'debug': {
|
|
312
|
-
|
|
314
|
+
debug$2(data.message);
|
|
313
315
|
break;
|
|
314
316
|
}
|
|
315
317
|
case 'error': {
|
|
@@ -584,6 +586,7 @@ class Jobber {
|
|
|
584
586
|
}
|
|
585
587
|
}
|
|
586
588
|
|
|
589
|
+
const debug$1 = globalThis.createDebugger('leofcoin/state');
|
|
587
590
|
class State extends Contract {
|
|
588
591
|
#resolveErrored;
|
|
589
592
|
#lastResolvedTime;
|
|
@@ -680,7 +683,7 @@ class State extends Contract {
|
|
|
680
683
|
this.#getLastTransactions = async () => {
|
|
681
684
|
let lastTransactions = (await Promise.all((await this.blocks)
|
|
682
685
|
.filter((block) => block.loaded)
|
|
683
|
-
.slice(-
|
|
686
|
+
.slice(-24)
|
|
684
687
|
.map((block) => this.#loadBlockTransactions(block.transactions)))).reduce((all, transactions) => [...all, ...transactions], []);
|
|
685
688
|
return Promise.all(lastTransactions.map((transaction) => transaction.hash()));
|
|
686
689
|
};
|
|
@@ -738,10 +741,15 @@ class State extends Contract {
|
|
|
738
741
|
}
|
|
739
742
|
}
|
|
740
743
|
async updateState(message) {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
744
|
+
try {
|
|
745
|
+
const hash = await message.hash();
|
|
746
|
+
// await this.state.updateState(message)
|
|
747
|
+
await globalThis.chainStore.put('lastBlock', hash);
|
|
748
|
+
globalThis.pubsub.publish('lastBlock', message.encoded);
|
|
749
|
+
}
|
|
750
|
+
catch (error) {
|
|
751
|
+
console.error(error);
|
|
752
|
+
}
|
|
745
753
|
}
|
|
746
754
|
getLatestBlock() {
|
|
747
755
|
// @ts-ignore
|
|
@@ -777,7 +785,7 @@ class State extends Contract {
|
|
|
777
785
|
this.#totalSize += size;
|
|
778
786
|
this.#blocks[index - 1] = { hash, ...block.decoded };
|
|
779
787
|
this.#blockHashMap.set(hash, index);
|
|
780
|
-
|
|
788
|
+
debug$1(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
|
|
781
789
|
globalThis.pubsub.publish('block-resolved', { hash, index });
|
|
782
790
|
this.#lastResolved = this.#blocks[index - 1];
|
|
783
791
|
this.#lastResolvedTime = Date.now();
|
|
@@ -915,7 +923,7 @@ class State extends Contract {
|
|
|
915
923
|
await this.resolveBlock(lastBlock.hash);
|
|
916
924
|
console.log('ok');
|
|
917
925
|
let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
|
|
918
|
-
|
|
926
|
+
debug$1(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
919
927
|
const blocks = this.#blocks;
|
|
920
928
|
const start = blocks.length - blocksSynced;
|
|
921
929
|
if (this.#machine) {
|
|
@@ -1047,7 +1055,7 @@ class State extends Contract {
|
|
|
1047
1055
|
this.#blocks[block.index - 1].loaded = true;
|
|
1048
1056
|
await this.#machine.addLoadedBlock(block);
|
|
1049
1057
|
// @ts-ignore
|
|
1050
|
-
|
|
1058
|
+
debug$1(`loaded block: ${block.hash} @${block.index}`);
|
|
1051
1059
|
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
1052
1060
|
}
|
|
1053
1061
|
}
|
|
@@ -1058,7 +1066,7 @@ class State extends Contract {
|
|
|
1058
1066
|
return new Promise(async (resolve, reject) => {
|
|
1059
1067
|
const timeout = setTimeout(() => {
|
|
1060
1068
|
resolve([{ index: 0, hash: '0x0' }]);
|
|
1061
|
-
|
|
1069
|
+
debug$1('sync timed out');
|
|
1062
1070
|
}, this.requestTimeout);
|
|
1063
1071
|
promises = await Promise.allSettled(promises);
|
|
1064
1072
|
promises = promises.filter(({ status }) => status === 'fulfilled');
|
|
@@ -1142,7 +1150,7 @@ class VersionControl extends State {
|
|
|
1142
1150
|
}
|
|
1143
1151
|
|
|
1144
1152
|
globalThis.BigNumber = BigNumber;
|
|
1145
|
-
const
|
|
1153
|
+
const debug = globalThis.createDebugger('leofcoin/chain');
|
|
1146
1154
|
// check if browser or local
|
|
1147
1155
|
class Chain extends VersionControl {
|
|
1148
1156
|
#state;
|
|
@@ -1169,7 +1177,7 @@ class Chain extends VersionControl {
|
|
|
1169
1177
|
const transaction = new TransactionMessage(message);
|
|
1170
1178
|
await transaction.hash();
|
|
1171
1179
|
// if (await transactionPoolStore.has(hash)) await transactionPoolStore.delete(hash)
|
|
1172
|
-
|
|
1180
|
+
debug(`added ${transaction}`);
|
|
1173
1181
|
};
|
|
1174
1182
|
// @ts-ignore
|
|
1175
1183
|
return this.#init();
|
|
@@ -1292,7 +1300,6 @@ class Chain extends VersionControl {
|
|
|
1292
1300
|
const transactionsToGet = [];
|
|
1293
1301
|
for (const key of transactionsInPool) {
|
|
1294
1302
|
!transactions.includes(key) &&
|
|
1295
|
-
!ignorelist.includes(key) &&
|
|
1296
1303
|
transactionsToGet.push(transactionPoolStore.put(key, await peernet.get(key, 'transaction')));
|
|
1297
1304
|
}
|
|
1298
1305
|
return Promise.all(transactionsToGet);
|
|
@@ -1301,7 +1308,10 @@ class Chain extends VersionControl {
|
|
|
1301
1308
|
const peer = peernet.getConnection(peerId);
|
|
1302
1309
|
// todo handle version changes
|
|
1303
1310
|
// for now just do nothing if version doesn't match
|
|
1304
|
-
|
|
1311
|
+
debug(`peer connected with version ${peer.version}`);
|
|
1312
|
+
if (peer.version !== this.version) {
|
|
1313
|
+
debug(`versions don't match`);
|
|
1314
|
+
}
|
|
1305
1315
|
if (!peer.version || peer.version !== this.version)
|
|
1306
1316
|
return;
|
|
1307
1317
|
const lastBlock = await this.#makeRequest(peer, 'lastBlock');
|
|
@@ -1344,7 +1354,6 @@ class Chain extends VersionControl {
|
|
|
1344
1354
|
}
|
|
1345
1355
|
}
|
|
1346
1356
|
async #addBlock(block) {
|
|
1347
|
-
console.log({ block });
|
|
1348
1357
|
const blockMessage = await new BlockMessage(block);
|
|
1349
1358
|
const hash = await blockMessage.hash();
|
|
1350
1359
|
await Promise.all(blockMessage.decoded.transactions
|
|
@@ -1361,7 +1370,7 @@ class Chain extends VersionControl {
|
|
|
1361
1370
|
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
1362
1371
|
if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
|
|
1363
1372
|
await this.updateState(blockMessage);
|
|
1364
|
-
|
|
1373
|
+
debug(`added block: ${hash}`);
|
|
1365
1374
|
let promises = [];
|
|
1366
1375
|
let contracts = [];
|
|
1367
1376
|
for (let transaction of blockMessage.decoded.transactions) {
|
|
@@ -1419,16 +1428,41 @@ class Chain extends VersionControl {
|
|
|
1419
1428
|
if ((await this.hasTransactionToHandle()) && !this.#runningEpoch && this.#participating)
|
|
1420
1429
|
await this.#runEpoch();
|
|
1421
1430
|
}
|
|
1431
|
+
async #handleTransaction(transaction, latestTransactions, block) {
|
|
1432
|
+
const hash = await transaction.hash();
|
|
1433
|
+
const doubleTransactions = [];
|
|
1434
|
+
if (latestTransactions.includes(hash)) {
|
|
1435
|
+
doubleTransactions.push(hash);
|
|
1436
|
+
}
|
|
1437
|
+
if (doubleTransactions.length > 0) {
|
|
1438
|
+
await globalThis.transactionPoolStore.delete(hash);
|
|
1439
|
+
await globalThis.peernet.publish('invalid-transaction', hash);
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
// if (timestamp + this.#slotTime > Date.now()) {
|
|
1443
|
+
try {
|
|
1444
|
+
const result = await this.#executeTransaction({ ...transaction.decoded, hash });
|
|
1445
|
+
block.transactions.push(transaction);
|
|
1446
|
+
block.fees = block.fees.add(await calculateFee(transaction.decoded));
|
|
1447
|
+
await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
|
|
1448
|
+
}
|
|
1449
|
+
catch (e) {
|
|
1450
|
+
console.log('vvvvvv');
|
|
1451
|
+
console.log({ e });
|
|
1452
|
+
console.log(hash);
|
|
1453
|
+
peernet.publish('invalid-transaction', hash);
|
|
1454
|
+
console.log(await globalThis.transactionPoolStore.keys());
|
|
1455
|
+
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
1456
|
+
await globalThis.transactionPoolStore.delete(e.hash);
|
|
1457
|
+
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1422
1460
|
// todo filter tx that need to wait on prev nonce
|
|
1423
1461
|
async #createBlock(limit = this.transactionLimit) {
|
|
1424
1462
|
// vote for transactions
|
|
1425
1463
|
if ((await globalThis.transactionPoolStore.size()) === 0)
|
|
1426
1464
|
return;
|
|
1427
1465
|
let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
|
|
1428
|
-
for (const hash of await globalThis.transactionPoolStore.keys()) {
|
|
1429
|
-
if (ignorelist.includes(hash))
|
|
1430
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1431
|
-
}
|
|
1432
1466
|
if (Object.keys(transactions)?.length === 0)
|
|
1433
1467
|
return;
|
|
1434
1468
|
const timestamp = Date.now();
|
|
@@ -1441,39 +1475,16 @@ class Chain extends VersionControl {
|
|
|
1441
1475
|
reward: parseUnits('150'),
|
|
1442
1476
|
index: 0
|
|
1443
1477
|
};
|
|
1478
|
+
const latestTransactions = await this.machine.latestTransactions();
|
|
1444
1479
|
// exclude failing tx
|
|
1445
1480
|
transactions = await this.promiseTransactions(transactions);
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
}
|
|
1454
|
-
if (doubleTransactions.length > 0) {
|
|
1455
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
1456
|
-
await globalThis.peernet.publish('invalid-transaction', hash);
|
|
1457
|
-
return;
|
|
1458
|
-
}
|
|
1459
|
-
// if (timestamp + this.#slotTime > Date.now()) {
|
|
1460
|
-
try {
|
|
1461
|
-
const result = await this.#executeTransaction({ ...transaction.decoded, hash });
|
|
1462
|
-
block.transactions.push(transaction);
|
|
1463
|
-
block.fees = block.fees.add(await calculateFee(transaction.decoded));
|
|
1464
|
-
await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
|
|
1465
|
-
}
|
|
1466
|
-
catch (e) {
|
|
1467
|
-
console.log('vvvvvv');
|
|
1468
|
-
console.log({ e });
|
|
1469
|
-
console.log(hash);
|
|
1470
|
-
peernet.publish('invalid-transaction', hash);
|
|
1471
|
-
console.log(await globalThis.transactionPoolStore.keys());
|
|
1472
|
-
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
1473
|
-
await globalThis.transactionPoolStore.delete(e.hash);
|
|
1474
|
-
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1481
|
+
const priority = transactions.filter((transaction) => transaction.priority);
|
|
1482
|
+
await Promise.all(priority
|
|
1483
|
+
.sort((a, b) => a.nonce - b.nonce)
|
|
1484
|
+
.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
1485
|
+
await Promise.all(transactions
|
|
1486
|
+
.filter((transaction) => !transaction.priority)
|
|
1487
|
+
.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
1477
1488
|
// don't add empty block
|
|
1478
1489
|
if (block.transactions.length === 0)
|
|
1479
1490
|
return;
|
|
@@ -1540,7 +1551,7 @@ class Chain extends VersionControl {
|
|
|
1540
1551
|
await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
|
|
1541
1552
|
await this.updateState(blockMessage);
|
|
1542
1553
|
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
1543
|
-
|
|
1554
|
+
debug(`created block: ${hash} @${block.index}`);
|
|
1544
1555
|
globalThis.peernet.publish('add-block', blockMessage.encoded);
|
|
1545
1556
|
globalThis.pubsub.publish('add-block', blockMessage.decoded);
|
|
1546
1557
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EasyWorker, B as BigNumber, a as BlockMessage
|
|
1
|
+
import { E as EasyWorker, B as BigNumber, a as BlockMessage } from './worker-hbo9s9AT.js';
|
|
2
2
|
|
|
3
3
|
const worker = new EasyWorker();
|
|
4
4
|
|
|
@@ -18,9 +18,6 @@ const run = async (blocks) => {
|
|
|
18
18
|
const size = block.encoded.length || block.encoded.byteLength;
|
|
19
19
|
const hash = await block.hash();
|
|
20
20
|
const index = block.decoded.index;
|
|
21
|
-
console.log(`loaded block: ${hash} @${index} ${formatBytes(size)}`);
|
|
22
|
-
// todo we don't want this, need shared state
|
|
23
|
-
block.decoded.transactions = block.decoded.transactions.sort((a, b) => a.nonce - b.nonce);
|
|
24
21
|
resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } });
|
|
25
22
|
})
|
|
26
23
|
)
|