Skip to content

Commit

Permalink
[PLA-1986] Fixes marketplace parsing (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio authored Sep 10, 2024
1 parent c51826d commit 68eb301
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/Services/Processor/Substrate/Codec/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public function listingStorageKey(string $data): array
*/
public function listingStorageData(string $data): array
{
$decoded = $this->codec->process(isRunningLatest() ? 'ListingStorageDataV1010' : 'ListingStorageData', new ScaleBytes($data));
try {
$decoded = $this->codec->process('ListingStorageDataV1010', new ScaleBytes($data));
} catch (\Exception) {
$decoded = $this->codec->process('ListingStorageData', new ScaleBytes($data));
}

return [
'seller' => ($seller = $this->getValue($decoded, ['seller', 'creator'])) !== null ? HexConverter::prefix($seller) : null,
Expand Down
11 changes: 3 additions & 8 deletions src/Services/Processor/Substrate/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Enjin\Platform\Marketplace\Services\Processor\Substrate;

use Carbon\Carbon;
use Closure;
use Enjin\Platform\Marketplace\Enums\ListingState;
use Enjin\Platform\Marketplace\Models\MarketplaceBid;
use Enjin\Platform\Marketplace\Models\MarketplaceListing;
use Enjin\Platform\Marketplace\Models\MarketplaceState;
use Enjin\Platform\Marketplace\Services\MarketplaceService;
use Enjin\Platform\Marketplace\Services\Processor\Substrate\Codec\Codec;
Expand Down Expand Up @@ -89,12 +89,11 @@ public function listingsStorages(array $data): void
'start_block' => Arr::get($listingData, 'data.Auction.startBlock'),
'end_block' => Arr::get($listingData, 'data.Auction.endBlock'),
'amount_filled' => ($amountFilled = Arr::get($listingData, 'state.FixedPrice.amountFilled')) !== null ? gmp_strval($amountFilled) : null,
'created_at' => $now = Carbon::now(),
'updated_At' => $now,
];
}

$this->marketplaceService->insert($insertData);
MarketplaceListing::upsert($insertData, uniqueBy: 'listing_chain_id');

$this->marketplaceBids($insertBids);
$this->marketplaceStates($insertStates);
}
Expand All @@ -120,8 +119,6 @@ protected function marketplaceStates(array $data): void
// If the listing is currently in the storage means it is active
'state' => ListingState::ACTIVE->name,
'height' => Arr::get($state, 'height'),
'created_at' => $now = Carbon::now(),
'updated_at' => $now,
];
}

Expand Down Expand Up @@ -155,8 +152,6 @@ protected function marketplaceBids(array $data): void
'price' => ($price = Arr::get($bid, 'listingData.state.Auction.highBid.price')) !== null ? gmp_strval($price) : null,
// There is no way to know this info from state we will default to auction started block
'height' => Arr::get($bid, 'listingData.creationBlock'),
'created_at' => $now = Carbon::now(),
'updated_at' => $now,
];
}

Expand Down

0 comments on commit 68eb301

Please sign in to comment.