From 5af75606e5252699d52a29eb3365ed1de128fb3b Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 16 Dec 2024 15:52:27 +0530 Subject: [PATCH] save and load state --- apps/remix-ide/src/blockchain/blockchain.tsx | 20 ++++++++++++++++--- .../blockchain/providers/saved-vm-state.ts | 1 - 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.tsx b/apps/remix-ide/src/blockchain/blockchain.tsx index 75c89405a1f..c98f9c6351c 100644 --- a/apps/remix-ide/src/blockchain/blockchain.tsx +++ b/apps/remix-ide/src/blockchain/blockchain.tsx @@ -958,8 +958,23 @@ export class Blockchain extends Plugin { if (isVM) { if (!tx.useCall && this.config.get('settings/save-evm-state')) { try { - const state = await this.executionContext.getStateDetails() - this.call('fileManager', 'writeFile', `.states/${this.executionContext.getProvider()}/state.json`, state) + let state = await this.executionContext.getStateDetails() + const provider = this.executionContext.getProvider() + if (provider.startsWith('svs')) { + const stateName = provider.replace('svs-', '') + const stateFileExists = this.call('fileManager', 'exists', `.states/saved_states/${stateName}.json`) + if (stateFileExists) { + let stateDetails = await this.call('fileManager', 'readFile', `.states/saved_states/${stateName}.json`) + stateDetails = JSON.parse(stateDetails) + state = JSON.parse(state) + state['stateName'] = stateDetails.stateName + state['forkName'] = stateDetails.forkName + state['savingTimestamp'] = stateDetails.savingTimestamp + state = JSON.stringify(state, null, 2) + } + this.call('fileManager', 'writeFile', `.states/saved_states/${stateName}.json`, state) + } + else this.call('fileManager', 'writeFile', `.states/${provider}/state.json`, state) } catch (e) { console.error(e) } @@ -991,7 +1006,6 @@ export class Blockchain extends Plugin { this.call('terminal', 'logHtml', finalLogs) } execResult = await this.web3().remix.getExecutionResultFromSimulator(txResult.transactionHash) - if (execResult) { // if it's not the VM, we don't have return value. We only have the transaction, and it does not contain the return value. returnValue = execResult diff --git a/apps/remix-ide/src/blockchain/providers/saved-vm-state.ts b/apps/remix-ide/src/blockchain/providers/saved-vm-state.ts index 774c7fdca60..b23c2d93ca7 100644 --- a/apps/remix-ide/src/blockchain/providers/saved-vm-state.ts +++ b/apps/remix-ide/src/blockchain/providers/saved-vm-state.ts @@ -93,7 +93,6 @@ export class SVSProvider { try { const blockchainState = JSON.parse(stringifiedState) const blockNumber = parseInt(blockchainState.latestBlockNumber, 16) - console.log('blockNumber-in resetEnvironment-->', blockNumber) const stateDb = blockchainState.db this.worker.postMessage({