Skip to content

Commit

Permalink
[PLA-1469] Fixes fuel tanks (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio authored Dec 1, 2023
1 parent a5c8a41 commit de721f7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Events/Substrate/MultiTokens/TokenReserved.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TokenReserved extends PlatformBroadcastEvent
/**
* Create a new event instance.
*/
public function __construct(Model $collection, Model $token, Model $wallet, Model $event, ?Model $transaction = null)
public function __construct(Model $collection, Model $token, Model $wallet, $event, ?Model $transaction = null)
{
parent::__construct();

Expand Down
2 changes: 1 addition & 1 deletion src/Events/Substrate/MultiTokens/TokenUnreserved.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TokenUnreserved extends PlatformBroadcastEvent
/**
* Create a new event instance.
*/
public function __construct(Model $collection, Model $token, Model $wallet, Model $event, ?Model $transaction = null)
public function __construct(Model $collection, Model $token, Model $wallet, $event, ?Model $transaction = null)
{
parent::__construct();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ protected function parseCollection(CreateCollection|Generic $extrinsic, Collecti
$params = $extrinsic->params;

if ($extrinsic instanceof Generic) {
// TODO: We need to pop the call from the extrinsic
$calls = collect(Arr::get($extrinsic->params, 'calls'))->filter(
fn ($call) => Arr::get($call, 'MultiTokens.create_collection') !== null
)->first();

$params = Arr::get($calls, 'MultiTokens.create_collection');
// TODO: Batch extrinsics - We need to pop the call from the extrinsic
// For batch we have params.calls
if (($calls = Arr::get($extrinsic->params, 'calls')) !== null) {
$calls = collect($calls)->filter(
fn ($call) => Arr::get($call, 'MultiTokens.create_collection') !== null
)->first();

$params = Arr::get($calls, 'MultiTokens.create_collection');
}
// For fuel tanks we have params.call
else {
$params = Arr::get($extrinsic->params, 'call.MultiTokens.create_collection');
}
}

$owner = WalletService::firstOrStore(['account' => Account::parseAccount($event->owner)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void
$collection = $this->getCollection($event->collectionId);
$token = $this->getToken($collection->id, $event->tokenId);
$token->update([
'supply', $finalSupply = $token->supply + $event->amount,
'supply', $token->supply + $event->amount,
]);

$tokenAccount = TokenAccount::firstWhere([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Enjin\Platform\Enums\Substrate\PalletIdentifier;
use Enjin\Platform\Events\Substrate\MultiTokens\TokenReserved;
use Enjin\Platform\Models\Laravel\Block;
use Enjin\Platform\Models\Laravel\TokenAccountNamedReserve;
use Enjin\Platform\Models\TokenAccount;
use Enjin\Platform\Models\TokenAccountNamedReserve;
use Enjin\Platform\Services\Processor\Substrate\Codec\Codec;
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\MultiTokens\Reserved as ReservedPolkadart;
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ public function parseToken(Mint|BatchMint|Generic $extrinsic, TokenCreatedPolkad
}

if ($extrinsic instanceof Generic) {
$calls = collect(Arr::get($extrinsic->params, 'calls'))
->filter(
fn ($call) => Arr::get($call, 'MultiTokens.mint.collection_id') === $event->collectionId
&& Arr::get($call, 'MultiTokens.mint.params.CreateToken.token_id') === $event->tokenId
)->first();

$params = Arr::get($calls, 'MultiTokens.mint.params.CreateToken');
// TODO: Batch extrinsics - We need to pop the call from the extrinsic
// For batch we have params.calls
if (($calls = Arr::get($extrinsic->params, 'calls')) !== null) {
$calls = collect($calls)
->filter(
fn ($call) => Arr::get($call, 'MultiTokens.mint.collection_id') === $event->collectionId
&& Arr::get($call, 'MultiTokens.mint.params.CreateToken.token_id') === $event->tokenId
)->first();

$params = Arr::get($calls, 'MultiTokens.mint.params.CreateToken');
}
// For fuel tanks we have params.call
else {
$params = Arr::get($extrinsic->params, 'call.MultiTokens.mint.params.CreateToken');
}
}

$collection = $this->getCollection($event->collectionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Enjin\Platform\Enums\Substrate\PalletIdentifier;
use Enjin\Platform\Events\Substrate\MultiTokens\TokenUnreserved;
use Enjin\Platform\Models\Laravel\Block;
use Enjin\Platform\Models\Laravel\TokenAccountNamedReserve;
use Enjin\Platform\Models\TokenAccount;
use Enjin\Platform\Models\TokenAccountNamedReserve;
use Enjin\Platform\Services\Processor\Substrate\Codec\Codec;
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\MultiTokens\Unreserved as UnreservedPolkadart;
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent;
Expand Down

0 comments on commit de721f7

Please sign in to comment.