aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-28 07:28:26 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commitf479212410b238a7673983148f403b3a220083af (patch)
tree4d3ebe1ee98ec0a03b8eb99275878f5cc2062123 /packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
parentffb8b0a619be3b8fb30a6acc99f590a6b40d49e1 (diff)
downloaddexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar
dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.gz
dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.bz2
dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.lz
dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.xz
dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.zst
dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.zip
Style cleanup. Improved wording of some error messages.
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts')
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts28
1 files changed, 15 insertions, 13 deletions
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 98d90b7e4..ad22c8c6e 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
@@ -1,4 +1,3 @@
-/* tslint:disable prefer-function-over-method */
import { DataItem } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';
@@ -14,6 +13,17 @@ export class DynamicBytes extends AbstractDataTypes.Blob {
return type === 'bytes';
}
+ private static _sanityCheckValue(value: string | Buffer): void {
+ if (typeof value !== 'string') {
+ return;
+ }
+ if (!_.startsWith(value, '0x')) {
+ throw new Error(`Tried to encode non-hex value. Value must inlcude '0x' prefix.`);
+ } else if (value.length % 2 !== 0) {
+ throw new Error(`Tried to assign ${value}, which is contains a half-byte. Use full bytes only.`);
+ }
+ }
+
public constructor(dataItem: DataItem, dataTypeFactory: DataTypeFactory) {
super(dataItem, dataTypeFactory, DynamicBytes._SIZE_KNOWN_AT_COMPILE_TIME);
if (!DynamicBytes.matchType(dataItem.type)) {
@@ -21,6 +31,8 @@ export class DynamicBytes extends AbstractDataTypes.Blob {
}
}
+ // Disable prefer-function-over-method for inherited abstract methods.
+ /* tslint:disable prefer-function-over-method */
public encodeValue(value: string | Buffer): Buffer {
// Encoded value is of the form: <length><value>, with each field padded to be word-aligned.
// 1/3 Construct the length
@@ -48,22 +60,12 @@ export class DynamicBytes extends AbstractDataTypes.Blob {
const valueBufPadded = calldata.popWords(wordsToStoreValuePadded);
const valueBuf = valueBufPadded.slice(0, length);
const value = ethUtil.bufferToHex(valueBuf);
- this._sanityCheckValue(value);
+ DynamicBytes._sanityCheckValue(value);
return value;
}
public getSignature(): string {
return 'bytes';
}
-
- private _sanityCheckValue(value: string | Buffer): void {
- if (typeof value !== 'string') {
- return;
- }
- if (!_.startsWith(value, '0x')) {
- throw new Error(`Tried to encode non-hex value. Value must inlcude '0x' prefix.`);
- } else if (value.length % 2 !== 0) {
- throw new Error(`Tried to assign ${value}, which is contains a half-byte. Use full bytes only.`);
- }
- }
+ /* tslint:enable prefer-function-over-method */
}