Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthD20.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ethereum\DataType;
4 
6 
14 class EthD20 extends EthD
15 {
28  public function validateLength($val)
29  {
30  $un_padded = $this->unPadEnsureLength($val);
31  if ($un_padded) {
32  return $un_padded;
33  } else {
34  throw new \InvalidArgumentException('Invalid length for hex binary: ' . $val);
35  }
36  }
37 
50  public static function unPadEnsureLength($string)
51  {
52 
53  // Remove leading zeros.
54  // See: https://regex101.com/r/O2Rpei/5
55  $matches = [];
56  if (preg_match('/^0x0*([0-9,a-f]{40})$/is', self::ensureHexPrefix($string), $matches)) {
57  $address = '0x' . $matches[1];
58  // Throws an Exception if not valid.
59  if (self::isValidAddress($address, true)) {
60  return $address;
61  }
62  }
63  return null;
64  }
65 
71  public function isNotNull() {
72  $checkForValue = new EthQ($this->value);
73  return $checkForValue->isNotNull();
74  }
75 
79  public static function getDataLengthType()
80  {
81  return 'static';
82  }
83 
84 }
static unPadEnsureLength($string)
Definition: EthD20.php:50
static getDataLengthType()
Definition: EthD20.php:79