52 private const ABI_MAP = [
56 'address' =>
'EthD20',
71 'bytes' =>
'EthBytes',
89 'bytes10' =>
'EthD32',
90 'bytes11' =>
'EthD32',
91 'bytes12' =>
'EthD32',
92 'bytes13' =>
'EthD32',
93 'bytes14' =>
'EthD32',
94 'bytes15' =>
'EthD32',
95 'bytes16' =>
'EthD32',
96 'bytes17' =>
'EthD32',
97 'bytes18' =>
'EthD32',
98 'bytes19' =>
'EthD32',
99 'bytes20' =>
'EthD20',
100 'bytes21' =>
'EthD32',
101 'bytes22' =>
'EthD32',
102 'bytes23' =>
'EthD32',
103 'bytes24' =>
'EthD32',
104 'bytes25' =>
'EthD32',
105 'bytes26' =>
'EthD32',
106 'bytes27' =>
'EthD32',
107 'bytes28' =>
'EthD32',
108 'bytes29' =>
'EthD32',
109 'bytes30' =>
'EthD32',
110 'bytes31' =>
'EthD32',
111 'bytes32' =>
'EthD32',
133 $ns =
'Ethereum\DataType\\';
138 if (isset(self::ABI_MAP[$abiType])) {
139 return $ns . self::ABI_MAP[$abiType];
144 preg_match(
"/^(?'type'[u]?int)([\d]*)$/", $abiType, $int);
146 if ($int && isset(self::ABI_MAP[$int[
'type']])) {
147 return $ns . self::ABI_MAP[$int[
'type']];
150 throw new \Exception(
'Unknown ABI type: ' . $abiType);
197 public function getProperty(
string $property =
'value',
bool $returnHexVal =
false)
199 if (property_exists($this, $property)) {
201 if (is_object($this->$property)) {
202 return ($returnHexVal) ? $this->$property->hexval() : $this->$property->val();
205 if (is_array($this->$property)) {
207 foreach ($this->$property as $item) {
208 if (is_object($item)) {
209 $return[] = ($returnHexVal) ? $item->hexval() : $item->val();
216 throw new \InvalidArgumentException(
"Property '$property' does not exist.");
235 if (method_exists($this,
'validate')) {
236 if (isset($params[
'abi'])) {
237 $this->abi = $params[
'abi'];
239 $this->value = $this->validate($val, $params);
242 throw new \Exception(
'Validation of ' . __METHOD__ .
' not implemented yet.');
254 $ex = explode(
"\\", get_class($this));
274 public static function getTypeClass(
string $type,
bool $typed_constructor =
false)
278 if (strpos($type,
'[') !== FALSE) {
279 $type = str_replace([
'[',
']'],
'', $type);
285 if ($primitive_type) {
286 $type_class = $primitive_type;
290 if ($typed_constructor) {
291 $type_class = $isArray ?
'array' : $type;
299 throw new \Exception(
'Could not determine type class at getTypeClass()');
static getTypeClass(string $type, bool $typed_constructor=false)
static getDataLengthType()
static typeMap(string $type)
static getAllTypeClasses()
setValue($val, array $params=[])
getProperty(string $property='value', bool $returnHexVal=false)
static getPrimitiveTypes()
const static getClassByAbi(string $abiType)