mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-02 08:56:11 +00:00
refactor(@embark/utils): move web3 dependent functions into web3Utils
This commit is contained in:
parent
baf6f20066
commit
dd898f0c7a
@ -9,12 +9,13 @@ const logUtils = require('./log-utils');
|
||||
const toposortGraph = require('./toposort');
|
||||
import { unitRegex } from './constants';
|
||||
import * as AddressUtils from './addressUtils';
|
||||
const web3 = require("web3");
|
||||
import {
|
||||
getWeiBalanceFromString,
|
||||
getHexBalanceFromString,
|
||||
decodeParams,
|
||||
sha3
|
||||
sha3,
|
||||
isHex,
|
||||
soliditySha3
|
||||
} from './web3Utils';
|
||||
import { getAddressToContract, getTransactionParams } from './transactionUtils';
|
||||
import AccountParser from './accountParser';
|
||||
@ -41,11 +42,6 @@ function checkIsAvailable(url, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function isHex(hex) {
|
||||
const Web3 = require('web3');
|
||||
return Web3.utils.isHex(hex);
|
||||
}
|
||||
|
||||
function hashTo32ByteHexString(hash) {
|
||||
if (isHex(hash)) {
|
||||
if (!hash.startsWith('0x')) {
|
||||
@ -59,11 +55,6 @@ function hashTo32ByteHexString(hash) {
|
||||
return '0x' + multihash.toHexString(digest);
|
||||
}
|
||||
|
||||
function soliditySha3(arg) {
|
||||
const Web3 = require('web3');
|
||||
return Web3.utils.soliditySha3(arg);
|
||||
}
|
||||
|
||||
function sha512(arg) {
|
||||
if (typeof arg !== 'string') {
|
||||
throw new TypeError('argument must be a string');
|
||||
@ -145,11 +136,11 @@ function prepareContractsConfig(config) {
|
||||
const onDeploy = config.contracts[contractName].onDeploy;
|
||||
|
||||
if (gas && gas.toString().match(unitRegex)) {
|
||||
config.contracts[contractName].gas = getWeiBalanceFromString(gas, web3);
|
||||
config.contracts[contractName].gas = getWeiBalanceFromString(gas);
|
||||
}
|
||||
|
||||
if (gasPrice && gasPrice.toString().match(unitRegex)) {
|
||||
config.contracts[contractName].gasPrice = getWeiBalanceFromString(gasPrice, web3);
|
||||
config.contracts[contractName].gasPrice = getWeiBalanceFromString(gasPrice);
|
||||
}
|
||||
|
||||
if (address) {
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { __ } from "i18n";
|
||||
import { balanceRegex } from "./constants";
|
||||
const Web3EthAbi = require("web3-eth-abi");
|
||||
const Web3 = require("web3");
|
||||
const web3 = require("web3");
|
||||
|
||||
export function getHexBalanceFromString(balanceString: string, web3: any) {
|
||||
if (!web3) {
|
||||
throw new Error(__("[getHexBalanceFromString]: Missing parameter 'web3'"));
|
||||
}
|
||||
export function getHexBalanceFromString(balanceString: string) {
|
||||
if (!balanceString) {
|
||||
return 0xFFFFFFFFFFFFFFFFFF;
|
||||
}
|
||||
@ -24,10 +21,7 @@ export function getHexBalanceFromString(balanceString: string, web3: any) {
|
||||
return web3.utils.toHex(web3.utils.toWei(match[1], match[2]));
|
||||
}
|
||||
|
||||
export function getWeiBalanceFromString(balanceString: string, web3: any) {
|
||||
if (!web3) {
|
||||
throw new Error(__("[getWeiBalanceFromString]: Missing parameter 'web3'"));
|
||||
}
|
||||
export function getWeiBalanceFromString(balanceString: string) {
|
||||
if (!balanceString) {
|
||||
return 0;
|
||||
}
|
||||
@ -47,5 +41,13 @@ export function decodeParams(typesArray: any, hexString: string) {
|
||||
}
|
||||
|
||||
export function sha3(arg: any) {
|
||||
return Web3.utils.sha3(arg);
|
||||
return web3.utils.sha3(arg);
|
||||
}
|
||||
|
||||
export function isHex(hex: string) {
|
||||
return web3.utils.isHex(hex);
|
||||
}
|
||||
|
||||
export function soliditySha3(arg: any) {
|
||||
return web3.utils.soliditySha3(arg);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user