Skip to content

Commit

Permalink
[PLA-2005] Fix batch transfer sender (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Sep 26, 2024
1 parent 5521d60 commit 4e8db86
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Commands/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand All @@ -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
},
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 4e8db86

Please sign in to comment.