Skip to content

Commit

Permalink
[PLA-2005] Add source to beam (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Oct 14, 2024
1 parent 6e5d258 commit 8c187a5
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('beams', function (Blueprint $table) {
$table->string('source')->nullable()->after('flags_mask');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('beams', function (Blueprint $table) {
$table->dropColumn('source');
});
}
};
1 change: 1 addition & 0 deletions lang/en/mutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'common.args.quantityPerClaim' => 'The quantity per claim.',
'common.args.start' => 'The claim period start date.',
'common.args.type' => 'The beam type.',
'common.args.source' => 'The wallet from which the beam asset will be retrieved.',
'create_beam.args.collectionId' => 'The collection ID.',
'create_beam.args.tokenIds' => 'The token chain IDs to claim.',
'create_beam.description' => 'Mutation for creating a beam.',
Expand Down
1 change: 1 addition & 0 deletions src/BeamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function configurePackage(Package $package): void
->hasMigration('update_beams_table')
->hasMigration('add_collection_chain_id_to_beam_batches_table')
->hasMigration('add_idempotency_key_to_beam_claims_table')
->hasMigration('add_source_to_beams_table')
->hasRoute('enjin-platform-beam')
->hasTranslations();
}
Expand Down
9 changes: 6 additions & 3 deletions src/Commands/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Enjin\Platform\Services\Database\TransactionService;
use Enjin\Platform\Services\Serialization\Interfaces\SerializationServiceInterface;
use Enjin\Platform\Support\Account;
use Enjin\Platform\Support\SS58Address;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -159,9 +160,11 @@ protected function processBatch(BeamType $type): int
'tokenId' => ['integer' => $claim->token_chain_id],
'amount' => $claim->quantity,
'keepAlive' => false,
'source' => Account::daemonPublicKey() !== $claim->collection->owner->public_key
? $claim->collection->owner->public_key
: null,
'source' => match (true) {
!empty($claim->beam?->source) => SS58Address::getPublicKey($claim->beam->source),
Account::daemonPublicKey() !== $claim->collection->owner->public_key => $claim->collection->owner->public_key,
default => null,
},
])->toEncodable(),
];
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQL/Mutations/CreateBeamMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Enjin\Platform\Models\Collection;
use Enjin\Platform\Rules\DistinctAttributes;
use Enjin\Platform\Rules\IsCollectionOwnerOrApproved;
use Enjin\Platform\Rules\ValidSubstrateAddress;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -160,6 +161,10 @@ function (string $attribute, mixed $value, Closure $fail) {
new MaxTokenCount($args['collectionId']),
],
'flags.*.flag' => ['required', 'distinct'],
'source' => [
'nullable',
new ValidSubstrateAddress(),
],
];
}
}
4 changes: 4 additions & 0 deletions src/GraphQL/Traits/HasBeamCommonFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function getCommonFields(array $exclude = [], bool $updating = false): ar
'type' => GraphQL::type('DateTime' . $required),
'description' => __('enjin-platform-beam::mutation.common.args.end'),
],
'source' => [
'type' => GraphQL::type('String'),
'description' => __('enjin-platform-beam::mutation.common.args.source'),
],
];

return array_diff_key($fields, array_flip($exclude));
Expand Down
11 changes: 10 additions & 1 deletion src/GraphQL/Types/BeamType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Enjin\Platform\Beam\Services\BeamService;
use Enjin\Platform\GraphQL\Schemas\Traits\HasAuthorizableFields;
use Enjin\Platform\GraphQL\Types\Pagination\ConnectionInput;
use Enjin\Platform\Support\SS58Address;
use Enjin\Platform\Traits\HasSelectFields;
use Illuminate\Pagination\Cursor;
use Illuminate\Pagination\CursorPaginator;
Expand Down Expand Up @@ -48,7 +49,15 @@ public function fields(): array
'type' => GraphQL::type('String!'),
'description' => __('enjin-platform-beam::mutation.claim_beam.args.code'),
],
...$this->getCommonFields(),
...$this->getCommonFields(['source']),
'source' => [
'type' => GraphQL::type('Account'),
'description' => __('enjin-platform-beam::mutation.common.args.source'),
'resolve' => fn ($beam) => [
'publicKey' => $beam->source ? SS58Address::getPublicKey($beam->source) : '',
'address' => $beam->source ? SS58Address::encode($beam->source) : '',
],
],
'collection' => [
'type' => GraphQL::type('Collection'),
'description' => __('enjin-platform-beam::type.beam.field.collection'),
Expand Down
1 change: 1 addition & 0 deletions src/Models/Laravel/Beam.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Beam extends BaseModel
'end',
'collection_chain_id',
'flags_mask',
'source',
];

/**
Expand Down

0 comments on commit 8c187a5

Please sign in to comment.