Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
fix: fork network is working with deploy (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhulz committed Jul 19, 2022
1 parent cf67c70 commit c386882
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/Models/IDeployDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import {INetwork} from '@/helpers/ConfigurationReader';
import {ItemType} from './ItemType';
import {TLocalProjectOptions} from './TreeItems';

export interface IDeployDestination {
description?: string;
Expand All @@ -12,4 +13,5 @@ export interface IDeployDestination {
port?: number;
getTruffleNetwork: () => Promise<INetwork>;
networkId: number;
options?: TLocalProjectOptions;
}
1 change: 1 addition & 0 deletions src/Models/TreeItems/LocalProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class LocalProject extends Project {
networkId: node.networkId,
networkType: node.itemType,
port: node.port,
options: this.options,
} as IDeployDestination;
})
);
Expand Down
29 changes: 18 additions & 11 deletions src/commands/TruffleCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {getPathByPlatform} from '@/helpers/workspace';

import {IDeployDestination, ItemType} from '@/Models';
import {NetworkForContractItem} from '@/Models/QuickPickItems';
import {InfuraProject, LocalProject, LocalService} from '@/Models/TreeItems';
import {InfuraProject, LocalProject, LocalService, TLocalProjectOptions} from '@/Models/TreeItems';
import {Project} from '@/Models/TreeItems';
import {Output} from '@/Output';
import {
Expand Down Expand Up @@ -378,10 +378,12 @@ async function getTruffleDeployFunction(
networkId: number | string,
port?: number
): Promise<() => Promise<void>> {
const treeProjectNames = await getTreeProjectNames();
if (port !== undefined && (treeProjectNames.includes(name) || name === Constants.localhostName)) {
const projects = await getTreeProjects();
const project = projects.find((project) => project.label === name);

if (port !== undefined && (project !== undefined || name === Constants.localhostName)) {
Telemetry.sendEvent('TruffleCommands.getTruffleDeployFunction.returnDeployToLocalGanache');
return deployToLocalGanache.bind(undefined, name, truffleConfigPath, port);
return deployToLocalGanache.bind(undefined, name, truffleConfigPath, port, project?.options);
}
// 1 - is the marker of main network
if (networkId === 1 || networkId === '1') {
Expand All @@ -393,20 +395,20 @@ async function getTruffleDeployFunction(
return deployToNetwork.bind(undefined, name, truffleConfigPath);
}

async function getTreeProjectNames(): Promise<string[]> {
async function getTreeProjects(): Promise<IDeployDestination[]> {
const services = TreeManager.getItems();

const localService = services.find((service) => service instanceof LocalService);
const projects = (localService ? localService.getChildren() : []) as Project[];
const projects = (localService ? localService.getChildren() : []) as LocalProject[];

const projectNames = [];
const deployDestinations: IDeployDestination[] = [];

for (const project of projects) {
const projectDestinations = await project.getDeployDestinations();
projectNames.push(...projectDestinations);
deployDestinations.push(...projectDestinations);
}

return projectNames.map((destination) => destination.label);
return deployDestinations;
}

function getServiceCreateFunction(
Expand Down Expand Up @@ -495,8 +497,13 @@ async function deployToNetwork(networkName: string, truffleConfigPath: string):
});
}

async function deployToLocalGanache(networkName: string, truffleConfigPath: string, port: number): Promise<void> {
await GanacheService.startGanacheServer(port);
async function deployToLocalGanache(
networkName: string,
truffleConfigPath: string,
port: number,
options?: TLocalProjectOptions
): Promise<void> {
await GanacheService.startGanacheServer(port, options);
await deployToNetwork(networkName, truffleConfigPath);
}

Expand Down

0 comments on commit c386882

Please sign in to comment.