From 4e8db86c533ba343b84d348e27585484866f9972 Mon Sep 17 00:00:00 2001 From: Abner Tudtud <114082473+enjinabner@users.noreply.github.com> Date: Fri, 27 Sep 2024 05:53:49 +0800 Subject: [PATCH] [PLA-2005] Fix batch transfer sender (#101) --- src/Commands/BatchProcess.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Commands/BatchProcess.php b/src/Commands/BatchProcess.php index 9ddabfd..10d3c3f 100644 --- a/src/Commands/BatchProcess.php +++ b/src/Commands/BatchProcess.php @@ -30,6 +30,11 @@ class BatchProcess extends Command */ public static $signingAccountResolver; + /** + * Adhoc functions before transfer. + */ + public static $beforeTransferCallbacks = []; + /** * The name and signature of the console command. * @@ -154,6 +159,7 @@ protected function processBatch(BeamType $type): int $params[$collectionId]['beamId'] = $claim->beam_id; if ($type == BeamType::TRANSFER_TOKEN) { + $this->runBeforeTransferCallbacks($claim); $daemon = Account::daemonPublicKey(); $params[$collectionId]['recipients'][] = [ 'accountId' => $claim->wallet_public_key, @@ -162,7 +168,7 @@ protected function processBatch(BeamType $type): int 'amount' => $claim->quantity, 'keepAlive' => false, 'source' => match(true) { - resolve(CollectionService::class)->approvalExistsInCollection($collectionId, $daemon) => $daemon, + resolve(CollectionService::class)->approvalExistsInCollection($collectionId, $daemon, false) => $daemon, $daemon !== $claim->collection->owner->public_key => $claim->collection->owner->public_key, default => null }, @@ -257,4 +263,11 @@ protected function resolveSigningAccount(string $beamId): ?Model return null; } + + protected function runBeforeTransferCallbacks(mixed $claim) + { + foreach (static::$beforeTransferCallbacks as $callback) { + call_user_func($callback, $claim); + } + } }