-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b70a7b
commit fd1c890
Showing
4 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Events/Substrate/Marketplace/ListingRemovedUnderMinimum.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Marketplace\Events\Substrate\Marketplace; | ||
|
||
use Enjin\Platform\Channels\PlatformAppChannel; | ||
use Enjin\Platform\Events\PlatformBroadcastEvent; | ||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Marketplace\ListingRemovedUnderMinimum as ListingRemovedUnderMinimumPolkadart; | ||
|
||
class ListingRemovedUnderMinimum extends PlatformBroadcastEvent | ||
{ | ||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct(ListingRemovedUnderMinimumPolkadart $event, ?Model $transaction = null, ?array $extra = null) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->broadcastData = $event->toBroadcast([ | ||
'idempotencyKey' => $transaction?->idempotency_key, | ||
]); | ||
|
||
$this->broadcastChannels = [ | ||
new Channel("listing;{$event->listingId}"), | ||
new Channel("collection;{$extra['collection_id']}"), | ||
new Channel("token;{$extra['collection_id']}-{$extra['token_id']}"), | ||
new Channel($extra['seller']), | ||
new PlatformAppChannel(), | ||
]; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ces/Processor/Substrate/Events/Implementations/Marketplace/ListingRemovedUnderMinimum.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Marketplace\Services\Processor\Substrate\Events\Implementations\Marketplace; | ||
|
||
use Carbon\Carbon; | ||
use Enjin\Platform\Marketplace\Enums\ListingState; | ||
use Enjin\Platform\Marketplace\Events\Substrate\Marketplace\ListingRemovedUnderMinimum as ListingRemovedUnderMinimumEvent; | ||
use Enjin\Platform\Marketplace\Models\Laravel\Wallet; | ||
use Enjin\Platform\Marketplace\Models\MarketplaceState; | ||
use Enjin\Platform\Marketplace\Services\Processor\Substrate\Events\Implementations\MarketplaceSubstrateEvent; | ||
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Marketplace\ListingRemovedUnderMinimum as ListingRemovedUnderMinimumPolkadart; | ||
use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class ListingRemovedUnderMinimum extends MarketplaceSubstrateEvent | ||
{ | ||
/** @var ListingRemovedUnderMinimumPolkadart */ | ||
protected Event $event; | ||
|
||
/** | ||
* Handles the listing cancelled event. | ||
*/ | ||
#[\Override] | ||
public function run(): void | ||
{ | ||
try { | ||
// Fails if the listing is not found | ||
$listing = $this->getListing($this->event->listingId); | ||
$seller = Wallet::find($listing->seller_wallet_id); | ||
|
||
MarketplaceState::create([ | ||
'marketplace_listing_id' => $listing->id, | ||
'state' => ListingState::CANCELLED->name, | ||
'height' => $this->block->number, | ||
'created_at' => $now = Carbon::now(), | ||
'updated_at' => $now, | ||
]); | ||
|
||
$this->extra = [ | ||
'collection_id' => $listing->make_collection_chain_id, | ||
'token_id' => $listing->make_token_chain_id, | ||
'seller' => $seller->public_key, | ||
]; | ||
} catch (\Throwable) { | ||
Log::error( | ||
sprintf( | ||
'Listing %s was removed but could not be found in the database.', | ||
$this->event->listingId, | ||
) | ||
); | ||
} | ||
} | ||
|
||
#[\Override] | ||
public function log(): void | ||
{ | ||
Log::debug( | ||
sprintf( | ||
'Listing %s was removed because of royalties change.', | ||
$this->event->listingId, | ||
) | ||
); | ||
} | ||
|
||
#[\Override] | ||
public function broadcast(): void | ||
{ | ||
ListingRemovedUnderMinimumEvent::safeBroadcast( | ||
$this->event, | ||
$this->getTransaction($this->block, $this->event->extrinsicIndex), | ||
$this->extra, | ||
); | ||
} | ||
} |