@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.
Files changed (21) hide show
  1. package/exports/browser/{_polyfill-node.child_process-JsWeMPst.js → _polyfill-node.child_process-rc1HO9Xs.js} +46 -47
  2. package/exports/browser/{_polyfill-node.url-0PWARF9f.js → _polyfill-node.url-1q06MepH.js} +1 -1
  3. package/exports/browser/{browser-dc41c03f-8RoAu8QY.js → browser-1GyRaZxg-C9SpI6hG.js} +2 -2
  4. package/exports/browser/chain.js +98 -62
  5. package/exports/browser/{client-f193279c-xoTAp1Bg.js → client-UOCjJBGl-pbv-pTHd.js} +18 -14
  6. package/exports/browser/{index-fd97ecae-DMIypRPM.js → index-K4Kwju30-vS3fNpxy.js} +2 -2
  7. package/exports/browser/{index-81687e93-rKzKdyEa.js → index-ub31QSed-EMPr2oeb.js} +2 -2
  8. package/exports/browser/{messages-cccb78db-bQaa1gST.js → messages-guyZfse6-JeAlT5Nb.js} +2 -2
  9. package/exports/browser/{node-browser-cqEqYlW7.js → node-browser-0Ly80awM.js} +625 -609
  10. package/exports/browser/node-browser.js +2 -2
  11. package/exports/browser/workers/block-worker.js +1 -4
  12. package/exports/browser/workers/machine-worker.js +61 -34
  13. package/exports/browser/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
  14. package/exports/chain.d.ts +1 -0
  15. package/exports/chain.js +63 -52
  16. package/exports/workers/block-worker.js +1 -4
  17. package/exports/workers/machine-worker.js +61 -34
  18. package/exports/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
  19. package/package.json +4 -3
  20. /package/exports/browser/{browser-2c73e2ef-AyxSBUXj.js → browser-AyxSBUXj-AyxSBUXj.js} +0 -0
  21. /package/exports/browser/{qr-scanner-worker.min-c002e984-RaSiJc_R.js → qr-scanner-worker.min-RaSiJc_R-RaSiJc_R.js} +0 -0
@@ -1,4 +1,15 @@
1
- import { E as EasyWorker, B as BigNumber, f as formatBytes, C as ContractMessage, T as TransactionMessage } from './worker-Suy0gj0S.js';
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: 0, hash: '0x0', previousHash: '0x0' };
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
- await Promise.all(
160
- block.transactions.map(async (transaction) => {
161
- if (!block.loaded) {
162
- const hash = await new TransactionMessage(transaction).hash();
163
- if (latestTransactions.includes(hash)) {
164
- throw new Error(`double transaction found: ${hash} in block ${block.index}`)
165
- } else {
166
- latestTransactions.push(hash);
167
- const { from, to, method, params, nonce } = transaction;
168
- globalThis.msg = createMessage(from);
169
-
170
- await _.execute({ contract: to, method, params });
171
- if (to === nativeToken) {
172
- nativeCalls += 1;
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
- index: Number(),
12445
- previousHash: String(),
12446
- timestamp: Number(),
12447
- reward: BigNumber.from(0),
12448
- fees: BigNumber.from(0),
12449
- transactions: new Uint8Array(),
12450
- validators: new Uint8Array()
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
- get messageName() {
12455
- return 'BlockMessage';
12456
- }
12457
- constructor(buffer) {
12458
- if (buffer instanceof BlockMessage)
12459
- return buffer;
12460
- const name = 'block-message';
12461
- super(buffer, proto$1, { name });
12462
- }
12463
- encode(decoded) {
12464
- decoded = decoded || this.decoded;
12465
- const validators = [];
12466
- const transactions = [];
12467
- for (const validator of decoded.validators) {
12468
- if (validator instanceof ValidatorMessage)
12469
- validators.push(validator.encode());
12470
- else
12471
- validators.push(new ValidatorMessage(validator).encode());
12472
- }
12473
- for (const transaction of decoded.transactions) {
12474
- if (transaction instanceof TransactionMessage)
12475
- transactions.push(transaction.encode());
12476
- else
12477
- transactions.push(new TransactionMessage(transaction).encode());
12478
- }
12479
- return super.encode({
12480
- ...decoded,
12481
- validators: index$5(validators),
12482
- transactions: index$5(transactions)
12483
- });
12484
- }
12485
- decode(encoded) {
12486
- encoded = encoded || this.encoded;
12487
- super.decode(encoded);
12488
- // @ts-ignore
12489
- this.decoded.transactions = index$4(this.decoded.transactions).map((transaction) => new TransactionMessage(transaction).decoded);
12490
- // @ts-ignore
12491
- this.decoded.validators = index$4(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
12492
- return this.decoded;
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, formatBytes as f };
12588
+ export { BigNumber as B, ContractMessage as C, EasyWorker as E, TransactionMessage as T, BlockMessage as a };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.62",
3
+ "version": "1.5.64",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": {
@@ -57,7 +57,7 @@
57
57
  "@types/randombytes": "^2.0.0",
58
58
  "@types/semver": "^7.5.6",
59
59
  "@types/varint": "^6.0.1",
60
- "@vandeurenglenn/debug": "^1.0.0",
60
+ "@vandeurenglenn/debug": "^1.1.1",
61
61
  "eslint": "^8.28.0",
62
62
  "eslint-plugin-unicorn": "^45.0.0",
63
63
  "open": "^8.4.0",
@@ -79,12 +79,13 @@
79
79
  "@leofcoin/messages": "^1.3.17",
80
80
  "@leofcoin/multi-wallet": "^2.1.1",
81
81
  "@leofcoin/networks": "^1.0.0",
82
- "@leofcoin/peernet": "^1.1.37",
82
+ "@leofcoin/peernet": "^1.1.73",
83
83
  "@leofcoin/peernet-swarm": "^1.0.0",
84
84
  "@leofcoin/storage": "^3.0.6",
85
85
  "@leofcoin/utils": "^1.1.4",
86
86
  "@leofcoin/workers": "^1.3.13",
87
87
  "@netpeer/p2pt-swarm": "^1.3.5",
88
+ "@netpeer/swarm": "^0.8.9",
88
89
  "@vandeurenglenn/base32": "^1.1.0",
89
90
  "@vandeurenglenn/easy-worker": "^1.0.2",
90
91
  "@vandeurenglenn/queue": "^1.0.0",