Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dev/conract functions #229

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions src/lib/session.ts

This file was deleted.

12 changes: 6 additions & 6 deletions src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const parseBatchCompiledJSON = (context: ExtensionContext): void => {
let name = path.parse(e).base;
name = name.substring(0, name.length - 5);

logger.log(`Try to parse the ${name} contract output`);
logger.log(`Trying to parse ${name} contract output...`);

const data = fs.readFileSync(e);
const output: CompiledJSONOutput = getCompiledJsonObject(data);
Expand All @@ -32,7 +32,7 @@ const parseBatchCompiledJSON = (context: ExtensionContext): void => {
output.path = path.dirname(e);
output.name = name;

logger.success(`Loaded ${name} contract and saved to workspace`);
logger.success(`Loaded ${name} contract into workspace.`);
let contracts = context.workspaceState.get('contracts') as any;

if (contracts === undefined || contracts === '') contracts = new Map();
Expand Down Expand Up @@ -67,13 +67,13 @@ const getCompiledJsonObject = (_jsonPayload: any): CompiledJSONOutput => {

output.contractType = 1;
output.hardhatOutput = data;
logger.log('Loaded Hardhat compiled json output');
logger.log('Loaded Hardhat compiled json outputs.');
} else if (data.data !== undefined) {
// Remix format

output.contractType = 2;
output.remixOutput = data;
logger.log('Loaded Remix compiled json output');
logger.log('Loaded Remix compiled json output.');
}
} catch (e) {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -112,7 +112,7 @@ const selectContract = (context: ExtensionContext) => {
label: f || '',
functionKey: f || '',
}));
quickPick.placeholder = 'Select a contract';
quickPick.placeholder = 'Select a contract.';
quickPick.onDidChangeSelection((selection: Array<IFunctionQP>) => {
if (selection[0] && workspace.workspaceFolders) {
const { functionKey } = selection[0];
Expand All @@ -127,7 +127,7 @@ const selectContract = (context: ExtensionContext) => {
createFunctionInput(contract);
createDeployed(contract);

logger.success(`Contract ${name[0]} is selected`);
logger.success(`Contract ${name[0]} is selected.`);
}
});
quickPick.onDidHide(() => quickPick.dispose());
Expand Down
4 changes: 2 additions & 2 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createDeployedFile, writeConstructor, writeFunction } from '../lib/file
const createDeployed = (contract: CompiledJSONOutput) => {
const fullPath = getDeployedFullPath(contract);
if (fs.existsSync(fullPath)) {
logger.success("Functions input file already exists, remove it to add a empty file");
logger.success("Functions input file already exists, remove it to add a empty file.");
return;
}

Expand All @@ -32,7 +32,7 @@ const createDeployed = (contract: CompiledJSONOutput) => {
const createFunctionInput = (contract: CompiledJSONOutput) => {
const fullPath = getFunctionInputFullPath(contract);
if (fs.existsSync(fullPath)) {
logger.success("Functions input file already exists, remove it to add a empty file");
logger.success("Functions input file already exists, remove it to add a empty file.");
return;
}

Expand Down
21 changes: 11 additions & 10 deletions src/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ const callContractMethod = async (context: vscode.ExtensionContext) => {

const abi = getAbi(compiledOutput);
if (abi == undefined)
throw new Error("Abi is not defined");
throw new Error("Abi is not defined.");

const abiItem = await getFunctionInputs(context);
if (abiItem === undefined)
throw new Error("Please select a function to call");
throw new Error("Function is not defined.");

const params_ = abiItem.inputs?.map((e: any) => e.value);
const params = params_ === undefined ? [] : params_;

logger.success(`Calling the function : ${abiItem.name} of selected contract...`);
logger.success(`Calling ${compiledOutput.name} : ${abiItem.name} -->`);

const contractAddres = getDeployedInputs(context).address;
if (contractAddres === undefined)
throw new Error("Please input deployed address of selected contract");
throw new Error("Enter deployed address of selected contract.");

if (abiItem.stateMutability === 'view') {
const contract = new ethers.Contract(
Expand All @@ -130,15 +130,16 @@ const callContractMethod = async (context: vscode.ExtensionContext) => {
);

const result = await contract[abiItem.name as string](...params);
logger.success("Successfully called the function");
logger.success(`Calling ${compiledOutput.name} : ${abiItem.name} --> Success!`);
logger.log(JSON.stringify(result));
} else {
const contract = await getSignedContract(context, contractAddres);
const result = await contract[abiItem.name as string](...params);
logger.success("Waiting for confirmation...");

await result.wait();
logger.success("Mutable function was succcessfully called.");
logger.success("Transaction confirmed!");
logger.success(`Calling ${compiledOutput.name} : ${abiItem.name} --> Success!`);
}
} catch (err: any) {
logger.error(err);
Expand Down Expand Up @@ -171,11 +172,11 @@ const getSignedContract = async (context: vscode.ExtensionContext, contractAddre

const abi = getAbi(compiledOutput);
if (abi == undefined)
throw new Error("Abi is not defined");
throw new Error("Abi is not defined.");

const byteCode = getByteCode(compiledOutput);
if (byteCode == undefined)
throw new Error("ByteCode is not defined");
throw new Error("ByteCode is not defined.");

let contract;
if (isTestingNetwork(context)) {
Expand Down Expand Up @@ -205,11 +206,11 @@ const getContractFactoryWithParams = async (context: vscode.ExtensionContext): P

const abi = getAbi(compiledOutput);
if (abi == undefined)
throw new Error("Abi is not defined");
throw new Error("Abi is not defined.");

const byteCode = getByteCode(compiledOutput);
if (byteCode == undefined)
throw new Error("ByteCode is not defined");
throw new Error("ByteCode is not defined.");

let myContract;
if (isTestingNetwork(context)) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { logger } from '../lib';
const keythereum = require('keythereum');

import { toChecksumAddress } from '../lib/hash/util';
import { Account, GanacheAddressType, IAccountQP, LocalAddressType } from '../types';
import { Account, LocalAddressType } from '../types';
import { getSelectedNetwork, getSelectedProvider, isTestingNetwork } from './networks';

// list all local addresses
Expand Down