diff --git a/packages/embark-utils/src/index.js b/packages/embark-utils/src/index.js index 2f05a16d7..79fb38969 100644 --- a/packages/embark-utils/src/index.js +++ b/packages/embark-utils/src/index.js @@ -16,6 +16,7 @@ import { decodeParams, sha3 } from './web3Utils'; +import { getAddressToContract, getTransactionParams } from './transactionUtils'; import AccountParser from './accountParser'; const { extendZeroAddressShorthand, replaceZeroAddressShorthand } = AddressUtils; @@ -186,6 +187,8 @@ const Utils = { decodeParams, dockerHostSwap, exit, + getAddressToContract, + getTransactionParams, isDocker, checkIsAvailable, findNextPort, diff --git a/packages/embark/src/lib/utils/transactionUtils.ts b/packages/embark-utils/src/transactionUtils.ts similarity index 92% rename from packages/embark/src/lib/utils/transactionUtils.ts rename to packages/embark-utils/src/transactionUtils.ts index 505f76070..980b28875 100644 --- a/packages/embark/src/lib/utils/transactionUtils.ts +++ b/packages/embark-utils/src/transactionUtils.ts @@ -1,18 +1,18 @@ import { Contract } from "embark"; -import { decodeParams, sha3 } from "embark-utils"; import { ABIDefinition } from "web3/eth/abi"; +import { decodeParams, sha3 } from "./web3Utils"; -export interface AddressToContract { +interface AddressToContract { name: string; functions: { [functionName: string]: FunctionSignature; }; silent?: boolean; } -export interface AddressToContractArray { +interface AddressToContractArray { [address: string]: AddressToContract; } -export interface FunctionSignature { +interface FunctionSignature { abi: ABIDefinition; functionName?: string; name: string; diff --git a/packages/embark/src/lib/modules/console_listener/index.js b/packages/embark/src/lib/modules/console_listener/index.js index f00db8026..e3ffc062d 100644 --- a/packages/embark/src/lib/modules/console_listener/index.js +++ b/packages/embark/src/lib/modules/console_listener/index.js @@ -1,6 +1,6 @@ const async = require('async'); const utils = require('../../utils/utils.js'); -const {getAddressToContract, getTransactionParams} = require('../../utils/transactionUtils'); +import { getAddressToContract, getTransactionParams } from 'embark-utils'; class ConsoleListener { constructor(embark, options) { diff --git a/packages/embark/src/lib/modules/tests/reporter.js b/packages/embark/src/lib/modules/tests/reporter.js index 1225eddd3..fd2581461 100644 --- a/packages/embark/src/lib/modules/tests/reporter.js +++ b/packages/embark/src/lib/modules/tests/reporter.js @@ -1,7 +1,7 @@ const Base = require('mocha/lib/reporters/base'); const ms = require('mocha/lib/ms'); const color = Base.color; -const {getAddressToContract, getTransactionParams} = require('../../utils/transactionUtils'); +import {getAddressToContract, getTransactionParams} from 'embark-utils'; class EmbarkApiSpec extends Base { constructor(runner, options) { diff --git a/packages/embark/src/test/modules/console_listener.js b/packages/embark/src/test/modules/console_listener.js index 031d9d732..6bdcd86dd 100644 --- a/packages/embark/src/test/modules/console_listener.js +++ b/packages/embark/src/test/modules/console_listener.js @@ -3,7 +3,7 @@ const {expect} = require('chai'); const sinon = require('sinon'); const Events = require('../../lib/core/events'); const Logger = require('embark-logger'); -const transactionUtils = require('../../lib/utils/transactionUtils'); +import { getAddressToContract } from 'embark-utils'; const ConsoleListener = require('../../lib/modules/console_listener'); const IPC = require('../../lib/core/ipc.js'); require('colors'); @@ -131,7 +131,7 @@ describe('Console Listener', function () { describe('#listenForLogRequests', function () { it('should emit the correct contracts logs', function (done) { - transactionUtils.getAddressToContract(contractsList, consoleListener.addressToContract); + getAddressToContract(contractsList, consoleListener.addressToContract); consoleListener._onIpcLogRequest(ipcRequest); const expectedContractLog = { @@ -174,7 +174,7 @@ describe('Console Listener', function () { it('should emit a log for a non-contract log', function (done) { ipcRequest.type = 'something-other-than-contract-log'; - transactionUtils.getAddressToContract(contractsList, consoleListener.addressToContract); + getAddressToContract(contractsList, consoleListener.addressToContract); consoleListener._onIpcLogRequest(ipcRequest); expect(loggerInfos[0]).to.be.equal(JSON.stringify(ipcRequest)); diff --git a/packages/embark/src/test/transactionUtils.js b/packages/embark/src/test/transactionUtils.js index af95e4b0c..361b4257f 100644 --- a/packages/embark/src/test/transactionUtils.js +++ b/packages/embark/src/test/transactionUtils.js @@ -1,6 +1,6 @@ /*globals describe, it, beforeEach*/ const {expect} = require('chai'); -const transactionUtils = require('../lib/utils/transactionUtils'); +import { getAddressToContract, getTransactionParams } from 'embark-utils'; require('colors'); let contractsList; @@ -78,20 +78,20 @@ describe('Transaction Utils', () => { describe('#getAddressToContract', () => { it('should not update contracts list when no contracts', () => { contractsList = []; - const result = transactionUtils.getAddressToContract(contractsList, {}); + const result = getAddressToContract(contractsList, {}); expect(result).to.deep.equal({}); }); it('should not update contracts list when not deployed', () => { contractsList[0].deployedAddress = undefined; - const result = transactionUtils.getAddressToContract(contractsList, {}); + const result = getAddressToContract(contractsList, {}); expect(result).to.deep.equal({}); }); it('should update contracts list', () => { - const result = transactionUtils.getAddressToContract(contractsList, {}); + const result = getAddressToContract(contractsList, {}); expect(result).to.deep.equal({ "0x12345": { @@ -160,8 +160,8 @@ describe('Transaction Utils', () => { describe('#getTransactionParams', () => { it('should return the param string and function name', () => { - const result = transactionUtils.getAddressToContract(contractsList, {}); - const {functionName, paramString} = transactionUtils.getTransactionParams(result['0x12345'], '0x60fe47b100000000000000000000000099db99c77ad807f89829f5bda99527438f64a798'); + const result = getAddressToContract(contractsList, {}); + const {functionName, paramString} = getTransactionParams(result['0x12345'], '0x60fe47b100000000000000000000000099db99c77ad807f89829f5bda99527438f64a798'); expect(functionName).to.equal('set'); expect(paramString).to.equal('878372847193751743539905734564138820017777321880');