jaelis-node 1.10.0 → 2.1.0

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 (173) hide show
  1. package/README.md +156 -439
  2. package/bin/jaelis-node.js +83 -504
  3. package/lib/index.js +31 -2840
  4. package/lib/node.js +309 -0
  5. package/lib/rpc.js +315 -0
  6. package/lib/storage.js +198 -0
  7. package/lib/sync.js +366 -0
  8. package/package.json +19 -53
  9. package/config/default.json +0 -74
  10. package/config/mainnet.json +0 -30
  11. package/config/testnet.json +0 -26
  12. package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +0 -454
  13. package/lib/JAELIS-VM/lib/adapters/index.js +0 -411
  14. package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +0 -457
  15. package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +0 -1097
  16. package/lib/JAELIS-VM/lib/execution/engine.js +0 -1183
  17. package/lib/JAELIS-VM/lib/index.js +0 -440
  18. package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +0 -543
  19. package/lib/JAELIS-VM/lib/serialization/serializer.js +0 -819
  20. package/lib/JAELIS-VM/lib/state/state-manager.js +0 -1116
  21. package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +0 -1222
  22. package/lib/JAELIS-VM/lib/unified/cross-chain-deploy.js +0 -1678
  23. package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +0 -836
  24. package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +0 -1127
  25. package/lib/JAELIS-VM/lib/unified/index.js +0 -456
  26. package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +0 -1150
  27. package/lib/JAELIS-VM/lib/unified/unified-compiler.js +0 -1350
  28. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +0 -12
  29. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +0 -17
  30. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +0 -28
  31. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +0 -12
  32. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +0 -17
  33. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +0 -28
  34. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  35. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  36. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  37. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  38. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  39. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  40. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  41. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  42. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  43. package/lib/JAELIS-VM/node_modules/.package-lock.json +0 -127
  44. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +0 -1
  45. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
  46. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
  47. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
  48. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +0 -17
  49. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +0 -1
  50. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
  51. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
  52. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
  53. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +0 -17
  54. package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +0 -21
  55. package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +0 -5
  56. package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +0 -11
  57. package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +0 -60
  58. package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +0 -1
  59. package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +0 -50
  60. package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +0 -198
  61. package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +0 -21
  62. package/lib/JAELIS-VM/node_modules/cbor-x/README.md +0 -380
  63. package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +0 -11
  64. package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +0 -73
  65. package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +0 -11
  66. package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +0 -2
  67. package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +0 -1300
  68. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +0 -1244
  69. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +0 -1
  70. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +0 -2509
  71. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +0 -1
  72. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +0 -2
  73. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +0 -1
  74. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +0 -2508
  75. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +0 -1
  76. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +0 -2
  77. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +0 -1
  78. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +0 -2629
  79. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +0 -1
  80. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +0 -3343
  81. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +0 -1
  82. package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +0 -1
  83. package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +0 -1231
  84. package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +0 -79
  85. package/lib/JAELIS-VM/node_modules/cbor-x/index.js +0 -3
  86. package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +0 -85
  87. package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +0 -24
  88. package/lib/JAELIS-VM/node_modules/cbor-x/package.json +0 -94
  89. package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +0 -88
  90. package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +0 -61
  91. package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +0 -19
  92. package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +0 -201
  93. package/lib/JAELIS-VM/node_modules/detect-libc/README.md +0 -163
  94. package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +0 -14
  95. package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +0 -313
  96. package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +0 -39
  97. package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +0 -51
  98. package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +0 -24
  99. package/lib/JAELIS-VM/node_modules/detect-libc/package.json +0 -44
  100. package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +0 -21
  101. package/lib/JAELIS-VM/node_modules/msgpackr/README.md +0 -372
  102. package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +0 -11
  103. package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +0 -67
  104. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +0 -2407
  105. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +0 -1
  106. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +0 -2
  107. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +0 -1
  108. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +0 -2406
  109. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +0 -1
  110. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +0 -2
  111. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +0 -1
  112. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +0 -3320
  113. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +0 -1
  114. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +0 -4540
  115. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +0 -1
  116. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +0 -1250
  117. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +0 -1
  118. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +0 -91
  119. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +0 -91
  120. package/lib/JAELIS-VM/node_modules/msgpackr/index.js +0 -5
  121. package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +0 -87
  122. package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +0 -25
  123. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +0 -1
  124. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +0 -1
  125. package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +0 -1141
  126. package/lib/JAELIS-VM/node_modules/msgpackr/package.json +0 -104
  127. package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +0 -88
  128. package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +0 -57
  129. package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +0 -815
  130. package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +0 -3
  131. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +0 -2
  132. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +0 -2
  133. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +0 -1221
  134. package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +0 -21
  135. package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +0 -5
  136. package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +0 -13
  137. package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +0 -63
  138. package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +0 -1
  139. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  140. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  141. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  142. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  143. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  144. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  145. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  146. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  147. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  148. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  149. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  150. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +0 -82
  151. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  152. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +0 -6
  153. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +0 -236
  154. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  155. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  156. package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +0 -50
  157. package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +0 -274
  158. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  159. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  160. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +0 -77
  161. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  162. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +0 -224
  163. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  164. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  165. package/lib/JAELIS-VM/package-lock.json +0 -284
  166. package/lib/JAELIS-VM/package.json +0 -38
  167. package/lib/JAELIS-VM/test/comprehensive.test.js +0 -267
  168. package/lib/JAELIS-VM/test/cross-chain-test.js +0 -470
  169. package/lib/JAELIS-VM/test/unified-vm-test.js +0 -459
  170. package/lib/JAELIS-VM/test/unified.test.js +0 -166
  171. package/lib/JAELIS-VM/test/vm.test.js +0 -599
  172. package/lib/settlement-server.js +0 -999
  173. package/lib/vm/index.js +0 -397
package/lib/vm/index.js DELETED
@@ -1,397 +0,0 @@
1
- /**
2
- * JAELIS UNIFIED VM INTEGRATION
3
- *
4
- * Wires the UnifiedJaelisVM (NO BRIDGES, NO ADAPTERS!) into the JAELIS blockchain
5
- * for smart contract execution.
6
- *
7
- * This is THE execution engine - all contracts from ALL languages run here:
8
- * - Solidity (EVM)
9
- * - Rust (Solana)
10
- * - Move (Aptos/Sui)
11
- * - FunC (TON)
12
- * - Cairo (Starknet)
13
- *
14
- * Key Features:
15
- * - TRUE cross-chain interoperability (NO BRIDGES!)
16
- * - Dynamic contracts (auto-update when VMs change)
17
- * - JAELIS ABI (ONE encoding for all)
18
- * - ZERO FEES (ENE system)
19
- *
20
- * @version 1.0.0
21
- * @author Mario Papaleo - JAELIS Foundation
22
- * @patent PATENT PENDING - Unified Cross-Chain Virtual Machine
23
- */
24
-
25
- const path = require('path');
26
- const EventEmitter = require('events');
27
-
28
- // Import the Unified VM from JAELIS-VM
29
- let UnifiedJaelisVM, JaelisABI, DynamicContractManager;
30
-
31
- try {
32
- const vmPath = path.resolve(__dirname, '../../../JAELIS-VM/lib/unified');
33
- const unified = require(vmPath);
34
- UnifiedJaelisVM = unified.UnifiedJaelisVM;
35
- JaelisABI = unified.JaelisABI;
36
- DynamicContractManager = unified.DynamicContractManager;
37
- } catch (e) {
38
- console.warn('[JAELIS-VM] Could not load UnifiedJaelisVM from relative path, trying npm...');
39
- try {
40
- const unified = require('jaelis-vm/lib/unified');
41
- UnifiedJaelisVM = unified.UnifiedJaelisVM;
42
- JaelisABI = unified.JaelisABI;
43
- DynamicContractManager = unified.DynamicContractManager;
44
- } catch (e2) {
45
- console.warn('[JAELIS-VM] UnifiedJaelisVM not available, using fallback');
46
- }
47
- }
48
-
49
- /**
50
- * VMExecutor - Executes smart contracts on the JAELIS blockchain
51
- *
52
- * This wraps the UnifiedJaelisVM and provides blockchain-specific functionality:
53
- * - Transaction processing
54
- * - State commitment to blockchain
55
- * - Event emission for block inclusion
56
- * - Gas-less execution (ENE system)
57
- */
58
- class VMExecutor extends EventEmitter {
59
- constructor(blockchain, options = {}) {
60
- super();
61
-
62
- this.blockchain = blockchain;
63
- this.options = options;
64
-
65
- // Initialize the Unified VM (NO BRIDGES!)
66
- if (UnifiedJaelisVM) {
67
- this.vm = new UnifiedJaelisVM({
68
- ...options,
69
- enableLogging: options.debug || false
70
- });
71
- console.log('[VMExecutor] Unified VM initialized - NO BRIDGES, NO ADAPTERS!');
72
- } else {
73
- this.vm = null;
74
- console.log('[VMExecutor] Running in light mode (no VM)');
75
- }
76
-
77
- // Contract address mapping
78
- this.contracts = new Map();
79
-
80
- // Pending state changes (committed on block finalization)
81
- this.pendingStateChanges = [];
82
-
83
- // Transaction receipts
84
- this.receipts = new Map();
85
-
86
- // Stats
87
- this.stats = {
88
- contractsDeployed: 0,
89
- transactionsExecuted: 0,
90
- crossContractCalls: 0,
91
- totalGasUsed: 0 // Always 0 - ZERO FEES!
92
- };
93
- }
94
-
95
- /**
96
- * Deploy a smart contract
97
- *
98
- * Supports ANY language:
99
- * - Solidity, Vyper (EVM)
100
- * - Rust/Anchor (Solana)
101
- * - Move (Aptos/Sui)
102
- * - FunC (TON)
103
- * - Cairo (Starknet)
104
- */
105
- async deployContract(source, language, options = {}) {
106
- if (!this.vm) {
107
- throw new Error('VM not available - run in full node mode');
108
- }
109
-
110
- const deployer = options.from || options.deployer || '0x0';
111
-
112
- console.log(`[VMExecutor] Deploying ${language} contract...`);
113
-
114
- // Deploy through Unified VM
115
- const result = await this.vm.deploy(source, language, {
116
- ...options,
117
- deployer
118
- });
119
-
120
- // Store in local registry
121
- this.contracts.set(result.address, {
122
- address: result.address,
123
- language,
124
- deployedAt: Date.now(),
125
- deployer,
126
- bytecodeHash: result.bytecode ?
127
- require('crypto').createHash('sha256').update(result.bytecode).digest('hex') : null
128
- });
129
-
130
- this.stats.contractsDeployed++;
131
-
132
- // Emit event for block inclusion
133
- this.emit('contractDeployed', {
134
- address: result.address,
135
- language,
136
- deployer,
137
- blockNumber: this.blockchain?.getHeight?.() || 0
138
- });
139
-
140
- console.log(`[VMExecutor] Contract deployed: ${result.address.substring(0, 20)}...`);
141
-
142
- return {
143
- address: result.address,
144
- abi: result.abi,
145
- language,
146
- gasUsed: 0 // ZERO FEES!
147
- };
148
- }
149
-
150
- /**
151
- * Execute a contract call
152
- */
153
- async executeCall(to, functionName, args = [], options = {}) {
154
- if (!this.vm) {
155
- throw new Error('VM not available');
156
- }
157
-
158
- const from = options.from || '0x0';
159
- const value = options.value || 0;
160
-
161
- console.log(`[VMExecutor] Executing ${functionName} on ${to.substring(0, 16)}...`);
162
-
163
- // Execute through Unified VM
164
- const result = await this.vm.execute(to, functionName, args, {
165
- from,
166
- value,
167
- blockNumber: this.blockchain?.getHeight?.() || 0,
168
- timestamp: Date.now()
169
- });
170
-
171
- this.stats.transactionsExecuted++;
172
-
173
- // Create receipt
174
- const receipt = {
175
- transactionHash: this._generateTxHash(to, functionName, args, from),
176
- blockNumber: this.blockchain?.getHeight?.() || 0,
177
- from,
178
- to,
179
- status: result.success ? 1 : 0,
180
- gasUsed: 0, // ZERO FEES!
181
- logs: result.logs || [],
182
- returnValue: result.returnValue
183
- };
184
-
185
- this.receipts.set(receipt.transactionHash, receipt);
186
-
187
- // Emit for block inclusion
188
- this.emit('transactionExecuted', receipt);
189
-
190
- return receipt;
191
- }
192
-
193
- /**
194
- * Cross-contract call (NO BRIDGES!)
195
- *
196
- * This is THE key innovation - contracts from ANY VM can call each other DIRECTLY
197
- */
198
- async crossContractCall(fromContract, toContract, functionName, args = [], options = {}) {
199
- if (!this.vm) {
200
- throw new Error('VM not available');
201
- }
202
-
203
- console.log(`[VMExecutor] Cross-call: ${fromContract.substring(0, 10)}... → ${toContract.substring(0, 10)}...::${functionName}`);
204
- console.log(`[VMExecutor] NO BRIDGE! NO ADAPTER! Direct execution.`);
205
-
206
- // Execute through Unified VM's cross-call
207
- const result = await this.vm.crossCall(fromContract, toContract, functionName, args);
208
-
209
- this.stats.crossContractCalls++;
210
-
211
- // Emit event
212
- this.emit('crossContractCall', {
213
- from: fromContract,
214
- to: toContract,
215
- function: functionName,
216
- success: result.success,
217
- blockNumber: this.blockchain?.getHeight?.() || 0
218
- });
219
-
220
- return result;
221
- }
222
-
223
- /**
224
- * Process a transaction
225
- *
226
- * This is called by the blockchain when a new transaction arrives
227
- */
228
- async processTransaction(tx) {
229
- // Validate transaction
230
- if (!tx.to && !tx.data) {
231
- throw new Error('Invalid transaction: no target or data');
232
- }
233
-
234
- // Contract deployment (no 'to' address)
235
- if (!tx.to && tx.data) {
236
- // Detect language from data or metadata
237
- const language = tx.language || this._detectLanguage(tx.data);
238
- return this.deployContract(tx.data, language, {
239
- from: tx.from,
240
- value: tx.value
241
- });
242
- }
243
-
244
- // Contract call
245
- if (tx.to && tx.data) {
246
- const { functionName, args } = this._decodeCalldata(tx.data);
247
- return this.executeCall(tx.to, functionName, args, {
248
- from: tx.from,
249
- value: tx.value
250
- });
251
- }
252
-
253
- // Simple transfer (no data)
254
- return this._processTransfer(tx);
255
- }
256
-
257
- /**
258
- * Get contract information
259
- */
260
- getContract(address) {
261
- return this.contracts.get(address) || null;
262
- }
263
-
264
- /**
265
- * Get all deployed contracts
266
- */
267
- getAllContracts() {
268
- return Array.from(this.contracts.values());
269
- }
270
-
271
- /**
272
- * Get transaction receipt
273
- */
274
- getReceipt(txHash) {
275
- return this.receipts.get(txHash) || null;
276
- }
277
-
278
- /**
279
- * Get VM stats
280
- */
281
- getStats() {
282
- const vmStats = this.vm?.getStats?.() || {};
283
- return {
284
- ...this.stats,
285
- ...vmStats,
286
- vmAvailable: !!this.vm
287
- };
288
- }
289
-
290
- /**
291
- * Encode function call using JAELIS ABI
292
- */
293
- encodeCall(functionName, args, types) {
294
- if (JaelisABI) {
295
- return JaelisABI.encodeFunctionCall(functionName, args, types);
296
- }
297
- // Fallback encoding
298
- return Buffer.from(JSON.stringify({ functionName, args }));
299
- }
300
-
301
- /**
302
- * Decode function call
303
- */
304
- decodeCall(data) {
305
- if (JaelisABI) {
306
- return JaelisABI.decodeFunctionCall(data);
307
- }
308
- // Fallback decoding
309
- try {
310
- return JSON.parse(data.toString());
311
- } catch {
312
- return { functionName: 'unknown', args: [] };
313
- }
314
- }
315
-
316
- // ═══════════════════════════════════════════════════════════════
317
- // PRIVATE METHODS
318
- // ═══════════════════════════════════════════════════════════════
319
-
320
- _generateTxHash(to, functionName, args, from) {
321
- const crypto = require('crypto');
322
- return '0x' + crypto.createHash('sha256')
323
- .update(JSON.stringify({ to, functionName, args, from, timestamp: Date.now() }))
324
- .digest('hex');
325
- }
326
-
327
- _detectLanguage(data) {
328
- const code = typeof data === 'string' ? data : data.toString();
329
-
330
- // Detect by patterns
331
- if (code.includes('contract ') && code.includes('function ')) return 'solidity';
332
- if (code.includes('#[program]') || code.includes('pub mod ')) return 'rust';
333
- if (code.includes('module ') && code.includes('public fun ')) return 'move';
334
- if (code.includes('recv_internal') || code.includes('method_id')) return 'func';
335
- if (code.includes('#[contract]') && code.includes('fn ')) return 'cairo';
336
-
337
- return 'solidity'; // Default
338
- }
339
-
340
- _decodeCalldata(data) {
341
- // If it's already JSON
342
- if (typeof data === 'object' && data.functionName) {
343
- return data;
344
- }
345
-
346
- // Try JAELIS ABI decode
347
- if (JaelisABI && Buffer.isBuffer(data)) {
348
- try {
349
- return JaelisABI.decodeFunctionCall(data);
350
- } catch {
351
- // Fall through
352
- }
353
- }
354
-
355
- // Try JSON
356
- try {
357
- return JSON.parse(data.toString());
358
- } catch {
359
- return { functionName: 'fallback', args: [] };
360
- }
361
- }
362
-
363
- async _processTransfer(tx) {
364
- // Simple value transfer (no contract execution)
365
- const receipt = {
366
- transactionHash: this._generateTxHash(tx.to, 'transfer', [tx.value], tx.from),
367
- blockNumber: this.blockchain?.getHeight?.() || 0,
368
- from: tx.from,
369
- to: tx.to,
370
- value: tx.value,
371
- status: 1,
372
- gasUsed: 0 // ZERO FEES!
373
- };
374
-
375
- this.receipts.set(receipt.transactionHash, receipt);
376
- this.emit('transfer', receipt);
377
-
378
- return receipt;
379
- }
380
- }
381
-
382
- /**
383
- * Factory function to create VM executor
384
- */
385
- function createVMExecutor(blockchain, options = {}) {
386
- return new VMExecutor(blockchain, options);
387
- }
388
-
389
- module.exports = {
390
- VMExecutor,
391
- createVMExecutor,
392
-
393
- // Re-export VM components
394
- UnifiedJaelisVM,
395
- JaelisABI,
396
- DynamicContractManager
397
- };