Skip to content

Commit

Permalink
[PLA-1915] Fixes beams encoding (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio authored Jul 30, 2024
1 parent 085a650 commit 774071d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Commands/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Enjin\Platform\Beam\Models\BeamClaim;
use Enjin\Platform\Beam\Services\BatchService;
use Enjin\Platform\Enums\Substrate\TokenMintCapType;
use Enjin\Platform\GraphQL\Schemas\Primary\Substrate\Mutations\BatchMintMutation;
use Enjin\Platform\Models\Token;
use Enjin\Platform\Services\Blockchain\Implementations\Substrate;
use Enjin\Platform\Services\Database\TransactionService;
Expand Down Expand Up @@ -192,7 +193,7 @@ protected function processBatch(BeamType $type): int
'behaviour' => null,
'unitPrice' => config('enjin-platform-beam.unit_price'),
'attributes' => $claim->attributes ?: [],
])->toEncodable(),
]),
];

if (! $this->tokenCreatedCache[$key]) {
Expand All @@ -204,12 +205,24 @@ protected function processBatch(BeamType $type): int

$method = $type == BeamType::MINT_ON_DEMAND ? 'BatchMint' : 'BatchTransfer';
foreach ($params as $param) {
$transaction = $this->transaction->store([
'method' => $method,
'encoded_data' => $this->serialize->encode(isRunningLatest() ? $method . 'V1010' : $method, [
// TODO: With the v1010 upgrade we run into a bug with the php-scale-codec lib where it cannot
// Encode the transaction with `0x` the solution here is to use Batch and within each call append the 0's
if ($method === 'BatchMint') {
$encodedData = $this->serialize->encode('Batch', BatchMintMutation::getEncodableParams(
collectionId: $param['collectionId'],
recipients: $param['recipients'],
continueOnFailure: true
));
} else {
$encodedData = $this->serialize->encode(isRunningLatest() ? $method . 'V1010' : $method, [
'collectionId' => $param['collectionId'],
'recipients' => $param['recipients'],
]),
]);
}

$transaction = $this->transaction->store([
'method' => $method,
'encoded_data' => $encodedData,
'idempotency_key' => Str::uuid()->toString(),
]);
BeamBatch::where('id', $batchId)->update(['transaction_id' => $transaction->id]);
Expand Down

0 comments on commit 774071d

Please sign in to comment.