aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_encoder/evm_data_types
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-28 09:11:15 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commit029b8d59507df25aa9c7d1b096c8d873eb6ae4da (patch)
treee95e60341f55da870fee30e1fb9aa98d201125c4 /packages/utils/src/abi_encoder/evm_data_types
parent14c094d050e7b2d0a4b31d02dbe58a54153be7bb (diff)
downloaddexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.tar
dexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.tar.gz
dexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.tar.bz2
dexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.tar.lz
dexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.tar.xz
dexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.tar.zst
dexon-sol-tools-029b8d59507df25aa9c7d1b096c8d873eb6ae4da.zip
Changed constants to an exported enum; this is 0x convention
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_types')
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/address.ts6
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/array.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/bool.ts6
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts12
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/int.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/method.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts6
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/string.ts12
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/uint.ts4
9 files changed, 29 insertions, 29 deletions
diff --git a/packages/utils/src/abi_encoder/evm_data_types/address.ts b/packages/utils/src/abi_encoder/evm_data_types/address.ts
index 07a0bd10c..c45355639 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/address.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/address.ts
@@ -4,12 +4,12 @@ import * as _ from 'lodash';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
export class Address extends AbstractDataTypes.Blob {
private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true;
private static readonly _ADDRESS_SIZE_IN_BYTES = 20;
- private static readonly _DECODED_ADDRESS_OFFSET_IN_BYTES = Constants.EVM_WORD_WIDTH_IN_BYTES -
+ private static readonly _DECODED_ADDRESS_OFFSET_IN_BYTES = constants.EVM_WORD_WIDTH_IN_BYTES -
Address._ADDRESS_SIZE_IN_BYTES;
public static matchType(type: string): boolean {
@@ -30,7 +30,7 @@ export class Address extends AbstractDataTypes.Blob {
throw new Error(`Invalid address: '${value}'`);
}
const valueBuf = ethUtil.toBuffer(value);
- const encodedValueBuf = ethUtil.setLengthLeft(valueBuf, Constants.EVM_WORD_WIDTH_IN_BYTES);
+ const encodedValueBuf = ethUtil.setLengthLeft(valueBuf, constants.EVM_WORD_WIDTH_IN_BYTES);
return encodedValueBuf;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/array.ts b/packages/utils/src/abi_encoder/evm_data_types/array.ts
index a86283c2a..272cc4132 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/array.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/array.ts
@@ -2,7 +2,7 @@ import { DataItem } from 'ethereum-types';
import * as _ from 'lodash';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
export class Array extends AbstractDataTypes.Set {
private static readonly _MATCHER = RegExp('^(.+)\\[([0-9]*)\\]$');
@@ -23,7 +23,7 @@ export class Array extends AbstractDataTypes.Set {
throw new Error(`Could not parse array length: ${type}`);
}
const arrayElementType = matches[1];
- const arrayLength = _.isEmpty(matches[2]) ? undefined : parseInt(matches[2], Constants.DEC_BASE);
+ const arrayLength = _.isEmpty(matches[2]) ? undefined : parseInt(matches[2], constants.DEC_BASE);
return [arrayElementType, arrayLength];
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/bool.ts b/packages/utils/src/abi_encoder/evm_data_types/bool.ts
index 7af13506b..0c29f690a 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts
@@ -5,7 +5,7 @@ import * as _ from 'lodash';
import { BigNumber } from '../../configured_bignumber';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
export class Bool extends AbstractDataTypes.Blob {
private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true;
@@ -27,7 +27,7 @@ export class Bool extends AbstractDataTypes.Blob {
const encodedValue = value ? '0x1' : '0x0';
const encodedValueBuf = ethUtil.setLengthLeft(
ethUtil.toBuffer(encodedValue),
- Constants.EVM_WORD_WIDTH_IN_BYTES,
+ constants.EVM_WORD_WIDTH_IN_BYTES,
);
return encodedValueBuf;
}
@@ -35,7 +35,7 @@ export class Bool extends AbstractDataTypes.Blob {
public decodeValue(calldata: RawCalldata): boolean {
const valueBuf = calldata.popWord();
const valueHex = ethUtil.bufferToHex(valueBuf);
- const valueNumber = new BigNumber(valueHex, Constants.HEX_BASE);
+ const valueNumber = new BigNumber(valueHex, constants.HEX_BASE);
if (!(valueNumber.equals(0) || valueNumber.equals(1))) {
throw new Error(`Failed to decode boolean. Expected 0x0 or 0x1, got ${valueHex}`);
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
index ac2a1fb6e..2c256cfa9 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
export class DynamicBytes extends AbstractDataTypes.Blob {
private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = false;
@@ -37,10 +37,10 @@ export class DynamicBytes extends AbstractDataTypes.Blob {
// Encoded value is of the form: <length><value>, with each field padded to be word-aligned.
// 1/3 Construct the length
const valueBuf = ethUtil.toBuffer(value);
- const wordsToStoreValuePadded = Math.ceil(valueBuf.byteLength / Constants.EVM_WORD_WIDTH_IN_BYTES);
- const bytesToStoreValuePadded = wordsToStoreValuePadded * Constants.EVM_WORD_WIDTH_IN_BYTES;
+ const wordsToStoreValuePadded = Math.ceil(valueBuf.byteLength / constants.EVM_WORD_WIDTH_IN_BYTES);
+ const bytesToStoreValuePadded = wordsToStoreValuePadded * constants.EVM_WORD_WIDTH_IN_BYTES;
const lengthBuf = ethUtil.toBuffer(valueBuf.byteLength);
- const lengthBufPadded = ethUtil.setLengthLeft(lengthBuf, Constants.EVM_WORD_WIDTH_IN_BYTES);
+ const lengthBufPadded = ethUtil.setLengthLeft(lengthBuf, constants.EVM_WORD_WIDTH_IN_BYTES);
// 2/3 Construct the value
DynamicBytes._sanityCheckValue(value);
const valueBufPadded = ethUtil.setLengthRight(valueBuf, bytesToStoreValuePadded);
@@ -54,9 +54,9 @@ export class DynamicBytes extends AbstractDataTypes.Blob {
// 1/2 Decode length
const lengthBuf = calldata.popWord();
const lengthHex = ethUtil.bufferToHex(lengthBuf);
- const length = parseInt(lengthHex, Constants.HEX_BASE);
+ const length = parseInt(lengthHex, constants.HEX_BASE);
// 2/2 Decode value
- const wordsToStoreValuePadded = Math.ceil(length / Constants.EVM_WORD_WIDTH_IN_BYTES);
+ const wordsToStoreValuePadded = Math.ceil(length / constants.EVM_WORD_WIDTH_IN_BYTES);
const valueBufPadded = calldata.popWords(wordsToStoreValuePadded);
const valueBuf = valueBufPadded.slice(0, length);
const value = ethUtil.bufferToHex(valueBuf);
diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts
index 3e465fc15..244b720e3 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/int.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import { BigNumber } from '../../configured_bignumber';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
import * as EncoderMath from '../utils/math';
export class Int extends AbstractDataTypes.Blob {
@@ -26,7 +26,7 @@ export class Int extends AbstractDataTypes.Blob {
const matches = Int._MATCHER.exec(type);
const width =
!_.isNull(matches) && matches.length === 2 && !_.isUndefined(matches[1])
- ? parseInt(matches[1], Constants.DEC_BASE)
+ ? parseInt(matches[1], constants.DEC_BASE)
: Int._DEFAULT_WIDTH;
return width;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/method.ts b/packages/utils/src/abi_encoder/evm_data_types/method.ts
index bd4732097..7256a93d9 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/method.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts
@@ -3,7 +3,7 @@ import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';
import { AbstractDataTypes, DataType, DataTypeFactory } from '../abstract_data_types';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
import { DecodingRules, EncodingRules } from '../utils/rules';
import { Tuple } from './tuple';
@@ -62,7 +62,7 @@ export class Method extends AbstractDataTypes.Set {
ethUtil.toBuffer(
ethUtil
.sha3(signature)
- .slice(Constants.HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA, Constants.HEX_SELECTOR_LENGTH_IN_BYTES),
+ .slice(constants.HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA, constants.HEX_SELECTOR_LENGTH_IN_BYTES),
),
);
return selector;
diff --git a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts
index ed1f51f7e..5453d47a0 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
export class StaticBytes extends AbstractDataTypes.Blob {
private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true;
@@ -22,7 +22,7 @@ export class StaticBytes extends AbstractDataTypes.Blob {
const matches = StaticBytes._MATCHER.exec(type);
const width =
!_.isNull(matches) && matches.length === 3 && !_.isUndefined(matches[2])
- ? parseInt(matches[2], Constants.DEC_BASE)
+ ? parseInt(matches[2], constants.DEC_BASE)
: StaticBytes._DEFAULT_WIDTH;
return width;
}
@@ -45,7 +45,7 @@ export class StaticBytes extends AbstractDataTypes.Blob {
this._sanityCheckValue(value);
const valueBuf = ethUtil.toBuffer(value);
// 2/2 Store value as hex
- const valuePadded = ethUtil.setLengthRight(valueBuf, Constants.EVM_WORD_WIDTH_IN_BYTES);
+ const valuePadded = ethUtil.setLengthRight(valueBuf, constants.EVM_WORD_WIDTH_IN_BYTES);
return valuePadded;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/string.ts b/packages/utils/src/abi_encoder/evm_data_types/string.ts
index e5b2d5f33..ac62ea264 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/string.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/string.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
export class String extends AbstractDataTypes.Blob {
private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = false;
@@ -25,10 +25,10 @@ export class String extends AbstractDataTypes.Blob {
public encodeValue(value: string): Buffer {
// Encoded value is of the form: <length><value>, with each field padded to be word-aligned.
// 1/3 Construct the length
- const wordsToStoreValuePadded = Math.ceil(value.length / Constants.EVM_WORD_WIDTH_IN_BYTES);
- const bytesToStoreValuePadded = wordsToStoreValuePadded * Constants.EVM_WORD_WIDTH_IN_BYTES;
+ const wordsToStoreValuePadded = Math.ceil(value.length / constants.EVM_WORD_WIDTH_IN_BYTES);
+ const bytesToStoreValuePadded = wordsToStoreValuePadded * constants.EVM_WORD_WIDTH_IN_BYTES;
const lengthBuf = ethUtil.toBuffer(value.length);
- const lengthBufPadded = ethUtil.setLengthLeft(lengthBuf, Constants.EVM_WORD_WIDTH_IN_BYTES);
+ const lengthBufPadded = ethUtil.setLengthLeft(lengthBuf, constants.EVM_WORD_WIDTH_IN_BYTES);
// 2/3 Construct the value
const valueBuf = new Buffer(value);
const valueBufPadded = ethUtil.setLengthRight(valueBuf, bytesToStoreValuePadded);
@@ -42,9 +42,9 @@ export class String extends AbstractDataTypes.Blob {
// 1/2 Decode length
const lengthBufPadded = calldata.popWord();
const lengthHexPadded = ethUtil.bufferToHex(lengthBufPadded);
- const length = parseInt(lengthHexPadded, Constants.HEX_BASE);
+ const length = parseInt(lengthHexPadded, constants.HEX_BASE);
// 2/2 Decode value
- const wordsToStoreValuePadded = Math.ceil(length / Constants.EVM_WORD_WIDTH_IN_BYTES);
+ const wordsToStoreValuePadded = Math.ceil(length / constants.EVM_WORD_WIDTH_IN_BYTES);
const valueBufPadded = calldata.popWords(wordsToStoreValuePadded);
const valueBuf = valueBufPadded.slice(0, length);
const value = valueBuf.toString('ascii');
diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
index 970400a57..df7ea38a4 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import { BigNumber } from '../../configured_bignumber';
import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
-import * as Constants from '../utils/constants';
+import { constants } from '../utils/constants';
import * as EncoderMath from '../utils/math';
export class UInt extends AbstractDataTypes.Blob {
@@ -26,7 +26,7 @@ export class UInt extends AbstractDataTypes.Blob {
const matches = UInt._MATCHER.exec(type);
const width =
!_.isNull(matches) && matches.length === 2 && !_.isUndefined(matches[1])
- ? parseInt(matches[1], Constants.DEC_BASE)
+ ? parseInt(matches[1], constants.DEC_BASE)
: UInt._DEFAULT_WIDTH;
return width;
}