From d35ecef5f76383bf5920e8860f2b4854f2101bc7 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Mon, 11 Feb 2019 00:10:14 +0800 Subject: [PATCH] Fix bytes and dynamic bytes format --- src/Contracts/Types/Bytes.php | 7 ++++--- src/Contracts/Types/DynamicBytes.php | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Contracts/Types/Bytes.php b/src/Contracts/Types/Bytes.php index 542ba74..f85fa03 100644 --- a/src/Contracts/Types/Bytes.php +++ b/src/Contracts/Types/Bytes.php @@ -63,9 +63,10 @@ class Bytes extends SolidityType implements IType } $value = Utils::stripZero($value); - // if (mb_strlen($value) % 2 !== 0) { - // throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value); - // } + if (mb_strlen($value) % 2 !== 0) { + $value = "0" . $value; + // throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value); + } if (mb_strlen($value) > 64) { throw new InvalidArgumentException('The value to inputFormat is too long.'); diff --git a/src/Contracts/Types/DynamicBytes.php b/src/Contracts/Types/DynamicBytes.php index e6461f8..7ca3d73 100644 --- a/src/Contracts/Types/DynamicBytes.php +++ b/src/Contracts/Types/DynamicBytes.php @@ -63,9 +63,10 @@ class DynamicBytes extends SolidityType implements IType } $value = Utils::stripZero($value); - // if (mb_strlen($value) % 2 !== 0) { - // throw new InvalidArgumentException('The value to inputFormat has invalid length.'); - // } + if (mb_strlen($value) % 2 !== 0) { + $value = "0" . $value; + // throw new InvalidArgumentException('The value to inputFormat has invalid length.'); + } $bn = Utils::toBn(floor(mb_strlen($value) / 2)); $bnHex = $bn->toHex(true); $padded = mb_substr($bnHex, 0, 1); @@ -98,4 +99,4 @@ class DynamicBytes extends SolidityType implements IType return '0x' . mb_substr($value, 64, $length); } -} +} \ No newline at end of file