From a67de2d74e3cda49c9b5a7ae0520d4ec9b764ca7 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Tue, 31 Oct 2023 14:15:47 -0500 Subject: [PATCH] option to keep padding for quantities --- src.ts/utils/maths.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src.ts/utils/maths.ts b/src.ts/utils/maths.ts index c259147151..65815fe38a 100644 --- a/src.ts/utils/maths.ts +++ b/src.ts/utils/maths.ts @@ -228,13 +228,13 @@ export function toBeArray(_value: BigNumberish): Uint8Array { /** * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//. * - * A //Quantity// does not have and leading 0 values unless the value is + * A //Quantity// does not have any leading 0 values unless the value is * the literal value `0x0`. This is most commonly used for JSSON-RPC * numeric values. */ -export function toQuantity(value: BytesLike | BigNumberish): string { +export function toQuantity(value: BytesLike | BigNumberish, keepPadding = false): string { let result = hexlify(isBytesLike(value) ? value: toBeArray(value)).substring(2); - while (result.startsWith("0")) { result = result.substring(1); } + while (!keepPadding && result.startsWith("0")) { result = result.substring(1); } if (result === "") { result = "0"; } return "0x" + result; }