Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
Event.php
Go to the documentation of this file.
1 <?php
9 namespace Ethereum;
13 
14 class Event extends EthereumStatic
15 {
16 
17  protected $name;
18  protected $anonymous;
19  protected $inputs;
20  protected $abi;
21 
22  public function __construct($abiItem)
23  {
24  $this->abi = $abiItem;
25  $this->inputs = $abiItem->inputs;
26  $this->name = $abiItem->name;
27  $this->anonymous = $abiItem->anonymous;
28  }
29 
35  public function decode(FilterChange $filterChange) {
36  $values = []; // Intermediate return value store
37  $abiDecode = []; // Params we require to decode un-indexed data part.
38  $return = []; // Final ordered return values.
39 
40  // Removing topic[0]. Topic[1-n] are indexed values.
41  $indexedValues = array_slice($filterChange->topics, 1);
42 
43  foreach ($this->inputs as $i => $param) {
44  if ($param->indexed) {
45  $values[$param->name] = $indexedValues[$i]->convertByAbi($param->type);
46  }
47  else {
48  $abiDecode[] = $param;
49  }
50  }
51 
52  // Decode the Data part
53  if (count($abiDecode)) {
54  $decoded = Abi::decode($abiDecode, self::removeHexPrefix($filterChange->data->hexVal()));
55  foreach ($abiDecode as $i => $param) {
56  $values[$param->name] = $decoded[$i];
57  }
58  }
59 
60  // Restore array order (array_values($return) should return the right param order).
61  foreach ($this->inputs as $i => $param) {
62  $return[$param->name] = $values[$param->name];
63  }
64  return $return;
65  }
66 
67 
71  public function getSignature() {
72  $sign = $this->name . '(';
73  foreach ($this->inputs as $i => $item) {
74  $sign .= $item->type;
75  if ($i < count($this->inputs) - 1) {
76  $sign .= ',';
77  }
78  }
79  $sign .= ')';
80  return $sign;
81  }
82 
86  public function getTopic() {
87  return $this->sha3($this->getSignature());
88  }
89 
93  public function getHandler () {
94  return 'on' . ucfirst($this->name);
95  }
96 
100  public function getAbi() {
101  return $this->abi;
102  }
103 
104  public function getName() {
105  return $this->name;
106  }
107 }
decode(FilterChange $filterChange)
Definition: Event.php:35
getSignature()
Definition: Event.php:71
__construct($abiItem)
Definition: Event.php:22
Definition: Abi.php:3