17 private $intTypes = [
'int',
'uint'];
45 parent::__construct($val, $params);
64 $abi = isset($params[
'abi']) ? $params[
'abi'] : null;
69 $val = strtolower($val);
72 if (strlen(self::removeHexPrefix($val)) < self::HEXPADDING) {
73 $val = $this->padLeft($val);
77 if ($val[2] ===
'f') {
79 $big_int->is_negative =
true;
86 elseif (is_numeric($val)) {
89 $big_int->is_negative =
true;
95 if ($big_int && is_a($big_int,
'Math_BigInteger')) {
102 if ($this->abi !==
$abi) {
109 throw new \InvalidArgumentException(
110 'Given ABI (' .
$abi .
') does not match number given number: ' . $val);
117 throw new \InvalidArgumentException(
'Can not decode Hex number: ' . $val);
131 private static function padLeft(
string $val)
133 $unprefixed = self::removeHexPrefix($val);
134 $fillUp = self::HEXPADDING - (strlen($unprefixed) % self::HEXPADDING);
135 return self::ensureHexPrefix(str_repeat(
"0", $fillUp) . $unprefixed);
149 $negative = $number->is_negative;
158 $max_for_exp = $max_for_exp->bitwise_leftShift($exp - 1);
163 if ($number->compare($max_for_exp) <= 0) {
169 throw new \InvalidArgumentException(
'NOT IN RANGE: ' . $number->toString() .
' > (u)int256');
172 return 'int' . $abi_l;
176 return 'uint' . $abi_l;
196 $valid_length = in_array($abiObj->intLength, $this->getValidLengths());
197 $valid_type = in_array($abiObj->intType, $this->intTypes);
198 if (!($valid_length || $valid_type)) {
199 throw new \InvalidArgumentException(
'Can not validate ABI: ' .
$abi);
209 private static function abiAliases(
$abi)
212 if (
$abi ===
'int') {
215 if (
$abi ===
'uint') {
229 if (preg_match(
'/^(u?int)(\d{1,3})$/', self::abiAliases(
$abi),
233 'intType' => $matches[1],
234 'intLength' => $matches[2],
238 throw new \InvalidArgumentException(
'Could not decode ABI for: ' .
$abi);
251 $value = $this->value->toHex($this->value->is_negative);
253 if (strlen(
$value) > self::HEXPADDING) {
254 throw new \Exception(
'Values > (u)int32 not supported yet: ' .
$value);
258 $pad = self::HEXPADDING - strlen(
$value);
260 $fill = $this->value->is_negative ?
'f' :
'0';
261 $ret =
'0x' . str_repeat($fill, $pad) .
$value;
272 return '0x' . $this->value->toHex($this->value->is_negative);
282 return $type->intLength;
291 $type = $this->
splitAbi($this->abi);
297 if ($type->abi ===
'uint') {
316 return !((string)((
int)$val->toString()) === $val->toString());
329 return $this->value->toString();
332 return (
int)$this->value->toString();
352 return ($this->value->compare($null) > 0 || $this->value->compare($null) < 0);
377 $valid_lengths =
"8;16;24;32;40;48;56;64;72;80;88;96;104;112;120;128;136;144;152;160;168;176;184;192;200;208;216;224;232;240;248;256";
378 return explode(
';', $valid_lengths);
getAbiFromNumber(Math_BigInteger $number)
validate($val, array $params)
static getDataLengthType()
__construct($val, array $params=[])
isLargeNumber(Math_BigInteger $val)
static hasHexPrefix($str)