Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLA-1986] Fixes marketplace parsing #64

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading