Fixing TypeScript compiler using host paths for resolving constants.

This commit is contained in:
Richard Moore 2018-08-02 21:34:10 -04:00
parent bacf42a22f
commit 421b2c857b
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
7 changed files with 35 additions and 37 deletions

View File

@ -4,8 +4,9 @@ import { Indexed, Interface } from './interface';
import { defaultAbiCoder, formatSignature, parseSignature } from '../utils/abi-coder';
import { getAddress, getContractAddress } from '../utils/address';
import { BigNumber, bigNumberify, ConstantZero } from '../utils/bignumber';
import { BigNumber, bigNumberify } from '../utils/bignumber';
import { hexDataLength, hexDataSlice, isHexString } from '../utils/bytes';
import { Zero } from '../utils/constants';
import { defineReadOnly, jsonCopy, shallowCopy } from '../utils/properties';
import { poll } from '../utils/web';
@ -139,7 +140,7 @@ function runMethod(contract: Contract, functionName: string, estimateOnly: boole
// Call (constant functions) always cost 0 ether
if (estimateOnly) {
return Promise.resolve(ConstantZero);
return Promise.resolve(Zero);
}
if (!contract.provider) {

View File

@ -6,7 +6,7 @@ import * as providers from './providers';
import { HDNode, SigningKey, Wallet } from './wallet';
import { constants } from './utils/constants';
import * as constants from './utils/constants';
import * as errors from './utils/errors';
import * as utils from './utils';

View File

@ -3,8 +3,9 @@
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
import { getAddress } from './address';
import { BigNumber, bigNumberify, ConstantNegativeOne, ConstantZero, ConstantOne, ConstantMaxUint256 } from './bignumber';
import { BigNumber, bigNumberify } from './bignumber';
import { arrayify, concat, hexlify, padZeros } from './bytes';
import { NegativeOne, Zero, One, MaxUint256 } from '../utils/constants';
import { toUtf8Bytes, toUtf8String } from './utf8';
import { defineReadOnly, jsonCopy } from './properties';
@ -449,11 +450,11 @@ class CoderNumber extends Coder {
try {
let v = bigNumberify(value);
if (this.signed) {
let bounds = ConstantMaxUint256.maskn(this.size * 8 - 1);
let bounds = MaxUint256.maskn(this.size * 8 - 1);
if (v.gt(bounds)) { throw new Error('out-of-bounds'); }
bounds = bounds.add(ConstantOne).mul(ConstantNegativeOne);
bounds = bounds.add(One).mul(NegativeOne);
if (v.lt(bounds)) { throw new Error('out-of-bounds'); }
} else if (v.lt(ConstantZero) || v.gt(ConstantMaxUint256.maskn(this.size * 8))) {
} else if (v.lt(Zero) || v.gt(MaxUint256.maskn(this.size * 8))) {
throw new Error('out-of-bounds');
}

View File

@ -188,9 +188,3 @@ export function bigNumberify(value: BigNumberish): BigNumber {
return new BigNumber(value);
}
export const ConstantNegativeOne = bigNumberify(-1);
export const ConstantZero = bigNumberify(0);
export const ConstantOne = bigNumberify(1);
export const ConstantTwo = bigNumberify(2);
export const ConstantWeiPerEther = bigNumberify('1000000000000000000');
export const ConstantMaxUint256 = bigNumberify('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');

View File

@ -1,11 +1,4 @@
import {
ConstantNegativeOne,
ConstantZero,
ConstantOne,
ConstantTwo,
ConstantWeiPerEther,
ConstantMaxUint256
} from './bignumber';
import { BigNumber, bigNumberify } from './bignumber';
const AddressZero = '0x0000000000000000000000000000000000000000';
const HashZero = '0x0000000000000000000000000000000000000000000000000000000000000000';
@ -16,16 +9,23 @@ const HashZero = '0x000000000000000000000000000000000000000000000000000000000000
// NFKC (composed)
const EtherSymbol = '\u039e';
export const constants = {
AddressZero: AddressZero,
HashZero: HashZero,
const NegativeOne: BigNumber = bigNumberify(-1);
const Zero: BigNumber = bigNumberify(0);
const One: BigNumber = bigNumberify(1);
const Two: BigNumber = bigNumberify(2);
const WeiPerEther: BigNumber = bigNumberify('1000000000000000000');
const MaxUint256: BigNumber = bigNumberify('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
EtherSymbol: EtherSymbol,
export {
AddressZero,
HashZero,
NegativeOne: ConstantNegativeOne,
Zero: ConstantZero,
One: ConstantOne,
Two: ConstantTwo,
WeiPerEther: ConstantWeiPerEther,
MaxUint256: ConstantMaxUint256
EtherSymbol,
NegativeOne,
Zero,
One,
Two,
WeiPerEther,
MaxUint256
};

View File

@ -2,8 +2,9 @@
import { recoverAddress } from './secp256k1';
import { getAddress } from './address';
import { BigNumber, bigNumberify, ConstantZero } from './bignumber';
import { BigNumber, bigNumberify } from './bignumber';
import { arrayify, hexlify, hexZeroPad, splitSignature, stripZeros, } from './bytes';
import { Zero } from './constants';
import { keccak256 } from './keccak256';
import * as RLP from './rlp';
@ -58,7 +59,7 @@ function handleAddress(value: string): string {
}
function handleNumber(value: string): BigNumber {
if (value === '0x') { return ConstantZero; }
if (value === '0x') { return Zero; }
return bigNumberify(value);
}

View File

@ -1,6 +1,7 @@
'use strict';
import { BigNumber, bigNumberify, ConstantZero, ConstantNegativeOne } from './bignumber';
import { BigNumber, bigNumberify } from './bignumber';
import { Zero, NegativeOne } from './constants';
// Imported Types
import { BigNumberish } from './bignumber';
@ -79,8 +80,8 @@ export function formatUnits(value: BigNumberish, unitType?: string | number, opt
// Make sure wei is a big number (convert as necessary)
value = bigNumberify(value);
var negative = value.lt(ConstantZero);
if (negative) { value = value.mul(ConstantNegativeOne); }
var negative = value.lt(Zero);
if (negative) { value = value.mul(NegativeOne); }
var fraction = value.mod(unitInfo.tenPower).toString();
while (fraction.length < unitInfo.decimals) { fraction = '0' + fraction; }
@ -153,7 +154,7 @@ export function parseUnits(value: string, unitType?: string | number): BigNumber
let wei = (wholeValue.mul(unitInfo.tenPower)).add(fractionValue);
if (negative) { wei = wei.mul(ConstantNegativeOne); }
if (negative) { wei = wei.mul(NegativeOne); }
return wei;
}