diff --git a/packages/embark-utils/package.json b/packages/embark-utils/package.json index 14273a2f0..c88d0c630 100644 --- a/packages/embark-utils/package.json +++ b/packages/embark-utils/package.json @@ -54,9 +54,10 @@ "i18n": "0.8.3", "merge": "1.2.1", "multihashes": "0.4.14", - "web3": "1.0.0-beta.37", "ora": "2.1.0", "web3": "1.0.0-beta.37", + "web3-eth": "1.0.0-beta.37", + "web3-eth-abi": "1.0.0-beta.37", "shelljs": "0.5.3" }, "devDependencies": { diff --git a/packages/embark-utils/src/index.js b/packages/embark-utils/src/index.js index 9428e9a32..2f05a16d7 100644 --- a/packages/embark-utils/src/index.js +++ b/packages/embark-utils/src/index.js @@ -10,7 +10,12 @@ const toposortGraph = require('./toposort'); import { unitRegex } from './constants'; import * as AddressUtils from './addressUtils'; const web3 = require("web3"); -import { getWeiBalanceFromString, getHexBalanceFromString } from './web3Utils'; +import { + getWeiBalanceFromString, + getHexBalanceFromString, + decodeParams, + sha3 +} from './web3Utils'; import AccountParser from './accountParser'; const { extendZeroAddressShorthand, replaceZeroAddressShorthand } = AddressUtils; @@ -178,6 +183,7 @@ const Utils = { deconstructUrl, defaultCorsHost, defaultHost, + decodeParams, dockerHostSwap, exit, isDocker, @@ -192,6 +198,7 @@ const Utils = { getWeiBalanceFromString, getHexBalanceFromString, sha512, + sha3, timer, unitRegex, runCmd, diff --git a/packages/embark-utils/src/web3Utils.ts b/packages/embark-utils/src/web3Utils.ts index bf2d7527e..8710a8d05 100644 --- a/packages/embark-utils/src/web3Utils.ts +++ b/packages/embark-utils/src/web3Utils.ts @@ -1,5 +1,7 @@ import { __ } from "i18n"; import { balanceRegex } from "./constants"; +const Web3EthAbi = require("web3-eth-abi"); +const Web3 = require("web3"); export function getHexBalanceFromString(balanceString: string, web3: any) { if (!web3) { @@ -39,3 +41,11 @@ export function getWeiBalanceFromString(balanceString: string, web3: any) { return web3.utils.toWei(match[1], match[2]); } + +export function decodeParams(typesArray: any, hexString: string) { + return Web3EthAbi.decodeParameters(typesArray, hexString); +} + +export function sha3(arg: any) { + return Web3.utils.sha3(arg); +} diff --git a/packages/embark/src/lib/modules/deploytracker/index.js b/packages/embark/src/lib/modules/deploytracker/index.js index f4b7fb146..4a0902ec1 100644 --- a/packages/embark/src/lib/modules/deploytracker/index.js +++ b/packages/embark/src/lib/modules/deploytracker/index.js @@ -1,4 +1,4 @@ -let utils = require('../../utils/utils.js'); +import { sha3 } from 'embark-utils'; class DeployTracker { @@ -87,7 +87,7 @@ class DeployTracker { trackContract(contractName, code, args, address) { if (!this.currentChain) return false; - this.currentChain.contracts[utils.sha3(code + contractName + args.join(','))] = { + this.currentChain.contracts[sha3(code + contractName + args.join(','))] = { name: contractName, address: address }; @@ -95,7 +95,7 @@ class DeployTracker { getContract(contractName, code, args) { if (!this.currentChain) return false; - let contract = this.currentChain.contracts[utils.sha3(code + contractName + args.join(','))]; + let contract = this.currentChain.contracts[sha3(code + contractName + args.join(','))]; if (contract && contract.address === undefined) { return false; } diff --git a/packages/embark/src/lib/utils/transactionUtils.ts b/packages/embark/src/lib/utils/transactionUtils.ts index f8965e855..505f76070 100644 --- a/packages/embark/src/lib/utils/transactionUtils.ts +++ b/packages/embark/src/lib/utils/transactionUtils.ts @@ -1,7 +1,6 @@ -import {Contract} from "embark"; -import {ABIDefinition} from "web3/eth/abi"; - -const utils = require("./utils"); +import { Contract } from "embark"; +import { decodeParams, sha3 } from "embark-utils"; +import { ABIDefinition } from "web3/eth/abi"; export interface AddressToContract { name: string; @@ -37,7 +36,7 @@ export function getAddressToContract(contractsList: Contract[], addressToContrac .filter((func: ABIDefinition) => func.type === "function") .map((func: ABIDefinition) => { const name = `${func.name}(${func.inputs ? func.inputs.map((input) => input.type).join(",") : ""})`; - funcSignatures[utils.sha3(name).substring(0, 10)] = { + funcSignatures[sha3(name).substring(0, 10)] = { abi: func, functionName: func.name, name, @@ -59,7 +58,7 @@ export function getTransactionParams(contract: AddressToContract, transactionInp let paramString = ""; if (func && func.abi && func.abi.inputs) { - const decodedParameters = utils.decodeParams(func.abi.inputs, transactionInput.substring(10)); + const decodedParameters = decodeParams(func.abi.inputs, transactionInput.substring(10)); func.abi.inputs.forEach((input) => { const quote = input.type.indexOf("int") === -1 ? '"' : ""; paramString += quote + decodedParameters[input.name] + quote + ", "; diff --git a/packages/embark/src/lib/utils/utils.js b/packages/embark/src/lib/utils/utils.js index a04fdf6ee..1846472f4 100644 --- a/packages/embark/src/lib/utils/utils.js +++ b/packages/embark/src/lib/utils/utils.js @@ -287,21 +287,11 @@ function isValidDomain(v) { return isValid; } -function decodeParams(typesArray, hexString) { - var Web3EthAbi = require('web3-eth-abi'); - return Web3EthAbi.decodeParameters(typesArray, hexString); -} - function toChecksumAddress(address) { const Web3 = require('web3'); return Web3.utils.toChecksumAddress(address); } -function sha3(arg) { - const Web3 = require('web3'); - return Web3.utils.sha3(arg); -} - /** * Builds a URL * @@ -462,7 +452,6 @@ module.exports = { hexToNumber, isValidDomain, pingEndpoint, - decodeParams, cd, sed, downloadFile, @@ -470,7 +459,6 @@ module.exports = { extractZip, getExternalContractUrl, toChecksumAddress, - sha3, normalizeInput, buildUrl, buildUrlFromConfig,