From d5c21afec05eab232eb4168cadefc5cfeb2b7b2d Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sun, 24 Jun 2018 21:16:12 +0800 Subject: [PATCH] Fix decode bytes * Return non zero bytes. Decode bytes1 data: 0x6300000000000000000000000000000000000000000000000000000000000000 Will return 0x63 --- src/Contracts/Types/Bytes.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Contracts/Types/Bytes.php b/src/Contracts/Types/Bytes.php index 29e7fad..542ba74 100644 --- a/src/Contracts/Types/Bytes.php +++ b/src/Contracts/Types/Bytes.php @@ -36,7 +36,7 @@ class Bytes extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^bytes([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bytes([0-9]{1,})(\[([0-9]*)\])*$/', $name) === 1); } /** @@ -90,6 +90,11 @@ class Bytes extends SolidityType implements IType if (empty($checkZero)) { return '0'; } + if (preg_match('/^bytes([0-9]*)/', $name, $match) === 1) { + $size = intval($match[1]); + $length = 2 * $size; + $value = mb_substr($value, 0, $length); + } return '0x' . $value; } } \ No newline at end of file