aboutsummaryrefslogblamecommitdiffstats
path: root/packages/utils/src/abi_encoder/evm_data_types/uint.ts
blob: 86b31ab4ca812ae14a3b51e08ea99e4c03b2cd31 (plain) (tree)
































                                                                                                                                       
/* tslint:disable prefer-function-over-method */
import { DataItem } from 'ethereum-types';

import { BigNumber } from '../../configured_bignumber';
import { DataTypeFactory } from '../data_type';

import { Number } from './number';

export class UInt extends Number {
    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}$',
    );

    public static matchType(type: string): boolean {
        return UInt._matcher.test(type);
    }

    public constructor(dataItem: DataItem, dataTypeFactory: DataTypeFactory) {
        super(dataItem, UInt._matcher, dataTypeFactory);
    }

    public getMaxValue(): BigNumber {
        return new BigNumber(2).toPower(this._width).sub(1);
    }

    public getMinValue(): BigNumber {
        return new BigNumber(0);
    }

    public getSignature(): string {
        return `uint${this._width}`;
    }
}