Skip to content

Commit 6bd103f

Browse files
authored
Merge pull request #7 from androzd/master
Improve decoder
2 parents 0b75c35 + 9d60600 commit 6bd103f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/Coder.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public function __construct(string $connection, string $contractAddress)
4040
* @param array $logs
4141
* @return array
4242
*/
43-
public function decodeLogs(array $logs): array
43+
public function decodeLog(array $log): array
4444
{
4545
$eventInputs = [];
46-
$data = Arr::get($logs, '0.data');
47-
$topics = array_slice(Arr::get($logs, '0.topics', []), 1);
48-
$topicId = substr(Arr::first(Arr::get($logs, '0.topics', [])), 2);
46+
$data = Arr::get($log, 'data');
47+
$topics = array_slice(Arr::get($log, 'topics', []), 1);
48+
$topicId = substr(Arr::first(Arr::get($log, 'topics', [])), 2);
4949

5050
if (empty($topics) || is_null($data))
5151
{
@@ -62,11 +62,30 @@ public function decodeLogs(array $logs): array
6262
{
6363
$inputs = Arr::get($eventInputs[$topicId], 'inputs');
6464
$parsedEvent = $this->decodeEvent($inputs, $topics, $data);
65+
$parsedEvent['eventName'] = $eventInputs[$topicId]['name'];
6566
}
6667

6768
return $parsedEvent ?? [];
6869
}
6970

71+
/**
72+
* @param array $logs
73+
* @return array
74+
*/
75+
public function decodeLogs(array $logs): array
76+
{
77+
$parsedEvents = [];
78+
foreach ($logs as $log) {
79+
$decodedLog = $this->decodeLog($log);
80+
if (empty($decodedLog)) {
81+
continue;
82+
}
83+
$parsedEvents[] = $decodedLog;
84+
}
85+
86+
return $parsedEvents;
87+
}
88+
7089
/**
7190
* @param array $event
7291
* @return bool|string

0 commit comments

Comments
 (0)