Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthD32.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ethereum\DataType;
4 
12 class EthD32 extends EthD
13 {
26  public function validateLength($val)
27  {
28  if (strlen($val) <= 66) {
29  $padUp = 66 - strlen($val);
30  $val = $val . str_repeat('0', $padUp);
31  }
32  if (strlen($val) === 66) {
33  return $val;
34  }
35  else {
36  throw new \InvalidArgumentException('Invalid length for hex binary: ' . $val);
37  }
38  }
39 
43  public static function getDataLengthType()
44  {
45  return 'static';
46  }
47 
53  protected function getDataStrLength()
54  {
55  return 2 * preg_replace('/[^0-9]/', '', $this->abi);
56  }
57 
66  public function val()
67  {
68  if ($this->abi) {
69  // Shortening Data according to ABI lenngth if available.
70  return substr($this->value, 2, $this->getDataStrLength());
71  }
72  // Fall back on full 32 bytes if Abi is not set.
73  // It is recommended not to use bytes[1-31], as they all use same space/gas.
74  return substr($this->value, 2);
75  }
76 }
static getDataLengthType()
Definition: EthD32.php:43