Skip to content
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
9 changes: 1 addition & 8 deletions ext-src/api.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
/* eslint class-methods-use-this: "warn" */

import { ICompilationResult } from './types';
import { ExtensionContext, commands } from 'vscode';
import { ReactPanel } from './reactPanel';
import { commands } from 'vscode';

export default class API {
// ctx: ExtensionContext;

// constructor(context: ExtensionContext) {
// this.ctx = context;
// }

loadCompiled(compilationRes: ICompilationResult) {
commands.executeCommand('ethcode.standard-json.load', compilationRes.data);
}
Expand Down
7 changes: 1 addition & 6 deletions ext-src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// @ts-ignore
import { ethers } from 'ethers';
import * as vscode from 'vscode';
import { InputBoxOptions, window, commands, workspace } from 'vscode';
import API from './api';
import { ReactPanel } from './reactPanel';
import Logger from './utils/logger';
import {
IAccountQP,
Expand Down Expand Up @@ -167,7 +165,7 @@ export async function activate(context: vscode.ExtensionContext) {
// List local Accounts
commands.registerCommand('ethcode.account.list', () => {
const accWorker = createAccWorker();
accWorker.on('message', (m) => {
accWorker.on('message', (m: any) => {
if (m.localAddresses) {
context.workspaceState.update('addresses', <Array<LocalAddressType>>m.localAddresses);
logger.log(JSON.stringify(m.localAddresses));
Expand Down Expand Up @@ -460,9 +458,6 @@ export async function activate(context: vscode.ExtensionContext) {
const gas = await window.showInputBox(gasInp);
context.workspaceState.update('gasEstimate', gas);
}),
commands.registerCommand('ethcode.show', async () => {
ReactPanel.createOrShow(context.extensionPath, context.workspaceState);
}),
// Activate
commands.registerCommand('ethcode.activate', async () => {
commands.executeCommand('ethcode.account.list');
Expand Down
1 change: 0 additions & 1 deletion ext-src/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ext-src/lib/accWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function extractPvtKey(keyStorePath: string, address: string, pswd: string) {

// worker communication
// @ts-ignore
process.on('message', (m) => {
process.on('message', (m: any) => {
if (m.command === 'create-account') {
createKeyPair(m.ksPath, m.pswd);
}
Expand Down
22 changes: 0 additions & 22 deletions ext-src/lib/proto.ts

This file was deleted.

7 changes: 3 additions & 4 deletions ext-src/lib/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { sha3 } from '../hash/sha3';
import { clientCallClient } from './proto';
// import { sha3 } from '../hash/sha3';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const EthereumTx = require('ethereumjs-tx').Transaction;
// const EthereumTx = require('ethereumjs-tx').Transaction;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { formatters } = require('web3-core-helpers');
// const { formatters } = require('web3-core-helpers');

// sign raw transaction and deploy
export function deployUnsignedTx(meta: any, tx: string, privateKey: string, testnetId: number) {
Expand Down
236 changes: 2 additions & 234 deletions ext-src/lib/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as fs from 'fs';
import * as grpc from '@grpc/grpc-js';
import { ABIDescription, ABIParameter } from '../types';
import { clientCallClient } from './proto';
import { deployUnsignedTx, deployGanacheTx, getTransaction, getTransactionReceipt } from './transactions';
import * as path from 'path';

function flatten(lists: any) {
Expand Down Expand Up @@ -80,238 +77,9 @@ const loadAllCompiledJsonOutputs = (path_: string) => {
};

// @ts-ignore
process.on('message', async (m) => {
const meta = new grpc.Metadata();
// Fetch accounts and balance
if (m.command === 'get-accounts') {
const c = {
networkid: m.testnetId,
};
clientCallClient.GetGanacheAccounts(c, meta, (err: any, response: any) => {
if (err) {
console.log('err', err);
// @ts-ignore
process.send({ error: err });
} else {
// @ts-ignore
process.send({ accounts: response.accounts, balance: response.balance });
}
});
}
// send wei value to address in other testnets
if (m.command === 'send-ether-signed') {
const { transactionInfo, pvtKey } = m.payload;
const c = {
callInterface: {
command: 'build-raw-eth-tx',
payload: JSON.stringify(transactionInfo),
testnetId: m.testnetId,
},
};
const call = clientCallClient.RunDeploy(c, meta, (err: any) => {
if (err) {
console.error('err', err);
// @ts-ignore
process.send({ error: err });
// @ts-ignore
process.exit(1);
}
});
call.on('data', (data: any) => {
// @ts-ignore
process.send({ unsignedTx: data.result });
deployUnsignedTx(meta, data.result, pvtKey, m.testnetId);
});
call.on('error', (err: Error) => {
// @ts-ignore
process.send({ error: err });
// @ts-ignore
process.exit(1);
});
}
// send wei_value to a address
if (m.command === 'send-ether') {
const { transactionInfo } = m;
const c = {
callInterface: {
command: 'send-ether',
payload: JSON.stringify(transactionInfo),
testnetId: m.testnetId,
},
};
const call = clientCallClient.RunDeploy(c, meta, (err: any, response: any) => {
if (err) {
// @ts-ignore
process.send({ error: err });
// @ts-ignore
process.exit(1);
} else {
// @ts-ignore
process.send({ response });
}
});
call.on('data', (data: any) => {
// @ts-ignore
process.send({ transactionResult: data.result });
});
}
// fetch balance of an account
if (m.command === 'get-balance') {
const hashAddr = m.account;
const c = {
networkid: m.testnetId,
address: hashAddr,
};
clientCallClient.GetBalance(c, meta, (err: any, response: any) => {
if (err) {
// @ts-ignore
process.send({ error: err });
} else {
// @ts-ignore
process.send({ balance: response.balance });
}
});
}
// Method call
if (m.command === 'ganache-contract-method-call') {
const { from, abi, address, methodName, params, gasSupply, deployAccount, value } = m.payload;
const inp = {
from,
abi,
address,
methodName,
params,
gasSupply: typeof gasSupply === 'string' ? parseInt(gasSupply, 10) : gasSupply,
deployAccount,
value,
};
const c = {
callInterface: {
command: 'ganache-contract-method-call',
payload: JSON.stringify(inp),
testnetId: m.testnetId,
},
};
const call = clientCallClient.EthCall(c, meta, (err: any, response: any) => {
if (err) {
console.log('err', err);
} else {
// @ts-ignore
process.send({ response });
}
});
call.on('data', (data: any) => {
// @ts-ignore
process.send({ callResult: data.result });
});
call.on('end', () => {
process.exit(0);
});
call.on('error', (err: Error) => {
// @ts-ignore
process.send({ error: err });
});
}

// testnet method call
if (m.command === 'contract-method-call') {
/*
const { from, abi, address, methodName, params, gasSupply, value } = m.payload;
const c = new CallRequest();
c.setNetworkid(m.testnetId);
c.setFromaddress(from);
c.setAbi(JSON.stringify(abi));
c.setAddress(address);
c.setFn(methodName);
c.setParams(JSON.stringify(params));
c.setGas(0);
c.setValue(0);
clientCallClient.EthCall(c.toObject(), meta, (err: any, response: any) => {
console.log(response);
if (err) {
// @ts-ignore
process.send({ error: err });
} else {
// @ts-ignore
process.send({ callResult: response.result });
}
});
*/
}
// Gas Estimate
if (m.command === 'get-gas-estimate') {
/*
const { abi, bytecode, params, from } = m.payload;
const c = new EstimateGasReq();
c.setNetworkid(m.testnetId);
c.setAbi(JSON.stringify(abi));
c.setBytecode(bytecode);
c.setParams(JSON.stringify(params));
c.setFromaddress(from);
c.setValue(0);
console.log(c.toObject());
clientCallClient.EstimateGas(c.toObject(), meta, (err: any, response: any) => {
if (err) {
// @ts-ignore
process.send({ error: err });
} else {
// @ts-ignore
process.send({ gasEstimate: response.result });
}
});
*/
}
// Build raw transaction for contract creation
if (m.command === 'build-rawtx') {
/*
const { abi, bytecode, params, gasSupply, from } = m.payload;
const c = new BuildTxRequest();
c.setNetworkid(m.testnetId);
c.setAbi(JSON.stringify(abi));
c.setBytecode(bytecode);
c.setParams(JSON.stringify(params));
c.setFromaddress(from);
c.setGas(gasSupply);
c.setValue(0);
clientCallClient.BuildRawTransaction(c.toObject(), meta, (err: any, response: any) => {
if (err) {
console.error('err', err);
// @ts-ignore
process.send({ error: err });
} else {
// @ts-ignore
process.send({ buildTxResult: response.transaction });
}
});
*/
}
// sign and deploy unsigned transaction
if (m.command === 'sign-deploy') {
const { unsignedTx, pvtKey } = m.payload;
deployUnsignedTx(meta, unsignedTx, pvtKey, m.testnetId);
}
// Deploy
if (m.command === 'deploy-contract') {
deployGanacheTx(meta, m.payload);
}
if (m.command === 'create-input-file') {
const { inputs, path } = m.payload;
writeConstrucor(path, inputs);
}
if (m.command === 'create-function-input') {
const { path, abiItem } = m.payload;
writeFunction(path, abiItem);
}
if (m.command === 'get-transaction') {
const { txhash } = m.payload;
getTransaction(meta, txhash, m.testnetId);
}
if (m.command === 'get-transaction-receipt') {
const { txhash } = m.payload;
getTransactionReceipt(meta, txhash, m.testnetId);
}
process.on('message', async (m: any) => {
if (m.command === 'load-all-compiled-json') {
const { path } = m.payload;
loadAllCompiledJsonOutputs(path);
}
});
});
Loading