Skip to content

Commit

Permalink
save and load state
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket-Engg committed Dec 16, 2024
1 parent dc29fab commit 5af7560
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 17 additions & 3 deletions apps/remix-ide/src/blockchain/blockchain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion apps/remix-ide/src/blockchain/providers/saved-vm-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 5af7560

Please sign in to comment.