9 use \Ethereum\EmittedEvent;
27 private $contractAddress;
58 $this->abi =
new Abi($abi);
60 $this->contractAddress = $contractAddress;
61 $this->events = $this->abi->getEventsByTopic();
79 public function __call(
string $method, array $args)
82 new EthD20($this->contractAddress),
87 $this->abi->encodeFunction($method, $args)
92 $rawReturn = $this->eth->eth_call($call,
new EthBlockParam());
94 return $this->abi->decodeMethod($method, $rawReturn);
106 if ($filterChange->address->hexVal() !== $this->contractAddress) {
110 if (is_array($filterChange->topics)) {
111 $topic = $filterChange->topics[0]->hexVal();
112 if (isset($this->events[$topic])) {
113 $transaction = $this->eth->eth_getTransactionByHash($filterChange->transactionHash);
115 $event =
new EmittedEvent($this->events[$topic], $filterChange, $transaction);
117 if (method_exists($this, $event->getHandler())) {
118 call_user_func([$this, $event->getHandler()], $event);
130 return $this->contractAddress;
157 foreach (scandir($path) as $fileName) {
158 if (strpos($fileName,
'.json') !==
false) {
159 $filePath = $path .
'/' . $fileName;
160 $file = pathinfo($filePath);
161 if($file[
'extension'] ===
'json') {
162 $contractMeta = self::createMetaFromTruffle($filePath);
164 if ($web3 && $networkId) {
165 $address = $contractMeta->networks->{$networkId}->address;
166 if (!class_exists($file[
'filename']) && $file[
'filename'] instanceof
SmartContract) {
168 trigger_error(
'Found a json for ' . $file[
'filename'] .
', but no corresponding contract class name. Initializing with default contract class.', E_USER_WARNING);
169 $return[$file[
'filename']] =
new SmartContract($contractMeta->abi,
$address, $web3);
172 $return[$file[
'filename']] =
new $file[
'filename']($contractMeta->abi,
$address, $web3);
176 $return[$file[
'filename']] = self::createMetaFromTruffle($filePath);
190 return json_decode(file_get_contents($filePath));
static createFromTruffleBuildDirectory($path, $web3=null, $networkId=null)
__call(string $method, array $args)
__construct(array $abi, string $contractAddress, Ethereum $eth)
processLog(FilterChange $filterChange)
static createMetaFromTruffle($filePath)