diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-26 09:12:21 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | d2d89adbddaec435ddb65545a86fc4dc981de521 (patch) | |
tree | 0b95f1e18889440e67a534131aee7e6f18c73bd0 /packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts | |
parent | 58a2dfbc4d191ea21e6a749371e586dcff3b3239 (diff) | |
download | dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.tar dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.tar.gz dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.tar.bz2 dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.tar.lz dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.tar.xz dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.tar.zst dexon-sol-tools-d2d89adbddaec435ddb65545a86fc4dc981de521.zip |
Abstracted out encoding/decoding of numeric values into its own utility. Could be useful elsewhere.
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts')
-rw-r--r-- | packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts | 8 |
1 files changed, 4 insertions, 4 deletions
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 afa9afdf2..0d01e6105 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 @@ -8,18 +8,18 @@ import * as Constants from '../utils/constants'; export class StaticBytes extends PayloadDataType { private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true; - private static readonly _matcher = RegExp( + private static readonly _MATCHER = RegExp( '^(byte|bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32))$', ); private static readonly _DEFAULT_WIDTH = 1; private readonly _width: number; public static matchType(type: string): boolean { - return StaticBytes._matcher.test(type); + return StaticBytes._MATCHER.test(type); } private static _decodeWidthFromType(type: string): number { - const matches = StaticBytes._matcher.exec(type); + const matches = StaticBytes._MATCHER.exec(type); const width = (matches !== null && matches.length === 3 && matches[2] !== undefined) ? parseInt(matches[2], Constants.DEC_BASE) : StaticBytes._DEFAULT_WIDTH; @@ -55,7 +55,7 @@ export class StaticBytes extends PayloadDataType { this._sanityCheckValue(value); return value; } - + private _sanityCheckValue(value: string | Buffer): void { if (typeof value === 'string') { if (!value.startsWith('0x')) { |