Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthBytes.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ethereum\DataType;
4 
6 
14 class EthBytes extends EthD
15 {
16 
33  public function validate($val, array $params)
34  {
35  if (!ctype_xdigit($this->removeHexPrefix($val))) {
36  throw new \InvalidArgumentException(
37  'Value of dynamic ABI type is not a valid hex string.'
38  );
39  }
40  return $this->ensureHexPrefix($val);
41  }
42 
54  public function validateLength($val)
55  {
56  if (strlen($val) % 2 !== 0) {
57  throw new \InvalidArgumentException(
58  'A valid bytes string must have a even number of letters.'
59  );
60  } else {
61  return $val;
62  }
63  }
64 
70  public static function cretateFromRLP($hexVal)
71  {
72  $rlpItem = Rlp::decode($hexVal);
73  return new EthBytes(self::ensureHexPrefix($rlpItem[0]->get()));
74  }
75 
82  public function hexVal()
83  {
84  return $this->value;
85  }
86 
90  public function encodedHexVal()
91  {
92  return $this->rlpVal();
93  }
94 
101  public function rlpVal()
102  {
103  return Rlp::encode($this->value);
104  }
105 
114  public function val()
115  {
116  return $this->removeHexPrefix($this->value);
117  }
118 
122  public static function getDataLengthType()
123  {
124  return 'dynamic';
125  }
126 
127 }
static cretateFromRLP($hexVal)
Definition: EthBytes.php:70
validate($val, array $params)
Definition: EthBytes.php:33
static decode(string $hexVal)
Definition: Rlp.php:100
static encode(string $val)
Definition: Rlp.php:43