Skip to content

Commit

Permalink
Parse tank name (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Sep 19, 2023
1 parent cc9b219 commit f3d2ca5
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/Services/Processor/Substrate/ExtrinsicProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Enjin\Platform\Services\Processor\Substrate;

use Enjin\BlockchainTools\HexConverter;
use Enjin\Platform\Clients\Implementations\SubstrateWebsocket;
use Enjin\Platform\Enums\Global\TransactionState;
use Enjin\Platform\Enums\Substrate\StorageKey;
Expand Down Expand Up @@ -101,14 +102,26 @@ protected function saveExtrinsicEvents($transaction, int $index): void
Event::where('transaction_id', $transaction->id)->delete();

$eventsWithTransaction = collect($this->block->events)->filter(fn ($event) => $event->extrinsicIndex == $index)
->map(fn ($event) => [
'transaction_id' => $transaction->id,
'phase' => '2',
'look_up' => 'unknown',
'module_id' => $event->module,
'event_id' => $event->name,
'params' => json_encode($event->getParams()),
])->toArray();
->map(function ($event) use ($transaction) {
$params = $event->getParams();
if ($event->name == 'FuelTankCreated') {
foreach ($params as &$param) {
$param->value = match ($param->type) {
'tankName' => HexConverter::hexToString($param->value),
default => $param->value
};
}
}

return [
'transaction_id' => $transaction->id,
'phase' => '2',
'look_up' => 'unknown',
'module_id' => $event->module,
'event_id' => $event->name,
'params' => json_encode($params),
];
})->toArray();

Event::insert($eventsWithTransaction);
}
Expand Down

0 comments on commit f3d2ca5

Please sign in to comment.