diff --git a/src/Services/Processor/Substrate/Codec/Decoder.php b/src/Services/Processor/Substrate/Codec/Decoder.php index 26469b6..6ee747a 100644 --- a/src/Services/Processor/Substrate/Codec/Decoder.php +++ b/src/Services/Processor/Substrate/Codec/Decoder.php @@ -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, diff --git a/src/Services/Processor/Substrate/Parser.php b/src/Services/Processor/Substrate/Parser.php index 6b401be..4d08da0 100644 --- a/src/Services/Processor/Substrate/Parser.php +++ b/src/Services/Processor/Substrate/Parser.php @@ -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; @@ -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); } @@ -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, ]; } @@ -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, ]; }