aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_encoder/evm_data_types/uint.ts
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-26 10:24:46 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commit9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0 (patch)
tree1978be0aa6086aeba0337d37dae01e26871278f9 /packages/utils/src/abi_encoder/evm_data_types/uint.ts
parentbb4d02e413119132f283ee17549cf5e1732d75b5 (diff)
downloaddexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar
dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.gz
dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.bz2
dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.lz
dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.xz
dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.zst
dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.zip
Payload -> Blob, Dependent -> Pointer, Member -> Set
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_types/uint.ts')
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/uint.ts16
1 files changed, 7 insertions, 9 deletions
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 832ab075c..b1bc690d8 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
@@ -2,21 +2,21 @@
import { DataItem } from 'ethereum-types';
import { BigNumber } from '../../configured_bignumber';
-import { DataTypeFactory, PayloadDataType } from '../abstract_data_types';
+import { AbstractDataTypes, DataTypeFactory } from '../abstract_data_types';
import { RawCalldata } from '../calldata';
import * as Constants from '../utils/constants';
import * as EncoderMath from '../utils/math';
-export class UInt extends PayloadDataType {
+export class UInt extends AbstractDataTypes.Blob {
private static readonly _MATCHER = RegExp(
'^uint(8|16|24|32|40|48|56|64|72|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256){0,1}$',
);
private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true;
private static readonly _MAX_WIDTH: number = 256;
private static readonly _DEFAULT_WIDTH: number = UInt._MAX_WIDTH;
- private _width: number;
- private _minValue: BigNumber;
- private _maxValue: BigNumber;
+ private static readonly _MIN_VALUE = new BigNumber(0);
+ private readonly _width: number;
+ private readonly _maxValue: BigNumber;
public static matchType(type: string): boolean {
return UInt._MATCHER.test(type);
@@ -36,18 +36,17 @@ export class UInt extends PayloadDataType {
throw new Error(`Tried to instantiate UInt with bad input: ${dataItem}`);
}
this._width = UInt._decodeWidthFromType(dataItem.type);
- this._minValue = new BigNumber(0);
this._maxValue = new BigNumber(2).toPower(this._width).sub(1);
}
public encodeValue(value: BigNumber | string | number): Buffer {
- const encodedValue = EncoderMath.safeEncodeNumericValue(value, this._minValue, this._maxValue);
+ const encodedValue = EncoderMath.safeEncodeNumericValue(value, UInt._MIN_VALUE, this._maxValue);
return encodedValue;
}
public decodeValue(calldata: RawCalldata): BigNumber {
const valueBuf = calldata.popWord();
- const value = EncoderMath.safeDecodeNumericValue(valueBuf, this._minValue, this._maxValue);
+ const value = EncoderMath.safeDecodeNumericValue(valueBuf, UInt._MIN_VALUE, this._maxValue);
return value;
}
@@ -55,4 +54,3 @@ export class UInt extends PayloadDataType {
return `uint${this._width}`;
}
}
-