@leofcoin/chain 1.5.57 → 1.5.58
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/browser-store.js +1 -26
- package/exports/browser/chain.js +82 -78
- package/exports/browser/workers/block-worker.js +1 -1
- package/exports/browser/workers/machine-worker.js +144 -163
- package/exports/chain.js +82 -78
- package/exports/machine.d.ts +12 -10
- package/exports/state.d.ts +9 -7
- package/exports/types.d.ts +33 -0
- package/exports/workers/block-worker.js +1 -1
- package/exports/workers/machine-worker.js +144 -163
- package/package.json +1 -1
- package/exports/typer.d.ts +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EasyWorker, B as BigNumber, f as formatBytes, C as ContractMessage, T as TransactionMessage
|
|
1
|
+
import { E as EasyWorker, B as BigNumber, f as formatBytes, C as ContractMessage, T as TransactionMessage } from './worker-Suy0gj0S.js';
|
|
2
2
|
|
|
3
3
|
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
4
|
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";
|
|
@@ -29,20 +29,27 @@ const contractFactoryMessage = bytecodes.contractFactory;
|
|
|
29
29
|
const nativeTokenMessage = bytecodes.nativeToken;
|
|
30
30
|
const nameServiceMessage = bytecodes.nameService;
|
|
31
31
|
const validatorsMessage = bytecodes.validators;
|
|
32
|
+
|
|
33
|
+
const latestTransactions = [];
|
|
34
|
+
|
|
32
35
|
let nativeCalls = 0;
|
|
33
36
|
let nativeBurns = 0;
|
|
34
37
|
let nativeMints = 0;
|
|
35
38
|
let nativeTransfers = 0;
|
|
36
|
-
|
|
39
|
+
|
|
40
|
+
let blocks = [];
|
|
41
|
+
let contracts = {};
|
|
42
|
+
const _ = {};
|
|
37
43
|
|
|
38
44
|
globalThis.BigNumber = BigNumber;
|
|
39
|
-
|
|
45
|
+
|
|
46
|
+
let lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
40
47
|
|
|
41
48
|
const has = (address) => {
|
|
42
49
|
return contracts[address] ? true : false
|
|
43
50
|
};
|
|
44
51
|
|
|
45
|
-
const get = (contract, method, params) => {
|
|
52
|
+
const get = ({ contract, method, params }) => {
|
|
46
53
|
let result;
|
|
47
54
|
if (params?.length > 0) {
|
|
48
55
|
result = contracts[contract][method](...params);
|
|
@@ -52,7 +59,7 @@ const get = (contract, method, params) => {
|
|
|
52
59
|
return result
|
|
53
60
|
};
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
_.runContract = async ({ decoded, hash, encoded }) => {
|
|
56
63
|
const params = decoded.constructorParameters;
|
|
57
64
|
try {
|
|
58
65
|
const func = new Function(new TextDecoder().decode(decoded.contract));
|
|
@@ -74,7 +81,7 @@ const runContract = async ({ decoded, hash, encoded }) => {
|
|
|
74
81
|
}
|
|
75
82
|
};
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
_.execute = async ({ contract, method, params }) => {
|
|
78
85
|
try {
|
|
79
86
|
let result;
|
|
80
87
|
// don't execute the method on a proxy
|
|
@@ -99,26 +106,25 @@ const execute = async (contract, method, params) => {
|
|
|
99
106
|
const createMessage = (sender = globalThis.peerid) => {
|
|
100
107
|
return {
|
|
101
108
|
sender,
|
|
102
|
-
call: execute,
|
|
109
|
+
call: _.execute,
|
|
103
110
|
staticCall: get
|
|
104
111
|
}
|
|
105
112
|
};
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
_.init = async (message) => {
|
|
115
|
+
let { contracts, peerid } = message;
|
|
108
116
|
globalThis.peerid = peerid;
|
|
109
117
|
contracts = [contractFactoryMessage, nativeTokenMessage, nameServiceMessage, validatorsMessage];
|
|
110
118
|
|
|
111
119
|
contracts = await Promise.all(
|
|
112
120
|
contracts.map(async (contract) => {
|
|
113
121
|
contract = await new ContractMessage(new Uint8Array(contract.split(',')));
|
|
114
|
-
await runContract({ decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash() });
|
|
122
|
+
await _.runContract({ decoded: contract.decoded, encoded: contract.encoded, hash: await contract.hash() });
|
|
115
123
|
return contract
|
|
116
124
|
})
|
|
117
125
|
);
|
|
118
126
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (blocks?.length > 0) {
|
|
127
|
+
if (message.blocks?.length > 0) {
|
|
122
128
|
let pre;
|
|
123
129
|
|
|
124
130
|
try {
|
|
@@ -134,68 +140,65 @@ const _init = async ({ contracts, blocks, peerid }) => {
|
|
|
134
140
|
serialization: 'advanced',
|
|
135
141
|
type: 'module'
|
|
136
142
|
});
|
|
137
|
-
blocks = await _worker.once(blocks);
|
|
143
|
+
blocks = await _worker.once(message.blocks);
|
|
138
144
|
_worker = null;
|
|
139
145
|
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
140
146
|
// for (let i = 0; i < blocks.length; i++) {
|
|
141
147
|
|
|
142
148
|
// }
|
|
143
149
|
for (const block of blocks) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
// we only revalidate the latest 128 blocks
|
|
151
|
+
// every 128 blocks a snapshot is taken and stored in state
|
|
152
|
+
// this means contracts will be restored from this state
|
|
153
|
+
// this also means devs NEED to make sure the state can be restored
|
|
154
|
+
// on contract deploy an error will be thrown if state wasn't recoverable
|
|
155
|
+
if (block.index > 128) {
|
|
156
|
+
for (const transaction of blocks[block.index - 2].transactions) {
|
|
157
|
+
latestTransactions.splice(transaction, 1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
await Promise.all(
|
|
161
|
+
block.transactions.map(async (transaction) => {
|
|
162
|
+
if (!block.loaded) {
|
|
163
|
+
const hash = await new TransactionMessage(transaction).hash();
|
|
164
|
+
if (latestTransactions.includes(hash)) {
|
|
165
|
+
throw new Error(`double transaction found: ${hash} in block ${block.index}`)
|
|
166
|
+
} else {
|
|
167
|
+
latestTransactions.push(hash);
|
|
148
168
|
const { from, to, method, params, nonce } = transaction;
|
|
149
169
|
globalThis.msg = createMessage(from);
|
|
150
170
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (method === 'transfer') nativeTransfers += 1;
|
|
158
|
-
}
|
|
159
|
-
totalTransactions += 1;
|
|
160
|
-
|
|
161
|
-
worker.postMessage({
|
|
162
|
-
type: 'transactionLoaded',
|
|
163
|
-
result: {
|
|
164
|
-
hash: await new TransactionMessage(transaction).hash(),
|
|
165
|
-
from,
|
|
166
|
-
nonce: String(nonce)
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
} catch (error) {
|
|
170
|
-
throw error
|
|
171
|
+
await _.execute({ contract: to, method, params });
|
|
172
|
+
if (to === nativeToken) {
|
|
173
|
+
nativeCalls += 1;
|
|
174
|
+
if (method === 'burn') nativeBurns += 1;
|
|
175
|
+
if (method === 'mint') nativeMints += 1;
|
|
176
|
+
if (method === 'transfer') nativeTransfers += 1;
|
|
171
177
|
}
|
|
178
|
+
|
|
179
|
+
worker.postMessage({
|
|
180
|
+
type: 'transactionLoaded',
|
|
181
|
+
result: {
|
|
182
|
+
hash,
|
|
183
|
+
from,
|
|
184
|
+
nonce: String(nonce)
|
|
185
|
+
}
|
|
186
|
+
});
|
|
172
187
|
}
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
worker.postMessage({
|
|
184
|
-
type: 'error',
|
|
185
|
-
message: error.message
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
block.loaded = true;
|
|
192
|
+
worker.postMessage({
|
|
193
|
+
type: 'debug',
|
|
194
|
+
message: `loaded transactions for block: ${block.blockInfo.hash} @${block.blockInfo.index} ${formatBytes(
|
|
195
|
+
block.blockInfo.size
|
|
196
|
+
)}`
|
|
197
|
+
});
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
if (blocks.length > 0) {
|
|
191
201
|
lastBlock = blocks[blocks.length - 1];
|
|
192
|
-
// todo blocks already loaded as blockmessage so use it!
|
|
193
|
-
lastBlock = await new BlockMessage(lastBlock);
|
|
194
|
-
|
|
195
|
-
lastBlock = {
|
|
196
|
-
...lastBlock.decoded,
|
|
197
|
-
hash: await lastBlock.hash()
|
|
198
|
-
};
|
|
199
202
|
}
|
|
200
203
|
globalThis.blocks = blocks;
|
|
201
204
|
}
|
|
@@ -205,113 +208,91 @@ const _init = async ({ contracts, blocks, peerid }) => {
|
|
|
205
208
|
// worker.postMessage({blocks});
|
|
206
209
|
};
|
|
207
210
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
id
|
|
231
|
-
});
|
|
232
|
-
} else if (e.type === 'nativeMints') {
|
|
233
|
-
worker.postMessage({
|
|
234
|
-
type: 'response',
|
|
235
|
-
value: nativeMints,
|
|
236
|
-
id
|
|
237
|
-
});
|
|
238
|
-
} else if (e.type === 'nativeTransfers') {
|
|
239
|
-
worker.postMessage({
|
|
240
|
-
type: 'response',
|
|
241
|
-
value: nativeTransfers,
|
|
242
|
-
id
|
|
243
|
-
});
|
|
244
|
-
} else if (e.type === 'totalTransfers') {
|
|
211
|
+
_.addLoadedBlock = (block) => {
|
|
212
|
+
blocks[block.index - 1] = block;
|
|
213
|
+
return true
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
_.loadBlock = (block) => {
|
|
217
|
+
// todo validate here and deprecate addLoadedBlock
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const respond = (id, value) => {
|
|
221
|
+
worker.postMessage({
|
|
222
|
+
type: 'response',
|
|
223
|
+
value,
|
|
224
|
+
id
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const runTask = async (id, taskName, input) => {
|
|
229
|
+
try {
|
|
230
|
+
const result = await _[taskName](input);
|
|
231
|
+
respond(id, result);
|
|
232
|
+
} catch (e) {
|
|
245
233
|
worker.postMessage({
|
|
246
|
-
type:
|
|
247
|
-
|
|
234
|
+
type: `${taskName}Error`,
|
|
235
|
+
message: e.message,
|
|
248
236
|
id
|
|
249
237
|
});
|
|
250
238
|
}
|
|
251
|
-
if (e.type === 'has') {
|
|
252
|
-
try {
|
|
253
|
-
const value = await has(e.input.address);
|
|
254
|
-
worker.postMessage({
|
|
255
|
-
type: 'response',
|
|
256
|
-
id,
|
|
257
|
-
value
|
|
258
|
-
});
|
|
259
|
-
} catch (error) {
|
|
260
|
-
worker.postMessage({
|
|
261
|
-
type: 'hasError',
|
|
262
|
-
message: error.message,
|
|
263
|
-
id
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (e.type === 'run') {
|
|
268
|
-
try {
|
|
269
|
-
const value = await runContract(e.input);
|
|
270
|
-
worker.postMessage({
|
|
271
|
-
type: 'response',
|
|
272
|
-
id,
|
|
273
|
-
value
|
|
274
|
-
});
|
|
275
|
-
} catch (e) {
|
|
276
|
-
worker.postMessage({
|
|
277
|
-
type: 'runError',
|
|
278
|
-
message: e.message,
|
|
279
|
-
id
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
if (e.type === 'get') {
|
|
284
|
-
try {
|
|
285
|
-
const value = await get(e.input.contract, e.input.method, e.input.params);
|
|
286
|
-
worker.postMessage({
|
|
287
|
-
type: 'response',
|
|
288
|
-
id,
|
|
289
|
-
value
|
|
290
|
-
});
|
|
291
|
-
} catch (e) {
|
|
292
|
-
worker.postMessage({
|
|
293
|
-
type: 'fetchError',
|
|
294
|
-
message: e.message,
|
|
295
|
-
id
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (e.type === 'execute') {
|
|
300
|
-
try {
|
|
301
|
-
const value = await execute(e.input.contract, e.input.method, e.input.params);
|
|
302
|
-
worker.postMessage({
|
|
303
|
-
type: 'response',
|
|
304
|
-
id,
|
|
305
|
-
value
|
|
306
|
-
});
|
|
307
|
-
} catch (e) {
|
|
308
|
-
worker.postMessage({
|
|
309
|
-
type: 'executionError',
|
|
310
|
-
message: e.message,
|
|
311
|
-
id
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
239
|
};
|
|
316
240
|
|
|
317
|
-
worker.onmessage((
|
|
241
|
+
worker.onmessage(({ id, type, input }) => {
|
|
242
|
+
switch (type) {
|
|
243
|
+
case 'init':
|
|
244
|
+
runTask(id, 'init', input);
|
|
245
|
+
break
|
|
246
|
+
case 'run':
|
|
247
|
+
runTask(id, 'runContract', input);
|
|
248
|
+
break
|
|
249
|
+
case 'execute':
|
|
250
|
+
runTask(id, 'execute', input);
|
|
251
|
+
break
|
|
252
|
+
case 'addLoadedBlock':
|
|
253
|
+
runTask(id, 'addLoadedBlock', input);
|
|
254
|
+
break
|
|
255
|
+
case 'nativeCalls':
|
|
256
|
+
respond(id, nativeCalls);
|
|
257
|
+
break
|
|
258
|
+
case 'contracts':
|
|
259
|
+
respond(id, contracts);
|
|
260
|
+
break
|
|
261
|
+
case 'nativeMints':
|
|
262
|
+
respond(id, nativeMints);
|
|
263
|
+
break
|
|
264
|
+
case 'nativeBurns':
|
|
265
|
+
respond(id, nativeBurns);
|
|
266
|
+
break
|
|
267
|
+
case 'nativeTransfers':
|
|
268
|
+
respond(id, nativeTransfers);
|
|
269
|
+
break
|
|
270
|
+
case 'totalTransfers':
|
|
271
|
+
respond(id, totalTransfers);
|
|
272
|
+
break
|
|
273
|
+
case 'totalBlocks':
|
|
274
|
+
respond(id, blocks.length);
|
|
275
|
+
break
|
|
276
|
+
case 'blocks':
|
|
277
|
+
respond(id, input ? blocks.slice(input.from, input.to) : blocks);
|
|
278
|
+
break
|
|
279
|
+
case 'block':
|
|
280
|
+
respond(id, blocks[input - 1]);
|
|
281
|
+
break
|
|
282
|
+
case 'lastBlock':
|
|
283
|
+
respond(id, blocks[blocks.length - 1]);
|
|
284
|
+
break
|
|
285
|
+
case 'latestTransactions':
|
|
286
|
+
respond(id, latestTransactions);
|
|
287
|
+
break
|
|
288
|
+
case 'has':
|
|
289
|
+
respond(id, has(input.address));
|
|
290
|
+
break
|
|
291
|
+
case 'get':
|
|
292
|
+
respond(id, get(input));
|
|
293
|
+
break
|
|
294
|
+
default:
|
|
295
|
+
console.log(`machine-worker: unsupported taskType: ${type}`);
|
|
296
|
+
break
|
|
297
|
+
}
|
|
298
|
+
});
|