Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLA-1837] Add account owner validation #194

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Rules/IsCollectionOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Enjin\Platform\Models\Collection;
use Enjin\Platform\Rules\Traits\HasDataAwareRule;
use Enjin\Platform\Support\Account;
use Enjin\Platform\Support\SS58Address;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Arr;
Expand All @@ -31,7 +30,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}

if (!static::$bypass &&
(!$collection->owner || !SS58Address::isSameAddress(
(!$collection->owner || !Account::isAccountOwner(
$collection->owner->public_key,
Arr::get($this->data, 'signingAccount') ?: Account::daemonPublicKey()
))
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/IsCollectionOwnerOrApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Enjin\Platform\Models\Collection;
use Enjin\Platform\Services\Database\CollectionService;
use Enjin\Platform\Support\Account;
use Enjin\Platform\Support\SS58Address;
use Illuminate\Contracts\Validation\ValidationRule;

class IsCollectionOwnerOrApproved implements ValidationRule
Expand All @@ -32,7 +31,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
$daemonAccount = Account::daemonPublicKey();

if (!$collection ||
(!SS58Address::isSameAddress($collection->owner->public_key, $daemonAccount) &&
(!Account::isAccountOwner($collection->owner->public_key, $daemonAccount) &&
!$this->collectionService->approvalExistsInCollection(
$collection->collection_chain_id,
$daemonAccount,
Expand Down
20 changes: 20 additions & 0 deletions src/Support/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,28 @@
class Account
{
public static $publicKey;
public static $walletAccounts = [];
private static $account;

/**
* Check if account is owner.
*/
public static function isAccountOwner(string $publicKey, string $others = ''): bool
{
$accounts = [
static::$publicKey,
...static::$walletAccounts,
$others,
];
foreach (array_filter($accounts) as $account) {
if ($account && SS58Address::isSameAddress($publicKey, $account)) {
return true;
}
}

return false;
}

/**
* Get daemon account public key.
*/
Expand Down
Loading