fork instead of save

pull/5563/head
aniket-engg 2 months ago committed by Aniket
parent d37c7ba917
commit 72503873c9
  1. 8
      apps/remix-dapp/src/locales/en/udapp.json
  2. 2
      apps/remix-ide/src/app/providers/vm-provider.tsx
  3. 8
      apps/remix-ide/src/app/tabs/locales/en/udapp.json
  4. 26
      apps/remix-ide/src/app/udapp/run-tab.tsx
  5. 21
      apps/remix-ide/src/blockchain/blockchain.tsx
  6. 12
      libs/remix-ui/environment-explorer/src/lib/components/environment-explorer-ui.tsx
  7. 4
      libs/remix-ui/environment-explorer/src/lib/types/index.ts
  8. 26
      libs/remix-ui/run-tab/src/lib/components/environment.tsx

@ -49,9 +49,10 @@
"udapp.enterAMessageToSign": "Enter a message to sign",
"udapp.hash": "hash",
"udapp.signature": "signature",
"udapp.saveVmStateTitle": "Save VM state",
"udapp.saveVmStateLabel": "State Name",
"udapp.saveVmStateTip": "VM state, saved for current workspace, can be pinned as an environment using Environment Explorer",
"udapp.forkStateTitle": "Fork VM state",
"udapp.forkStateLabel": "State Name",
"udapp.forkStateTip": "VM State, forked for current workspace, can be pinned as an environment using Environment Explorer",
"udapp.fork": "Fork",
"udapp.resetVmStateTitle": "Reset VM state",
"udapp.resetVmStateDesc1": "Resetting state of the selected environment will delete all your previously saved transaction details for current workspace.",
"udapp.resetVmStateDesc2": "It will also delete the data for contracts deployed and pinned for this workspace.",
@ -71,7 +72,6 @@
"udapp._comment_environment.tsx": "libs/remix-ui/run-tab/src/lib/components/environment.tsx",
"udapp.environment": "Environment",
"udapp.environmentDocs": "Click for docs about Environment",
"udapp.saveVmState": "Save VM state",
"udapp.resetVmStateTooltip": "Reset VM state",
"udapp.tooltipText2": "Open chainlist.org and get the connection specs of the chain you want to interact with.",
"udapp.tooltipText3": "Click to open a bridge for converting L1 mainnet ETH to the selected network currency.",

@ -132,7 +132,7 @@ export class CancunVMProvider extends BasicVMProvider {
}
}
export class SavedVMStateProvider extends BasicVMProvider {
export class ForkedVMStateProvider extends BasicVMProvider {
constructor(profile, blockchain, fork) {
super(profile, blockchain)
this.blockchain = blockchain

@ -49,9 +49,10 @@
"udapp.enterAMessageToSign": "Enter a message to sign and click `Sign`",
"udapp.hash": "hash",
"udapp.signature": "signature",
"udapp.saveVmStateTitle": "Save VM state",
"udapp.saveVmStateLabel": "State Name",
"udapp.saveVmStateTip": "VM state, saved for current workspace, can be pinned as an environment using Environment Explorer",
"udapp.forkStateTitle": "Fork VM state",
"udapp.forkStateLabel": "State Name",
"udapp.forkStateTip": "VM State, forked for current workspace, can be pinned as an environment using Environment Explorer",
"udapp.fork": "Fork",
"udapp.resetVmStateTitle": "Reset VM state",
"udapp.resetVmStateDesc1": "Resetting state of the selected environment will delete all your previously saved transaction details for current workspace.",
"udapp.resetVmStateDesc2": "It will also delete the data for contracts deployed and pinned for this workspace.",
@ -70,7 +71,6 @@
"udapp._comment_environment.tsx": "libs/remix-ui/run-tab/src/lib/components/environment.tsx",
"udapp.environment": "Environment",
"udapp.environmentDocs": "Click for docs about Environment",
"udapp.saveVmState": "Save VM state",
"udapp.resetVmStateTooltip": "Reset VM state",
"udapp.reset": "Reset",
"udapp.tooltipText2": "Open chainlist.org and get the connection specs of the chain you want to interact with.",

@ -9,7 +9,7 @@ import * as packageJson from '../../../../../package.json'
import { EventManager } from '@remix-project/remix-lib'
import type { Blockchain } from '../../blockchain/blockchain'
import type { CompilerArtefacts } from '@remix-project/core-plugin'
import { SavedVMStateProvider } from '../providers/vm-provider'
import { ForkedVMStateProvider } from '../providers/vm-provider'
import { Recorder } from '../tabs/runTab/model/recorder'
const _paq = (window._paq = window._paq || [])
@ -177,7 +177,7 @@ export class RunTab extends ViewPlugin {
'foundry-provider': ['assets/img/foundry.png']
}
const addProvider = async (position, name, displayName, isInjected, isVM, isSavedState, fork = '', dataId = '', title = '', forkedVM = false) => {
const addProvider = async (position, name, displayName, isInjected, isVM, isForkedState, fork = '', dataId = '', title = '', forkedVM = false) => {
await this.call('blockchain', 'addProvider', {
position,
options: {},
@ -190,7 +190,7 @@ export class RunTab extends ViewPlugin {
isInjected,
isForkedVM: forkedVM,
isVM,
isSavedState,
isForkedState,
title,
init: async function () {
const options = await udapp.call(name, 'init')
@ -257,18 +257,18 @@ export class RunTab extends ViewPlugin {
await addProvider(3, 'vm-sepolia-fork', 'Remix VM - Sepolia fork', false, true, false, 'cancun', 'settingsVMSepoliaMode', titleVM, true)
await addProvider(4, 'vm-custom-fork', 'Remix VM - Custom fork', false, true, false, '', 'settingsVMCustomMode', titleVM, true)
// Saved VM States
const addSVSProvider = async(stateFilePath, pos) => {
// Forked VM States
const addFVSProvider = async(stateFilePath, pos) => {
let stateDetail = await this.call('fileManager', 'readFile', stateFilePath)
stateDetail = JSON.parse(stateDetail)
const providerName = 'vm-svs-' + stateDetail.stateName
const providerName = 'vm-fs-' + stateDetail.stateName
descriptions[providerName] = JSON.stringify({
name: providerName,
latestBlock: stateDetail.latestBlockNumber,
timestamp: stateDetail.savingTimestamp
})
// Create and register provider plugin for saved states
const svsProvider = new SavedVMStateProvider({
const fvsProvider = new ForkedVMStateProvider({
name: providerName,
displayName: stateDetail.stateName,
kind: 'provider',
@ -276,25 +276,25 @@ export class RunTab extends ViewPlugin {
methods: ['sendAsync', 'init'],
version: packageJson.version
}, this.blockchain, stateDetail.forkName)
this.engine.register(svsProvider)
this.engine.register(fvsProvider)
await addProvider(pos, providerName, stateDetail.stateName, false, false, true, stateDetail.forkName)
}
this.on('filePanel', 'workspaceInitializationCompleted', async () => {
const ssExists = await this.call('fileManager', 'exists', '.states/saved_states')
const ssExists = await this.call('fileManager', 'exists', '.states/forked_states')
if (ssExists) {
const savedStatesDetails = await this.call('fileManager', 'readdir', '.states/saved_states')
const savedStatesDetails = await this.call('fileManager', 'readdir', '.states/forked_states')
const savedStatesFiles = Object.keys(savedStatesDetails)
let pos = 10
for (const filePath of savedStatesFiles) {
pos += 1
await addSVSProvider(filePath, pos)
await addFVSProvider(filePath, pos)
}
}
})
this.on('udapp', 'vmStateSaved', async (stateName) => {
await addSVSProvider(`.states/saved_states/${stateName}.json`, 20)
this.on('udapp', 'vmStateForked', async (stateName) => {
await addFVSProvider(`.states/forked_states/${stateName}.json`, 20)
})
// wallet connect

@ -55,7 +55,7 @@ export type Provider = {
description?: string
isInjected: boolean
isVM: boolean
isSavedState: boolean
isForkedState: boolean
isForkedVM: boolean
title: string
init: () => Promise<void>
@ -700,11 +700,11 @@ export class Blockchain extends Plugin {
const stateDb = await this.call('fileManager', 'readFile', `.states/${context}/state.json`)
await this.getCurrentProvider().resetEnvironment(stateDb)
} else {
// check if saved VM state is used as provider
const stateName = context.replace('vm-svs-', '')
const contextExists = await this.call('fileManager', 'exists', `.states/saved_states/${stateName}.json`)
// check if forked VM state is used as provider
const stateName = context.replace('vm-fs-', '')
const contextExists = await this.call('fileManager', 'exists', `.states/forked_states/${stateName}.json`)
if (contextExists) {
const stateDb = await this.call('fileManager', 'readFile', `.states/saved_states/${stateName}.json`)
const stateDb = await this.call('fileManager', 'readFile', `.states/forked_states/${stateName}.json`)
await this.getCurrentProvider().resetEnvironment(stateDb)
} else await this.getCurrentProvider().resetEnvironment()
}
@ -962,11 +962,12 @@ export class Blockchain extends Plugin {
try {
let state = await this.executionContext.getStateDetails()
const provider = this.executionContext.getProvider()
if (provider.startsWith('vm-svs-')) {
const stateName = provider.replace('vm-svs-', '')
const stateFileExists = this.call('fileManager', 'exists', `.states/saved_states/${stateName}.json`)
// Check if provider is forked VM state
if (provider.startsWith('vm-fs-')) {
const stateName = provider.replace('vm-fs-', '')
const stateFileExists = this.call('fileManager', 'exists', `.states/forked_states/${stateName}.json`)
if (stateFileExists) {
let stateDetails = await this.call('fileManager', 'readFile', `.states/saved_states/${stateName}.json`)
let stateDetails = await this.call('fileManager', 'readFile', `.states/forked_states/${stateName}.json`)
stateDetails = JSON.parse(stateDetails)
state = JSON.parse(state)
state['stateName'] = stateDetails.stateName
@ -974,7 +975,7 @@ export class Blockchain extends Plugin {
state['savingTimestamp'] = stateDetails.savingTimestamp
state = JSON.stringify(state, null, 2)
}
this.call('fileManager', 'writeFile', `.states/saved_states/${stateName}.json`, state)
this.call('fileManager', 'writeFile', `.states/forked_states/${stateName}.json`, state)
}
else this.call('fileManager', 'writeFile', `.states/${provider}/state.json`, state)
} catch (e) {

@ -17,11 +17,11 @@ const defaultSections: environmentExplorerUIGridSections = {
providers: [],
filterFn: (provider) => provider.isVM
},
'Saved VM States': {
title: 'Deploy to an In-browser Saved VM State.',
keywords: ['Saved VM States'],
'Forked States': {
title: 'Deploy to an In-browser Forked State.',
keywords: ['Forked State'],
providers: [],
filterFn: (provider) => provider.isSavedState,
filterFn: (provider) => provider.isForkedState,
descriptionFn: (provider) => {
const { latestBlock, timestamp } = JSON.parse(provider.description)
return (
@ -30,7 +30,7 @@ const defaultSections: environmentExplorerUIGridSections = {
<CustomTooltip
placement="auto"
tooltipId="overlay-tooltip-compile"
tooltipText={`Saved at: ${(new Date(timestamp)).toLocaleString()}`}
tooltipText={`Forked at: ${(new Date(timestamp)).toLocaleString()}`}
>
<div><b>Saved at: </b>{(new Date(timestamp)).toDateString()}</div>
</CustomTooltip>
@ -47,7 +47,7 @@ const defaultSections: environmentExplorerUIGridSections = {
title: 'Deploy to an external Provider.',
keywords: ['Externals'],
providers: [],
filterFn: (provider) => (!provider.isInjected && !provider.isVM && !provider.isSavedState && !provider.isForkedVM)
filterFn: (provider) => (!provider.isInjected && !provider.isVM && !provider.isForkedState && !provider.isForkedVM)
},
}
export const EnvironmentExplorerUI = (props: environmentExplorerUIProps) => {

@ -1,7 +1,7 @@
import { Plugin } from '@remixproject/engine'
import { Profile } from '@remixproject/plugin-utils'
export type ProvidersSection = `Injected` | 'Remix VMs' | 'Externals' | 'Remix forked VMs' | 'Saved VM States'
export type ProvidersSection = `Injected` | 'Remix VMs' | 'Externals' | 'Remix forked VMs' | 'Forked States'
export type environmentExplorerUIProps = {
state: {
@ -36,7 +36,7 @@ export type Provider = {
description?: string
isInjected: boolean
isVM: boolean
isSavedState: boolean
isForkedState: boolean
isForkedVM: boolean
title: string
init: () => Promise<void>

@ -27,22 +27,22 @@ export function EnvironmentUI(props: EnvironmentProps) {
const intl = useIntl()
const isSaveEvmStateChecked = props.config.get('settings/save-evm-state')
const saveVmStatePrompt = (defaultName: string) => {
const forkStatePrompt = (defaultName: string) => {
return (
<div>
<label id="stateName" className="form-check-label" style={{ fontWeight: 'bolder' }}>
<FormattedMessage id="udapp.saveVmStateLabel" />
<FormattedMessage id="udapp.forkStateLabel" />
</label>
<input
type="text"
data-id="modalDialogSaveVmState"
data-id="modalDialogForkState"
defaultValue={defaultName}
className="form-control"
onChange={(e) => vmStateName.current = e.target.value}
/>
<br/>
<div className='text-secondary'>
<b>Tip: </b><FormattedMessage id="udapp.saveVmStateTip" />
<b>Tip: </b><FormattedMessage id="udapp.forkStateTip" />
</div>
</div>
)
@ -60,24 +60,24 @@ export function EnvironmentUI(props: EnvironmentProps) {
)
}
const saveVmState = async () => {
const forkState = async () => {
const context = currentProvider.name
vmStateName.current = `${context}_${Date.now()}`
const contextExists = await props.runTabPlugin.call('fileManager', 'exists', `.states/${context}/state.json`)
if (contextExists) {
props.modal(
intl.formatMessage({ id: 'udapp.saveVmStateTitle' }),
saveVmStatePrompt(vmStateName.current),
intl.formatMessage({ id: 'udapp.save' }),
intl.formatMessage({ id: 'udapp.forkStateTitle' }),
forkStatePrompt(vmStateName.current),
intl.formatMessage({ id: 'udapp.fork' }),
async () => {
let currentStateDb = await props.runTabPlugin.call('fileManager', 'readFile', `.states/${context}/state.json`)
currentStateDb = JSON.parse(currentStateDb)
currentStateDb.stateName = vmStateName.current
currentStateDb.forkName = currentProvider.fork
currentStateDb.savingTimestamp = Date.now()
await props.runTabPlugin.call('fileManager', 'writeFile', `.states/saved_states/${vmStateName.current}.json`, JSON.stringify(currentStateDb, null, 2))
props.runTabPlugin.emit('vmStateSaved', vmStateName.current)
props.runTabPlugin.call('notification', 'toast', `VM state ${vmStateName.current} saved.`)
await props.runTabPlugin.call('fileManager', 'writeFile', `.states/forked_states/${vmStateName.current}.json`, JSON.stringify(currentStateDb, null, 2))
props.runTabPlugin.emit('vmStateForked', vmStateName.current)
props.runTabPlugin.call('notification', 'toast', `VM state ${vmStateName.current} forked successfully.`)
},
intl.formatMessage({ id: 'udapp.cancel' }),
null
@ -128,8 +128,8 @@ export function EnvironmentUI(props: EnvironmentProps) {
<i className="udapp_infoDeployAction ml-2 fas fa-info"></i>
</a>
</CustomTooltip>
{ currentProvider && currentProvider.isVM && isSaveEvmStateChecked && <CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="saveVMStatetooltip" tooltipText={<FormattedMessage id="udapp.saveVmState" />}>
<i className="udapp_infoDeployAction ml-2 fas fa-save" style={{cursor: 'pointer'}} onClick={saveVmState}></i>
{ currentProvider && currentProvider.isVM && isSaveEvmStateChecked && <CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="forkStatetooltip" tooltipText={<FormattedMessage id="udapp.forkStateTitle" />}>
<i className="udapp_infoDeployAction ml-2 fas fa-code-branch" style={{cursor: 'pointer'}} onClick={forkState}></i>
</CustomTooltip> }
{ currentProvider && currentProvider.isVM && isSaveEvmStateChecked && <CustomTooltip placement={'auto-end'} tooltipClasses="text-wrap" tooltipId="resetVMStatetooltip" tooltipText={<FormattedMessage id="udapp.resetVmStateTooltip" />}>
<i className="udapp_infoDeployAction ml-2 fas fa-refresh" style={{cursor: 'pointer'}} onClick={resetVmState}></i>

Loading…
Cancel
Save