From fef8fe110d843a3ae7d0905bfd02c807e32aa526 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:29:11 +0000 Subject: [PATCH 01/21] fix: handle missing state record --- app/Actions/CacheTotalSupply.php | 4 ++-- app/Services/BigNumber.php | 5 +++++ app/Services/Blockchain/Network.php | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Actions/CacheTotalSupply.php b/app/Actions/CacheTotalSupply.php index 7d8f9987e..82c51781d 100644 --- a/app/Actions/CacheTotalSupply.php +++ b/app/Actions/CacheTotalSupply.php @@ -4,7 +4,7 @@ namespace App\Actions; -use App\Models\State; +use App\Facades\Network; use App\Services\Cache\NetworkCache; final class CacheTotalSupply @@ -12,7 +12,7 @@ final class CacheTotalSupply public static function execute(): float { return (new NetworkCache())->setTotalSupply(function (): float { - return State::latest()->supply->toFloat(); + return Network::supply()->toFloat(); }); } } diff --git a/app/Services/BigNumber.php b/app/Services/BigNumber.php index 0ea928d29..51daece51 100644 --- a/app/Services/BigNumber.php +++ b/app/Services/BigNumber.php @@ -37,6 +37,11 @@ public static function new($value): self return new static($value); } + public static function zero(): self + { + return new static(0); + } + /** * @param BigDecimal|int|string $value */ diff --git a/app/Services/Blockchain/Network.php b/app/Services/Blockchain/Network.php index bad087509..71b0eccc3 100644 --- a/app/Services/Blockchain/Network.php +++ b/app/Services/Blockchain/Network.php @@ -110,7 +110,12 @@ public function blockReward(): int public function supply(): BigNumber { - return State::latest()->supply; + $latestState = State::first(); + if ($latestState === null) { + return BigNumber::zero(); + } + + return $latestState->supply; } public function config(): AbstractNetwork From 57716a253f4dd0ded93bb1b536097a5d4a82497e Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:31:54 +0000 Subject: [PATCH 02/21] use zero static helper method --- app/Console/Commands/CacheValidatorVoterCounts.php | 2 +- app/Providers/AppServiceProvider.php | 2 +- tests/Unit/Services/Cache/StatisticsCacheTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/CacheValidatorVoterCounts.php b/app/Console/Commands/CacheValidatorVoterCounts.php index f6567ee4d..b145abfb4 100644 --- a/app/Console/Commands/CacheValidatorVoterCounts.php +++ b/app/Console/Commands/CacheValidatorVoterCounts.php @@ -65,7 +65,7 @@ public function handle(): void return; } - $totalVoted = BigNumber::new(0); + $totalVoted = BigNumber::zero(); foreach ($wallets as $wallet) { $totalVoted->plus($wallet['balance']->valueOf()); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index d5dd537de..e148d132f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -68,7 +68,7 @@ private function registerCollectionMacros(): void return $collection->reduce(function ($result, $item) use ($key) { /** @var array $item */ return $result->plus($item[$key]->valueOf()); - }, BigNumber::new(0)); + }, BigNumber::zero()); }); Collection::macro('ksort', function (): Collection { diff --git a/tests/Unit/Services/Cache/StatisticsCacheTest.php b/tests/Unit/Services/Cache/StatisticsCacheTest.php index c95ee8b6b..a1a6e3a80 100644 --- a/tests/Unit/Services/Cache/StatisticsCacheTest.php +++ b/tests/Unit/Services/Cache/StatisticsCacheTest.php @@ -10,8 +10,8 @@ use Carbon\Carbon; it('should get fees', function () { - $volume = BigNumber::new(0); - $totalFees = BigNumber::new(0); + $volume = BigNumber::zero(); + $totalFees = BigNumber::zero(); $transactionCount = 7; From aff68e104f83bbf5c4c0a792dc1725678bc0e067 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:30:40 +0000 Subject: [PATCH 03/21] rename class names --- .../Transactions/TransactionMethod.php | 167 ++++++++++++++++++ app/Services/Transactions/TransactionType.php | 159 ----------------- .../{HasType.php => HasMethod.php} | 90 +++++----- app/ViewModels/TransactionViewModel.php | 10 +- 4 files changed, 219 insertions(+), 207 deletions(-) create mode 100644 app/Services/Transactions/TransactionMethod.php delete mode 100644 app/Services/Transactions/TransactionType.php rename app/ViewModels/Concerns/Transaction/{HasType.php => HasMethod.php} (51%) diff --git a/app/Services/Transactions/TransactionMethod.php b/app/Services/Transactions/TransactionMethod.php new file mode 100644 index 000000000..4eb7baed7 --- /dev/null +++ b/app/Services/Transactions/TransactionMethod.php @@ -0,0 +1,167 @@ + 'transfer', + 'isValidatorRegistration' => 'validator-registration', + // 'isUsernameRegistration' => 'username-registration', + // 'isUsernameResignation' => 'username-resignation', + // 'isVoteCombination' => 'vote-combination', + 'isUnvote' => 'unvote', + 'isVote' => 'vote', + // 'isMultiSignature' => 'multi-signature', + 'isValidatorResignation' => 'validator-resignation', + // 'isMultiPayment' => 'multi-payment', + ]; + + public function __construct(private Transaction $transaction) + { + $this->methodHash = $this->methodHash(); + } + + public function name(): string + { + foreach ($this->types as $method => $name) { + if ((bool) call_user_func_safe([$this, $method])) { + return $name; + } + } + + return 'unknown'; + } + + public function isTransfer(): bool + { + if ($this->methodHash === null) { + return true; + } + + return $this->methodHash === PayloadSignature::TRANSFER->value; + } + + public function isValidatorRegistration(): bool + { + return $this->methodHash === PayloadSignature::VALIDATOR_REGISTRATION->value; + } + + public function isVote(): bool + { + return $this->methodHash === PayloadSignature::VOTE->value; + } + + public function isUnvote(): bool + { + return $this->methodHash === PayloadSignature::UNVOTE->value; + } + + // public function isVoteCombination(): bool + // { + // [$containsVote, $containsUnvote] = $this->determineVoteTypes(); + + // return $containsVote && $containsUnvote; + // } + + // public function isMultiSignature(): bool + // { + // return $this->transaction->type === TransactionTypeEnum::MULTI_SIGNATURE; + // } + + public function isValidatorResignation(): bool + { + return $this->methodHash === PayloadSignature::VALIDATOR_RESIGNATION->value; + } + + // public function isMultiPayment(): bool + // { + // return $this->transaction->type === TransactionTypeEnum::MULTI_PAYMENT; + // } + + // public function isUsernameRegistration(): bool + // { + // return $this->transaction->type === TransactionTypeEnum::USERNAME_REGISTRATION; + // } + + // public function isUsernameResignation(): bool + // { + // return $this->transaction->type === TransactionTypeEnum::USERNAME_RESIGNATION; + // } + + public function isUnknown(): bool + { + if ($this->isTransfer()) { + return false; + } + + if ($this->isValidatorRegistration()) { + return false; + } + + // if ($this->isVoteCombination()) { + // return false; + // } + + if ($this->isUnvote()) { + return false; + } + + if ($this->isVote()) { + return false; + } + + // if ($this->isMultiSignature()) { + // return false; + // } + + if ($this->isValidatorResignation()) { + return false; + } + + // if ($this->isMultiPayment()) { + // return false; + // } + + // if ($this->isUsernameRegistration()) { + // return false; + // } + + // if ($this->isUsernameResignation()) { + // return false; + // } + + return true; + } + + // private function determineVoteTypes(): array + // { + // $containsVote = false; + // $containsUnvote = false; + + // if ($this->transaction->type !== TransactionTypeEnum::VOTE) { + // return [$containsVote, $containsUnvote]; + // } + + // if (! is_array($this->transaction->asset)) { + // return [$containsVote, $containsUnvote]; + // } + + // $containsVote = count(Arr::get($this->transaction->asset, 'votes', [])) !== 0; + // $containsUnvote = count(Arr::get($this->transaction->asset, 'unvotes', [])) !== 0; + + // return [$containsVote, $containsUnvote]; + // } +} diff --git a/app/Services/Transactions/TransactionType.php b/app/Services/Transactions/TransactionType.php deleted file mode 100644 index 4960ed0c2..000000000 --- a/app/Services/Transactions/TransactionType.php +++ /dev/null @@ -1,159 +0,0 @@ - 'transfer', - 'isValidatorRegistration' => 'validator-registration', - 'isUsernameRegistration' => 'username-registration', - 'isUsernameResignation' => 'username-resignation', - 'isVoteCombination' => 'vote-combination', - 'isUnvote' => 'unvote', - 'isVote' => 'vote', - 'isMultiSignature' => 'multi-signature', - 'isValidatorResignation' => 'validator-resignation', - 'isMultiPayment' => 'multi-payment', - ]; - - public function __construct(private Transaction $transaction) - { - } - - public function name(): string - { - foreach ($this->types as $method => $name) { - if ((bool) call_user_func_safe([$this, $method])) { - return $name; - } - } - - return 'unknown'; - } - - public function isTransfer(): bool - { - return $this->transaction->type === TransactionTypeEnum::TRANSFER; - } - - public function isValidatorRegistration(): bool - { - return $this->transaction->type === TransactionTypeEnum::VALIDATOR_REGISTRATION; - } - - public function isVote(): bool - { - return $this->determineVoteTypes()[0] === true; - } - - public function isUnvote(): bool - { - return $this->determineVoteTypes()[1] === true; - } - - public function isVoteCombination(): bool - { - [$containsVote, $containsUnvote] = $this->determineVoteTypes(); - - return $containsVote && $containsUnvote; - } - - public function isMultiSignature(): bool - { - return $this->transaction->type === TransactionTypeEnum::MULTI_SIGNATURE; - } - - public function isValidatorResignation(): bool - { - return $this->transaction->type === TransactionTypeEnum::VALIDATOR_RESIGNATION; - } - - public function isMultiPayment(): bool - { - return $this->transaction->type === TransactionTypeEnum::MULTI_PAYMENT; - } - - public function isUsernameRegistration(): bool - { - return $this->transaction->type === TransactionTypeEnum::USERNAME_REGISTRATION; - } - - public function isUsernameResignation(): bool - { - return $this->transaction->type === TransactionTypeEnum::USERNAME_RESIGNATION; - } - - public function isUnknown(): bool - { - if ($this->isTransfer()) { - return false; - } - - if ($this->isValidatorRegistration()) { - return false; - } - - if ($this->isVoteCombination()) { - return false; - } - - if ($this->isUnvote()) { - return false; - } - - if ($this->isVote()) { - return false; - } - - if ($this->isMultiSignature()) { - return false; - } - - if ($this->isValidatorResignation()) { - return false; - } - - if ($this->isMultiPayment()) { - return false; - } - - if ($this->isUsernameRegistration()) { - return false; - } - - if ($this->isUsernameResignation()) { - return false; - } - - return true; - } - - private function determineVoteTypes(): array - { - $containsVote = false; - $containsUnvote = false; - - if ($this->transaction->type !== TransactionTypeEnum::VOTE) { - return [$containsVote, $containsUnvote]; - } - - if (! is_array($this->transaction->asset)) { - return [$containsVote, $containsUnvote]; - } - - $containsVote = count(Arr::get($this->transaction->asset, 'votes', [])) !== 0; - $containsUnvote = count(Arr::get($this->transaction->asset, 'unvotes', [])) !== 0; - - return [$containsVote, $containsUnvote]; - } -} diff --git a/app/ViewModels/Concerns/Transaction/HasType.php b/app/ViewModels/Concerns/Transaction/HasMethod.php similarity index 51% rename from app/ViewModels/Concerns/Transaction/HasType.php rename to app/ViewModels/Concerns/Transaction/HasMethod.php index 2257ca582..9c259ccff 100644 --- a/app/ViewModels/Concerns/Transaction/HasType.php +++ b/app/ViewModels/Concerns/Transaction/HasMethod.php @@ -4,69 +4,73 @@ namespace App\ViewModels\Concerns\Transaction; -use App\Services\Transactions\TransactionType; +use App\Services\Transactions\TransactionMethod; -trait HasType +trait HasMethod { public function typeName(): string { - return (new TransactionType($this->transaction))->name(); + return (new TransactionMethod($this->transaction))->name(); } public function isTransfer(): bool { - return $this->type->isTransfer(); + return $this->method->isTransfer(); } public function isValidatorRegistration(): bool { - return $this->type->isValidatorRegistration(); + return $this->method->isValidatorRegistration(); } public function isVote(): bool { - return $this->type->isVote(); + return $this->method->isVote(); } public function isUnvote(): bool { - return $this->type->isUnvote(); + return $this->method->isUnvote(); } public function isVoteCombination(): bool { - return $this->type->isVoteCombination(); + return false; + + return $this->method->isVoteCombination(); } public function isMultiSignature(): bool { - return $this->type->isMultiSignature(); + return false; + + return $this->method->isMultiSignature(); } public function isValidatorResignation(): bool { - return $this->type->isValidatorResignation(); + return $this->method->isValidatorResignation(); } public function isMultiPayment(): bool { - return $this->type->isMultiPayment(); + return false; + + return $this->method->isMultiPayment(); } public function isUsernameRegistration(): bool { - return $this->type->isUsernameRegistration(); + return false; + + return $this->method->isUsernameRegistration(); } public function isUsernameResignation(): bool { - return $this->type->isUsernameResignation(); - } + return false; - // TODO: implement method correctly - https://app.clickup.com/t/86dur8fj6 - public function isEvm(): bool - { - return true; + return $this->method->isUsernameResignation(); } public function isLegacy(): bool @@ -79,21 +83,21 @@ public function isLegacy(): bool return false; } - if ($this->isUsernameRegistration()) { - return false; - } + // if ($this->isUsernameRegistration()) { + // return false; + // } - if ($this->isUsernameResignation()) { - return false; - } + // if ($this->isUsernameResignation()) { + // return false; + // } - if ($this->isMultiPayment()) { - return false; - } + // if ($this->isMultiPayment()) { + // return false; + // } - if ($this->isVoteCombination()) { - return false; - } + // if ($this->isVoteCombination()) { + // return false; + // } if ($this->isVote()) { return false; @@ -107,16 +111,16 @@ public function isLegacy(): bool return false; } - if ($this->isMultiSignature()) { - return false; - } + // if ($this->isMultiSignature()) { + // return false; + // } return true; } public function isUnknown(): bool { - return $this->type->isUnknown(); + return $this->method->isUnknown(); } public function isSelfReceiving(): bool @@ -129,9 +133,9 @@ public function isSelfReceiving(): bool return true; } - if ($this->isVoteCombination()) { - return true; - } + // if ($this->isVoteCombination()) { + // return true; + // } if ($this->isVote()) { return true; @@ -141,13 +145,13 @@ public function isSelfReceiving(): bool return true; } - if ($this->isUsernameRegistration()) { - return true; - } + // if ($this->isUsernameRegistration()) { + // return true; + // } - if ($this->isUsernameResignation()) { - return true; - } + // if ($this->isUsernameResignation()) { + // return true; + // } return false; } diff --git a/app/ViewModels/TransactionViewModel.php b/app/ViewModels/TransactionViewModel.php index 5e52d2aff..ff0f781c4 100644 --- a/app/ViewModels/TransactionViewModel.php +++ b/app/ViewModels/TransactionViewModel.php @@ -11,11 +11,11 @@ use App\Services\Timestamp; use App\Services\Transactions\TransactionDirection; use App\Services\Transactions\TransactionState; -use App\Services\Transactions\TransactionType; +use App\Services\Transactions\TransactionMethod; use App\ViewModels\Concerns\Transaction\HasDirection; use App\ViewModels\Concerns\Transaction\HasPayload; use App\ViewModels\Concerns\Transaction\HasState; -use App\ViewModels\Concerns\Transaction\HasType; +use App\ViewModels\Concerns\Transaction\HasMethod; use App\ViewModels\Concerns\Transaction\InteractsWithMultiPayment; use App\ViewModels\Concerns\Transaction\InteractsWithMultiSignature; use App\ViewModels\Concerns\Transaction\InteractsWithUsernames; @@ -31,7 +31,7 @@ final class TransactionViewModel implements ViewModel use HasDirection; use HasPayload; use HasState; - use HasType; + use HasMethod; use InteractsWithMultiPayment; use InteractsWithMultiSignature; use InteractsWithUsernames; @@ -39,7 +39,7 @@ final class TransactionViewModel implements ViewModel use InteractsWithVotes; use InteractsWithWallets; - private TransactionType $type; + private TransactionMethod $method; private TransactionState $state; @@ -47,7 +47,7 @@ final class TransactionViewModel implements ViewModel public function __construct(private Transaction $transaction) { - $this->type = new TransactionType($transaction); + $this->method = new TransactionMethod($transaction); $this->state = new TransactionState($transaction); $this->direction = new TransactionDirection($transaction); } From 798366c4c302688273854b18e827bbff6691eb7d Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:30:51 +0000 Subject: [PATCH 04/21] update handling of payload --- .../Concerns/Transaction/HasPayload.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/ViewModels/Concerns/Transaction/HasPayload.php b/app/ViewModels/Concerns/Transaction/HasPayload.php index 48e449f65..82dbf3a68 100644 --- a/app/ViewModels/Concerns/Transaction/HasPayload.php +++ b/app/ViewModels/Concerns/Transaction/HasPayload.php @@ -4,8 +4,6 @@ namespace App\ViewModels\Concerns\Transaction; -use Illuminate\Support\Arr; - trait HasPayload { public function hasPayload(): bool @@ -15,7 +13,12 @@ public function hasPayload(): bool public function rawPayload(): ?string { - $payload = Arr::get($this->transaction, 'asset.evmCall.payload'); + $payload = $this->transaction->data; + if ($payload === null) { + return null; + } + + $payload = bin2hex(stream_get_contents($payload, offset: 0)); if (is_string($payload) && strlen($payload) === 0) { return null; } @@ -38,14 +41,19 @@ public function utf8Payload(): ?string return $utf8; } - public function formattedPayload(): ?string + public function methodHash(): ?string { $payload = $this->rawPayload(); if ($payload === null) { return null; } - $methodId = substr($payload, 0, 8); + return substr($payload, 0, 8); + } + + public function formattedPayload(): ?string + { + $methodId = $this->methodHash(); $functionName = null; if (app('translator')->has('contracts.'.$methodId)) { From 07776c404fdcd30e0f3999e3b5670eaf298d8988 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:31:03 +0000 Subject: [PATCH 05/21] update langs --- resources/lang/en/forms.php | 2 +- resources/lang/en/pages.php | 2 +- resources/lang/en/tables.php | 2 +- .../components/tables/desktop/block-transactions.blade.php | 2 +- .../views/components/tables/desktop/home/transactions.blade.php | 2 +- .../tables/desktop/skeleton/home/transactions.blade.php | 2 +- .../components/tables/desktop/skeleton/transactions.blade.php | 2 +- .../tables/desktop/skeleton/wallet-transactions.blade.php | 2 +- .../views/components/tables/desktop/transactions.blade.php | 2 +- .../components/tables/desktop/wallet-transactions.blade.php | 2 +- .../components/transaction/page/transaction-type.blade.php | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 82db85e9d..4b368d40f 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -27,7 +27,7 @@ 'term_placeholder' => 'Find a block, transaction, address or validator ...', 'term_placeholder_mobile' => 'Search ...', 'type' => 'Search Type', - 'transaction_type' => 'Transaction Type', + 'transaction_method' => 'Transaction Method', 'transaction_types' => [ 'all' => 'All', 'validatorRegistration' => 'Validator Registration', diff --git a/resources/lang/en/pages.php b/resources/lang/en/pages.php index 3c7060fb9..e9452811a 100644 --- a/resources/lang/en/pages.php +++ b/resources/lang/en/pages.php @@ -86,7 +86,7 @@ ], 'transaction' => [ - 'transaction_type' => 'Transaction Type', + 'transaction_method' => 'Transaction Method', 'transaction_id' => 'Transaction ID', 'transaction_id_copied' => 'Transaction ID Copied', 'transaction_details' => 'Transaction Details', diff --git a/resources/lang/en/tables.php b/resources/lang/en/tables.php index 1dd3a1589..d744114e9 100644 --- a/resources/lang/en/tables.php +++ b/resources/lang/en/tables.php @@ -11,7 +11,7 @@ 'transactions' => [ 'id' => 'Tx ID', 'age' => 'Age', - 'type' => 'Type', + 'method' => 'Method', 'addressing' => 'Addressing', 'amount' => 'Amount (:currency)', 'fee' => 'Fee (:currency)', diff --git a/resources/views/components/tables/desktop/block-transactions.blade.php b/resources/views/components/tables/desktop/block-transactions.blade.php index c258b6172..38c75282e 100644 --- a/resources/views/components/tables/desktop/block-transactions.blade.php +++ b/resources/views/components/tables/desktop/block-transactions.blade.php @@ -14,7 +14,7 @@ class="hidden w-full rounded-b-xl md:block" class="whitespace-nowrap md-lg:w-[130px] lg:w-[150px]" /> diff --git a/resources/views/components/tables/desktop/home/transactions.blade.php b/resources/views/components/tables/desktop/home/transactions.blade.php index c624caf3c..055302bbd 100644 --- a/resources/views/components/tables/desktop/home/transactions.blade.php +++ b/resources/views/components/tables/desktop/home/transactions.blade.php @@ -21,7 +21,7 @@ class="whitespace-nowrap" breakpoint="xl" responsive /> - + true, 'breakpoint' => 'xl', ], - 'tables.transactions.type' => 'text', + 'tables.transactions.method' => 'text', 'tables.transactions.addressing' => [ 'type' => 'encapsulated.addressing', 'header' => 'address', diff --git a/resources/views/components/tables/desktop/skeleton/transactions.blade.php b/resources/views/components/tables/desktop/skeleton/transactions.blade.php index e3908501c..b8273fdb1 100644 --- a/resources/views/components/tables/desktop/skeleton/transactions.blade.php +++ b/resources/views/components/tables/desktop/skeleton/transactions.blade.php @@ -18,7 +18,7 @@ 'responsive' => true, 'breakpoint' => 'xl', ], - 'tables.transactions.type' => 'text', + 'tables.transactions.method' => 'text', 'tables.transactions.addressing' => [ 'type' => 'encapsulated.addressing', 'header' => 'address', diff --git a/resources/views/components/tables/desktop/skeleton/wallet-transactions.blade.php b/resources/views/components/tables/desktop/skeleton/wallet-transactions.blade.php index 34760bb2e..5589e204b 100644 --- a/resources/views/components/tables/desktop/skeleton/wallet-transactions.blade.php +++ b/resources/views/components/tables/desktop/skeleton/wallet-transactions.blade.php @@ -12,7 +12,7 @@ 'responsive' => true, 'breakpoint' => 'xl', ], - 'tables.transactions.type' => 'text', + 'tables.transactions.method' => 'text', 'tables.transactions.addressing' => [ 'type' => 'encapsulated.addressing', 'header' => 'address', diff --git a/resources/views/components/tables/desktop/transactions.blade.php b/resources/views/components/tables/desktop/transactions.blade.php index a2f887d94..5b6cf6b66 100644 --- a/resources/views/components/tables/desktop/transactions.blade.php +++ b/resources/views/components/tables/desktop/transactions.blade.php @@ -22,7 +22,7 @@ class="whitespace-nowrap" breakpoint="xl" responsive /> - + - + + Date: Wed, 13 Nov 2024 02:32:47 +0000 Subject: [PATCH 06/21] update method used for checking if transaction is evm - check if it has a payload instead --- resources/views/app/transaction.blade.php | 4 ++-- .../components/transaction/page/section-detail/row.blade.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/app/transaction.blade.php b/resources/views/app/transaction.blade.php index 73a01eaf0..2694d4988 100644 --- a/resources/views/app/transaction.blade.php +++ b/resources/views/app/transaction.blade.php @@ -5,7 +5,7 @@
! $transaction->isEvm(), + 'mb-8' => ! $transaction->hasPayload(), ])> @@ -28,7 +28,7 @@ @endif
- @if ($transaction->isEvm()) + @if ($transaction->hasPayload())
diff --git a/resources/views/components/transaction/page/section-detail/row.blade.php b/resources/views/components/transaction/page/section-detail/row.blade.php index 2a3bf206c..1a38e4285 100644 --- a/resources/views/components/transaction/page/section-detail/row.blade.php +++ b/resources/views/components/transaction/page/section-detail/row.blade.php @@ -9,7 +9,7 @@ @php $headerWidth = 'w-[87px]'; - if ($transaction->isEvm()) { + if ($transaction->hasPayload()) { $headerWidth = 'w-[132px]'; } elseif ($transaction->isVoteCombination()) { $headerWidth = 'w-[109px]'; From 1bff804e28434db85ecb312dfd79ee673c444e45 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:33:19 +0000 Subject: [PATCH 07/21] force no vote/unvote return value --- .../Transaction/InteractsWithVotes.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php b/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php index deb364701..5c2870eb5 100644 --- a/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php +++ b/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php @@ -16,13 +16,15 @@ public function voted(): ?WalletViewModel return null; } - /** @var array */ - $votes = Arr::get($this->transaction->asset ?? [], 'votes'); + return null; - /** @var string */ - $address = collect($votes)->firstOrFail(); + // /** @var array */ + // $votes = Arr::get($this->transaction->asset ?? [], 'votes'); - return new WalletViewModel(Wallets::findByPublicKey($address)); + // /** @var string */ + // $address = collect($votes)->firstOrFail(); + + // return new WalletViewModel(Wallets::findByPublicKey($address)); } public function unvoted(): ?WalletViewModel @@ -31,12 +33,14 @@ public function unvoted(): ?WalletViewModel return null; } - /** @var array */ - $votes = Arr::get($this->transaction->asset ?? [], 'unvotes'); + return null; + + // /** @var array */ + // $votes = Arr::get($this->transaction->asset ?? [], 'unvotes'); - /** @var string */ - $address = collect($votes)->firstOrFail(); + // /** @var string */ + // $address = collect($votes)->firstOrFail(); - return new WalletViewModel(Wallets::findByPublicKey($address)); + // return new WalletViewModel(Wallets::findByPublicKey($address)); } } From b687b36b6dfa6bbc6ce27cf95c61cf9d4bbbe95c Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:33:32 +0000 Subject: [PATCH 08/21] comment out voted validator --- .../components/general/encapsulated/vote-type.blade.php | 4 ++-- .../components/transaction/page/transaction-type.blade.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/components/general/encapsulated/vote-type.blade.php b/resources/views/components/general/encapsulated/vote-type.blade.php index 723109210..f564adf05 100644 --- a/resources/views/components/general/encapsulated/vote-type.blade.php +++ b/resources/views/components/general/encapsulated/vote-type.blade.php @@ -8,13 +8,13 @@ @elseif($transaction->isVote()) @lang('general.transaction.types.'.$transaction->typeName()) @else @lang('general.transaction.types.'.$transaction->typeName()) diff --git a/resources/views/components/transaction/page/transaction-type.blade.php b/resources/views/components/transaction/page/transaction-type.blade.php index 57f12e29d..317e6c7db 100644 --- a/resources/views/components/transaction/page/transaction-type.blade.php +++ b/resources/views/components/transaction/page/transaction-type.blade.php @@ -17,21 +17,21 @@ class="inline text-theme-secondary-700 dark:text-theme-dark-200" :title="trans('pages.transaction.header.old_validator')" :transaction="$transaction" > - + {{-- --}}
- + {{-- --}} @elseif ($transaction->isVote() || $transaction->isUnvote()) - + {{-- --}} @elseif ($transaction->isMultisignature()) Date: Wed, 13 Nov 2024 02:33:46 +0000 Subject: [PATCH 09/21] payload signature enum --- app/Enums/PayloadSignature.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/Enums/PayloadSignature.php diff --git a/app/Enums/PayloadSignature.php b/app/Enums/PayloadSignature.php new file mode 100644 index 000000000..f7b33f87a --- /dev/null +++ b/app/Enums/PayloadSignature.php @@ -0,0 +1,16 @@ + Date: Wed, 13 Nov 2024 02:37:30 +0000 Subject: [PATCH 10/21] style: resolve style guide violations --- app/Enums/PayloadSignature.php | 2 ++ app/ViewModels/TransactionViewModel.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Enums/PayloadSignature.php b/app/Enums/PayloadSignature.php index f7b33f87a..3a7c2f132 100644 --- a/app/Enums/PayloadSignature.php +++ b/app/Enums/PayloadSignature.php @@ -1,5 +1,7 @@ Date: Wed, 13 Nov 2024 02:56:11 +0000 Subject: [PATCH 11/21] remove vote combination/swap functionality --- app/Enums/StatsTransactionType.php | 3 - app/Http/Livewire/Validators/RecentVotes.php | 23 +-- .../Concerns/Transaction/CanBeSorted.php | 6 +- app/Models/Scopes/VoteCombinationScope.php | 20 --- app/Models/Transaction.php | 2 - app/Services/Forms.php | 1 - .../Aggregates/HistoricalAggregateFactory.php | 7 +- .../Type/VoteCombinationAggregate.php | 15 -- .../Concerns/ManagesTransactionTypes.php | 2 - .../Transactions/TransactionMethod.php | 12 -- .../Concerns/Transaction/HasMethod.php | 15 -- database/factories/TransactionFactory.php | 12 -- resources/lang/en/forms.php | 1 - resources/lang/en/general.php | 2 - resources/lang/en/pages.php | 1 - resources/lang/en/tables.php | 1 - .../encapsulated/transaction-type.blade.php | 1 - .../general/encapsulated/vote-type.blade.php | 8 +- .../results/mobile/transaction-type.blade.php | 2 +- .../results/transaction-types/vote.blade.php | 14 +- .../search/results/transaction.blade.php | 8 +- .../tables/filters/recent-votes.blade.php | 5 - .../page/section-detail/row.blade.php | 2 - .../page/transaction-type.blade.php | 16 +-- .../ShowTransactionControllerTest.php | 17 --- .../Http/Livewire/Stats/InsightsTest.php | 5 - .../Livewire/Validators/RecentVotesTest.php | 134 +++--------------- .../Commands/CacheTransactionsTest.php | 1 - tests/Unit/Models/TransactionTest.php | 17 --- tests/Unit/Services/FormsTest.php | 1 - .../HistoricalAggregateFactoryTest.php | 2 - .../Type/VoteCombinationAggregateTest.php | 16 --- .../Transactions/TransactionTypeTest.php | 5 - .../ViewModels/TransactionViewModelTest.php | 3 - 34 files changed, 32 insertions(+), 348 deletions(-) delete mode 100644 app/Models/Scopes/VoteCombinationScope.php delete mode 100644 app/Services/Transactions/Aggregates/Type/VoteCombinationAggregate.php delete mode 100644 tests/Unit/Services/Transactions/Aggregates/Type/VoteCombinationAggregateTest.php diff --git a/app/Enums/StatsTransactionType.php b/app/Enums/StatsTransactionType.php index 735bbabea..28647899b 100644 --- a/app/Enums/StatsTransactionType.php +++ b/app/Enums/StatsTransactionType.php @@ -16,8 +16,6 @@ enum StatsTransactionType public const UNVOTE = 'unvote'; - public const SWITCH_VOTE = 'switch_vote'; - public const VALIDATOR_REGISTRATION = 'validator_registration'; public const VALIDATOR_RESIGNATION = 'validator_resignation'; @@ -29,7 +27,6 @@ public static function all(): Collection self::MULTIPAYMENT, self::VOTE, self::UNVOTE, - self::SWITCH_VOTE, self::VALIDATOR_REGISTRATION, self::VALIDATOR_RESIGNATION, ]); diff --git a/app/Http/Livewire/Validators/RecentVotes.php b/app/Http/Livewire/Validators/RecentVotes.php index a90bfa7ea..6489eb896 100644 --- a/app/Http/Livewire/Validators/RecentVotes.php +++ b/app/Http/Livewire/Validators/RecentVotes.php @@ -29,9 +29,8 @@ final class RecentVotes extends TabbedTableComponent public const INITIAL_SORT_DIRECTION = SortDirection::DESC; public array $filter = [ - 'vote' => true, - 'unvote' => true, - 'vote-swap' => true, + 'vote' => true, + 'unvote' => true, ]; /** @var mixed */ @@ -42,9 +41,8 @@ final class RecentVotes extends TabbedTableComponent public function queryString(): array { return [ - 'vote' => ['except' => true], - 'unvote' => ['except' => true], - 'vote-swap' => ['except' => true], + 'vote' => ['except' => true], + 'unvote' => ['except' => true], ]; } @@ -96,11 +94,7 @@ private function hasFilters(): bool return true; } - if ($this->filter['unvote'] === true) { - return true; - } - - return $this->filter['vote-swap'] === true; + return $this->filter['unvote'] === true; } private function getRecentVotesQuery(): Builder @@ -121,12 +115,7 @@ private function getRecentVotesQuery(): Builder }))->orWhere(fn ($query) => $query->when($this->filter['unvote'], function ($query) { $query->whereRaw('jsonb_array_length(asset->\'unvotes\') >= 1') ->whereRaw('jsonb_array_length(asset->\'votes\') = 0'); - }))->orWhere(fn ($query) => $query->when( - $this->filter['vote-swap'], - fn ($query) => $query - ->whereRaw('jsonb_array_length(asset->\'votes\') >= 1') - ->whereRaw('jsonb_array_length(asset->\'unvotes\') >= 1') - )); + })); }) ->when($this->sortKey === 'age', fn ($query) => $query->sortByAge($sortDirection)) ->when($this->sortKey === 'address', fn ($query) => $query->sortByAddress($sortDirection)) diff --git a/app/Models/Concerns/Transaction/CanBeSorted.php b/app/Models/Concerns/Transaction/CanBeSorted.php index 645ab1ed2..51884b55a 100644 --- a/app/Models/Concerns/Transaction/CanBeSorted.php +++ b/app/Models/Concerns/Transaction/CanBeSorted.php @@ -25,12 +25,11 @@ public function scopeSortByType(mixed $query, SortDirection $sortDirection): Bui { return $query->select([ 'transaction_type' => fn ($query) => $query - ->selectRaw('coalesce(validator_vote.votecombination, validator_vote.vote, validator_vote.unvote)') + ->selectRaw('coalesce(validator_vote.vote, validator_vote.unvote)') ->from(function ($query) { $query ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'-\') IS null) then 0 end as unvote') ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'+\') IS null) then 1 end as vote') - ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'-\') IS null and asset->\'votes\'->>1 is not null and NULLIF(LEFT(asset->\'votes\'->>1, 1), \'+\') IS null) then 2 end as votecombination') ->whereColumn('transactions.id', 'validator_transaction.id') ->from('transactions', 'validator_transaction'); }, 'validator_vote'), @@ -48,11 +47,10 @@ public function scopeSortByUsername(mixed $query, SortDirection $sortDirection): $query ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'-\') IS null) then substring(asset->\'votes\'->>0, 2) end as unvote') ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'+\') IS null) then substring(asset->\'votes\'->>0, 2) end as vote') - ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'-\') IS null and asset->\'votes\'->>1 is not null and NULLIF(LEFT(asset->\'votes\'->>1, 1), \'+\') IS null) then substring(asset->\'votes\'->>1, 2) end as votecombination') ->whereColumn('transactions.id', 'validator_transaction.id') ->from('transactions', 'validator_transaction'); }, 'validator_vote') - ->join('wallets', 'wallets.public_key', '=', DB::raw('coalesce(validator_vote.votecombination, validator_vote.vote, validator_vote.unvote)')), + ->join('wallets', 'wallets.public_key', '=', DB::raw('coalesce(validator_vote.vote, validator_vote.unvote)')), ]) ->selectRaw('transactions.*') ->orderBy('validator_name', $sortDirection->value); diff --git a/app/Models/Scopes/VoteCombinationScope.php b/app/Models/Scopes/VoteCombinationScope.php deleted file mode 100644 index c30207a29..000000000 --- a/app/Models/Scopes/VoteCombinationScope.php +++ /dev/null @@ -1,20 +0,0 @@ -where('type', TransactionTypeEnum::VOTE); - $builder->whereJsonLength('asset->votes', 1); - $builder->whereJsonLength('asset->unvotes', 1); - } -} diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 797d303c9..35dbd6276 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -16,7 +16,6 @@ use App\Models\Scopes\UsernameResignationScope; use App\Models\Scopes\ValidatorRegistrationScope; use App\Models\Scopes\ValidatorResignationScope; -use App\Models\Scopes\VoteCombinationScope; use App\Models\Scopes\VoteScope; use App\Services\BigNumber; use App\Services\VendorField; @@ -68,7 +67,6 @@ final class Transaction extends Model 'usernameResignation' => UsernameResignationScope::class, 'transfer' => TransferScope::class, 'vote' => VoteScope::class, - 'voteCombination' => VoteCombinationScope::class, ]; /** diff --git a/app/Services/Forms.php b/app/Services/Forms.php index 9b95d676b..fccbfd985 100644 --- a/app/Services/Forms.php +++ b/app/Services/Forms.php @@ -14,7 +14,6 @@ final class Forms 'validatorRegistration', 'validatorResignation', 'vote', - 'voteCombination', 'multiSignature', 'multiPayment', 'usernameRegistration', diff --git a/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php b/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php index 1f2169149..250dd094b 100644 --- a/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php +++ b/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php @@ -18,7 +18,6 @@ use App\Services\Transactions\Aggregates\Type\ValidatorRegistrationAggregate; use App\Services\Transactions\Aggregates\Type\ValidatorResignationAggregate; use App\Services\Transactions\Aggregates\Type\VoteAggregate; -use App\Services\Transactions\Aggregates\Type\VoteCombinationAggregate; use InvalidArgumentException; final class HistoricalAggregateFactory @@ -52,7 +51,7 @@ public static function period(string $period): DayAggregate | WeekAggregate | Mo throw new InvalidArgumentException('Invalid aggregate period.'); } - public static function type(string $type): TransferAggregate | MultipaymentAggregate | VoteAggregate | UnvoteAggregate | VoteCombinationAggregate | ValidatorRegistrationAggregate | ValidatorResignationAggregate + public static function type(string $type): TransferAggregate | MultipaymentAggregate | VoteAggregate | UnvoteAggregate | ValidatorRegistrationAggregate | ValidatorResignationAggregate { if ($type === StatsTransactionType::TRANSFER) { return new TransferAggregate(); @@ -70,10 +69,6 @@ public static function type(string $type): TransferAggregate | MultipaymentAggre return new UnvoteAggregate(); } - if ($type === StatsTransactionType::SWITCH_VOTE) { - return new VoteCombinationAggregate(); - } - if ($type === StatsTransactionType::VALIDATOR_REGISTRATION) { return new ValidatorRegistrationAggregate(); } diff --git a/app/Services/Transactions/Aggregates/Type/VoteCombinationAggregate.php b/app/Services/Transactions/Aggregates/Type/VoteCombinationAggregate.php deleted file mode 100644 index a35615efb..000000000 --- a/app/Services/Transactions/Aggregates/Type/VoteCombinationAggregate.php +++ /dev/null @@ -1,15 +0,0 @@ - 'transfer', 'isValidatorRegistration' => 'validator-registration', - 'isVoteCombination' => 'vote-combination', 'isUnvote' => 'unvote', 'isVote' => 'vote', 'isMultiSignature' => 'multi-signature', @@ -22,7 +21,6 @@ trait ManagesTransactionTypes private array $typesExact = [ 'isTransfer' => 'transfer', 'isValidatorRegistration' => 'validator-registration', - 'isVoteCombination' => 'vote-combination', 'isUnvote' => 'unvote', 'isVote' => 'vote', 'isMultiSignature' => 'multi-signature', diff --git a/app/Services/Transactions/TransactionMethod.php b/app/Services/Transactions/TransactionMethod.php index 4eb7baed7..eed151815 100644 --- a/app/Services/Transactions/TransactionMethod.php +++ b/app/Services/Transactions/TransactionMethod.php @@ -21,7 +21,6 @@ final class TransactionMethod 'isValidatorRegistration' => 'validator-registration', // 'isUsernameRegistration' => 'username-registration', // 'isUsernameResignation' => 'username-resignation', - // 'isVoteCombination' => 'vote-combination', 'isUnvote' => 'unvote', 'isVote' => 'vote', // 'isMultiSignature' => 'multi-signature', @@ -69,13 +68,6 @@ public function isUnvote(): bool return $this->methodHash === PayloadSignature::UNVOTE->value; } - // public function isVoteCombination(): bool - // { - // [$containsVote, $containsUnvote] = $this->determineVoteTypes(); - - // return $containsVote && $containsUnvote; - // } - // public function isMultiSignature(): bool // { // return $this->transaction->type === TransactionTypeEnum::MULTI_SIGNATURE; @@ -111,10 +103,6 @@ public function isUnknown(): bool return false; } - // if ($this->isVoteCombination()) { - // return false; - // } - if ($this->isUnvote()) { return false; } diff --git a/app/ViewModels/Concerns/Transaction/HasMethod.php b/app/ViewModels/Concerns/Transaction/HasMethod.php index 9c259ccff..0f992fc37 100644 --- a/app/ViewModels/Concerns/Transaction/HasMethod.php +++ b/app/ViewModels/Concerns/Transaction/HasMethod.php @@ -33,13 +33,6 @@ public function isUnvote(): bool return $this->method->isUnvote(); } - public function isVoteCombination(): bool - { - return false; - - return $this->method->isVoteCombination(); - } - public function isMultiSignature(): bool { return false; @@ -95,10 +88,6 @@ public function isLegacy(): bool // return false; // } - // if ($this->isVoteCombination()) { - // return false; - // } - if ($this->isVote()) { return false; } @@ -133,10 +122,6 @@ public function isSelfReceiving(): bool return true; } - // if ($this->isVoteCombination()) { - // return true; - // } - if ($this->isVote()) { return true; } diff --git a/database/factories/TransactionFactory.php b/database/factories/TransactionFactory.php index c77d16f54..4325fb8d8 100644 --- a/database/factories/TransactionFactory.php +++ b/database/factories/TransactionFactory.php @@ -81,18 +81,6 @@ public function unvote(): Factory ]); } - public function voteCombination(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::VOTE, - 'type_group' => 1, - 'asset' => [ - 'votes' => ['address'], - 'unvotes' => ['address'], - ], - ]); - } - public function multiSignature(): Factory { return $this->state(fn () => [ diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 4b368d40f..d8afb7828 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -38,7 +38,6 @@ 'multiSignature' => 'Multisignature', 'transfer' => 'Transfer', 'vote' => 'Vote', - 'voteCombination' => 'Switch Vote', ], ], diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index e1bd8fee9..71b5e3078 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -117,13 +117,11 @@ 'voting_validator' => 'Voting for :validator', 'vote_validator' => 'Vote: :validator', 'unvote_validator' => 'Unvote: :validator', - 'vote_swap_validator' => 'Unvote: :validator_unvote | Vote: :validator_vote', 'types' => [ 'validator-registration' => 'Registration', 'validator-resignation' => 'Resignation', 'multi-payment' => 'Multipayment', - 'vote-combination' => 'Vote Swap', 'multi-signature' => 'Multisignature', 'username-registration' => 'Username Registration', 'username-resignation' => 'Username Resignation', diff --git a/resources/lang/en/pages.php b/resources/lang/en/pages.php index e9452811a..66aefac44 100644 --- a/resources/lang/en/pages.php +++ b/resources/lang/en/pages.php @@ -511,7 +511,6 @@ 'multipayment' => 'Multipayments', 'vote' => 'Votes', 'unvote' => 'Unvotes', - 'switch_vote' => 'Switch Votes', 'validator_registration' => 'Validator Registrations', 'validator_resignation' => 'Validator Resignations', 'transactions' => 'Transactions', diff --git a/resources/lang/en/tables.php b/resources/lang/en/tables.php index d744114e9..cec0d7693 100644 --- a/resources/lang/en/tables.php +++ b/resources/lang/en/tables.php @@ -165,7 +165,6 @@ 'select_all' => 'Select All', 'vote' => 'Vote', 'unvote' => 'Unvote', - 'vote_swap' => 'Vote Swap', ], ], ]; diff --git a/resources/views/components/general/encapsulated/transaction-type.blade.php b/resources/views/components/general/encapsulated/transaction-type.blade.php index d66bc4ce4..ca9b2c8d4 100644 --- a/resources/views/components/general/encapsulated/transaction-type.blade.php +++ b/resources/views/components/general/encapsulated/transaction-type.blade.php @@ -4,7 +4,6 @@ $isVoteType = in_array($transaction->typeName(), [ 'vote', 'unvote', - 'vote-combination', ]); @endphp diff --git a/resources/views/components/general/encapsulated/vote-type.blade.php b/resources/views/components/general/encapsulated/vote-type.blade.php index f564adf05..ea6ec2981 100644 --- a/resources/views/components/general/encapsulated/vote-type.blade.php +++ b/resources/views/components/general/encapsulated/vote-type.blade.php @@ -1,12 +1,6 @@ @props(['transaction']) -@if($transaction->isVoteCombination()) - - @lang('general.transaction.types.'.$transaction->typeName()) - -@elseif($transaction->isVote()) +@if($transaction->isVote()) diff --git a/resources/views/components/search/results/mobile/transaction-type.blade.php b/resources/views/components/search/results/mobile/transaction-type.blade.php index 30b671a34..5e2dad427 100644 --- a/resources/views/components/search/results/mobile/transaction-type.blade.php +++ b/resources/views/components/search/results/mobile/transaction-type.blade.php @@ -7,7 +7,7 @@ @if ($transaction->isTransfer()) - @elseif ($transaction->isVote() || $transaction->isUnvote() || $transaction->isVoteCombination()) + @elseif ($transaction->isVote() || $transaction->isUnvote()) @elseif ($transaction->isMultiPayment()) diff --git a/resources/views/components/search/results/transaction-types/vote.blade.php b/resources/views/components/search/results/transaction-types/vote.blade.php index 812bc6342..cfd2fa2e8 100644 --- a/resources/views/components/search/results/transaction-types/vote.blade.php +++ b/resources/views/components/search/results/transaction-types/vote.blade.php @@ -18,16 +18,8 @@ class="text-theme-secondary-900 dark:text-theme-dark-50" @lang('general.search.to') - @if ($transaction->isVoteCombination()) - - @else - - @lang('general.search.contract') - - @endif + + @lang('general.search.contract') + diff --git a/resources/views/components/search/results/transaction.blade.php b/resources/views/components/search/results/transaction.blade.php index a0ffbe8fa..2fa3950db 100644 --- a/resources/views/components/search/results/transaction.blade.php +++ b/resources/views/components/search/results/transaction.blade.php @@ -36,7 +36,7 @@ @lang('general.search.from') - @if ($transaction->isVote() || $transaction->isUnvote() || $transaction->isVoteCombination()) + @if ($transaction->isVote() || $transaction->isUnvote()) - @elseif ($transaction->isVoteCombination()) - @elseif ($transaction->isMultiPayment()) @lang('tables.transactions.multiple') diff --git a/resources/views/components/tables/filters/recent-votes.blade.php b/resources/views/components/tables/filters/recent-votes.blade.php index 52b15a5dc..16264bd08 100644 --- a/resources/views/components/tables/filters/recent-votes.blade.php +++ b/resources/views/components/tables/filters/recent-votes.blade.php @@ -24,11 +24,6 @@ class="pb-4 mb-4 border-b md:pb-2 md:mb-1 border-theme-secondary-300 dark:border name="unvote" :label="trans('tables.filters.recent-votes.unvote')" /> - - diff --git a/resources/views/components/transaction/page/section-detail/row.blade.php b/resources/views/components/transaction/page/section-detail/row.blade.php index 1a38e4285..89c7c0c0c 100644 --- a/resources/views/components/transaction/page/section-detail/row.blade.php +++ b/resources/views/components/transaction/page/section-detail/row.blade.php @@ -11,8 +11,6 @@ $headerWidth = 'w-[87px]'; if ($transaction->hasPayload()) { $headerWidth = 'w-[132px]'; - } elseif ($transaction->isVoteCombination()) { - $headerWidth = 'w-[109px]'; } elseif ($transaction->isLegacy()) { $headerWidth = 'w-[110px]'; } diff --git a/resources/views/components/transaction/page/transaction-type.blade.php b/resources/views/components/transaction/page/transaction-type.blade.php index 317e6c7db..bb011f36f 100644 --- a/resources/views/components/transaction/page/transaction-type.blade.php +++ b/resources/views/components/transaction/page/transaction-type.blade.php @@ -12,21 +12,7 @@ class="inline text-theme-secondary-700 dark:text-theme-dark-200" /> - @if ($transaction->isVoteCombination()) - - {{-- --}} - - - - {{-- --}} - - @elseif ($transaction->isVote() || $transaction->isUnvote()) + @if ($transaction->isVote() || $transaction->isUnvote()) withoutExceptionHandling(); - - $oldValidator = Wallet::factory()->activeValidator()->create(); - $newValidator = Wallet::factory()->activeValidator()->create(); - $transaction = Transaction::factory()->voteCombination()->create([ - 'asset' => [ - 'unvotes' => [$oldValidator->address, '+'.$newValidator->address], - ], - ]); - - $this - ->get(route('transaction', $transaction)) - ->assertOk() - ->assertSee($transaction->id); -}); diff --git a/tests/Feature/Http/Livewire/Stats/InsightsTest.php b/tests/Feature/Http/Livewire/Stats/InsightsTest.php index 27dc379af..31e86abff 100644 --- a/tests/Feature/Http/Livewire/Stats/InsightsTest.php +++ b/tests/Feature/Http/Livewire/Stats/InsightsTest.php @@ -36,7 +36,6 @@ ]); Transaction::factory(15)->vote()->create(); Transaction::factory(16)->unvote()->create(); - Transaction::factory(17)->voteCombination()->create(); $largest = Transaction::factory()->multiPayment()->create([ 'amount' => 99 * 1e18, @@ -75,7 +74,6 @@ 'multipayment' => 18, 'vote' => 15, 'unvote' => 16, - 'switch_vote' => 17, 'validator_registration' => 12, 'validator_resignation' => 13, ], @@ -94,8 +92,6 @@ '15', trans('pages.statistics.insights.transactions.header.unvote'), '16', - trans('pages.statistics.insights.transactions.header.switch_vote'), - '17', trans('pages.statistics.insights.transactions.header.validator_registration'), '12', trans('pages.statistics.insights.transactions.header.validator_resignation'), @@ -152,7 +148,6 @@ trans('pages.statistics.insights.transactions.header.multipayment'), trans('pages.statistics.insights.transactions.header.vote'), trans('pages.statistics.insights.transactions.header.unvote'), - trans('pages.statistics.insights.transactions.header.switch_vote'), trans('pages.statistics.insights.transactions.header.validator_registration'), trans('pages.statistics.insights.transactions.header.validator_resignation'), trans('pages.statistics.insights.transactions.header.transactions'), diff --git a/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php b/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php index 58d60122d..69f47c501 100644 --- a/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php +++ b/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php @@ -84,24 +84,21 @@ Livewire::test(RecentVotes::class) ->call('setIsReady') ->assertSet('filter', [ - 'vote' => true, - 'unvote' => true, - 'vote-swap' => true, + 'vote' => true, + 'unvote' => true, ]) ->assertSet('selectAllFilters', true) ->set('filter.vote', true) ->assertSet('selectAllFilters', true) ->set('selectAllFilters', false) ->assertSet('filter', [ - 'vote' => false, - 'unvote' => false, - 'vote-swap' => false, + 'vote' => false, + 'unvote' => false, ]) ->set('selectAllFilters', true) ->assertSet('filter', [ - 'vote' => true, - 'unvote' => true, - 'vote-swap' => true, + 'vote' => true, + 'unvote' => true, ]); }); @@ -109,9 +106,8 @@ Livewire::test(RecentVotes::class) ->call('setIsReady') ->assertSet('filter', [ - 'vote' => true, - 'unvote' => true, - 'vote-swap' => true, + 'vote' => true, + 'unvote' => true, ]) ->assertSet('selectAllFilters', true) ->set('filter.vote', false) @@ -143,25 +139,14 @@ ], ]); - $voteSwap = Transaction::factory()->voteCombination()->create([ - 'sender_public_key' => $sender->public_key, - 'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(), - 'asset' => [ - 'votes' => [$otherValidator->public_key], - 'unvotes' => [$validator->public_key], - ], - ]); - Livewire::test(RecentVotes::class) ->call('setIsReady') ->set('filter', [ - 'vote' => true, - 'unvote' => false, - 'vote-swap' => false, + 'vote' => true, + 'unvote' => false, ]) ->assertSee($vote->id) - ->assertDontSee($unvote->id) - ->assertDontSee($voteSwap->id); + ->assertDontSee($unvote->id); }); it('should filter unvote transactions', function () { @@ -187,76 +172,22 @@ ], ]); - $voteSwap = Transaction::factory()->voteCombination()->create([ - 'sender_public_key' => $sender->public_key, - 'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(), - 'asset' => [ - 'votes' => [$otherValidator->public_key], - 'unvotes' => [$validator->public_key], - ], - ]); - Livewire::test(RecentVotes::class) ->call('setIsReady') ->set('filter', [ - 'vote' => false, - 'unvote' => true, - 'vote-swap' => false, + 'vote' => false, + 'unvote' => true, ]) ->assertSee($unvote->id) - ->assertDontSee($vote->id) - ->assertDontSee($voteSwap->id); -}); - -it('should filter vote swap transactions', function () { - $sender = Wallet::factory()->create(); - $validator = Wallet::factory()->activeValidator()->create(); - $otherValidator = Wallet::factory()->activeValidator()->create(); - - $vote = Transaction::factory()->vote()->create([ - 'sender_public_key' => $sender->public_key, - 'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(), - 'asset' => [ - 'votes' => [$validator->public_key], - ], - ]); - - $unvote = Transaction::factory()->unvote()->create([ - 'sender_public_key' => $sender->public_key, - 'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(), - 'asset' => [ - 'unvotes' => [$validator->public_key], - ], - ]); - - $voteSwap = Transaction::factory()->voteCombination()->create([ - 'sender_public_key' => $sender->public_key, - 'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(), - 'asset' => [ - 'votes' => [$otherValidator->public_key], - 'unvotes' => [$validator->public_key], - ], - ]); - - Livewire::test(RecentVotes::class) - ->call('setIsReady') - ->set('filter', [ - 'vote' => false, - 'unvote' => false, - 'vote-swap' => true, - ]) - ->assertSee($voteSwap->id) - ->assertDontSee($vote->id) - ->assertDontSee($unvote->id); + ->assertDontSee($vote->id); }); it('should show correct message when no filters are selected', function () { Livewire::test(RecentVotes::class) ->call('setIsReady') ->set('filter', [ - 'vote' => false, - 'unvote' => false, - 'vote-swap' => false, + 'vote' => false, + 'unvote' => false, ]) ->assertSee(trans('tables.recent-votes.no_results.no_filters')); }); @@ -304,21 +235,12 @@ function generateTransactions(): array ], ]); - $voteSwapTransaction = Transaction::factory()->voteCombination()->create([ - 'timestamp' => Timestamp::fromUnix(Carbon::parse('2023-09-18 05:41:04')->unix())->unix(), - 'asset' => [ - 'votes' => [$validator3->public_key], - 'unvotes' => [$validator1->public_key], - ], - ]); - return [ 'validator1' => $validator1, 'validator2' => $validator2, 'validator3' => $validator3, 'voteTransaction' => $voteTransaction, 'unvoteTransaction' => $unvoteTransaction, - 'voteSwapTransaction' => $voteSwapTransaction, ]; }; @@ -330,10 +252,8 @@ function generateTransactions(): array ->assertSet('sortKey', 'age') ->assertSet('sortDirection', SortDirection::DESC) ->assertSeeInOrder([ - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, ]); @@ -349,10 +269,8 @@ function generateTransactions(): array ->assertSeeInOrder([ $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, ]); }); @@ -366,10 +284,8 @@ function generateTransactions(): array ->assertSeeInOrder([ $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, ]); }); @@ -382,10 +298,8 @@ function generateTransactions(): array ->call('sortBy', 'name') ->assertSet('sortDirection', SortDirection::DESC) ->assertSeeInOrder([ - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, ]); @@ -399,10 +313,8 @@ function generateTransactions(): array ->call('sortBy', 'address') ->assertSet('sortDirection', SortDirection::ASC) ->assertSeeInOrder([ - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, ]); @@ -419,10 +331,8 @@ function generateTransactions(): array ->assertSeeInOrder([ $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, ]); }); @@ -436,10 +346,8 @@ function generateTransactions(): array ->assertSeeInOrder([ $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, ]); }); @@ -452,10 +360,8 @@ function generateTransactions(): array ->call('sortBy', 'type') ->assertSet('sortDirection', SortDirection::DESC) ->assertSeeInOrder([ - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, ]); @@ -509,18 +415,14 @@ function generateTransactions(): array ->assertSeeInOrder([ $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, ]); $this->get('/test-validators?sort=type&sort-direction=desc') ->assertSeeInOrder([ - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, ]); @@ -535,10 +437,8 @@ function generateTransactions(): array $this->get('/test-validators?sort=type&sort-direction=desc') ->assertSeeInOrder([ - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, - $data['voteSwapTransaction']->address, $data['voteTransaction']->address, $data['unvoteTransaction']->address, ]); @@ -547,9 +447,7 @@ function generateTransactions(): array ->assertSeeInOrder([ $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, $data['unvoteTransaction']->address, $data['voteTransaction']->address, - $data['voteSwapTransaction']->address, ]); }); diff --git a/tests/Unit/Console/Commands/CacheTransactionsTest.php b/tests/Unit/Console/Commands/CacheTransactionsTest.php index c5b9ca871..02e3d83a0 100644 --- a/tests/Unit/Console/Commands/CacheTransactionsTest.php +++ b/tests/Unit/Console/Commands/CacheTransactionsTest.php @@ -61,7 +61,6 @@ expect($cache->getHistoricalByType(StatsTransactionType::TRANSFER))->toBe(4); expect($cache->getHistoricalByType(StatsTransactionType::MULTIPAYMENT))->toBe(4); expect($cache->getHistoricalByType(StatsTransactionType::VALIDATOR_RESIGNATION))->toBe(0); - expect($cache->getHistoricalByType(StatsTransactionType::SWITCH_VOTE))->toBe(0); expect($cache->getHistoricalByType(StatsTransactionType::UNVOTE))->toBe(0); expect($cache->getHistoricalByType(StatsTransactionType::VOTE))->toBe(0); diff --git a/tests/Unit/Models/TransactionTest.php b/tests/Unit/Models/TransactionTest.php index 4b3b14477..5a0f2229a 100644 --- a/tests/Unit/Models/TransactionTest.php +++ b/tests/Unit/Models/TransactionTest.php @@ -70,23 +70,6 @@ expect($transaction->recipient())->toEqual($validator->fresh()); }); -it('should get vote recipient if vote combination', function () { - $validator = Wallet::factory()->activeValidator()->create(); - $oldValidator = Wallet::factory()->activeValidator()->create(); - - $transaction = Transaction::factory() - ->voteCombination() - ->create([ - 'recipient_id' => null, - 'asset' => [ - 'votes' => [$validator->public_key], - 'unvotes' => [$oldValidator->public_key], - ], - ]); - - expect($transaction->recipient())->toEqual($validator->fresh()); -}); - it('should get vendorfield value multiple times despite resource', function () { $transaction = Transaction::factory()->transfer()->create([ 'recipient_id' => 'DENGkAwEfRvhhHKZYdEfQ1P3MEoRvPkHYj', diff --git a/tests/Unit/Services/FormsTest.php b/tests/Unit/Services/FormsTest.php index 8e0171d74..4a8003ccc 100644 --- a/tests/Unit/Services/FormsTest.php +++ b/tests/Unit/Services/FormsTest.php @@ -11,7 +11,6 @@ 'validatorRegistration', 'validatorResignation', 'vote', - 'voteCombination', 'multiSignature', 'multiPayment', 'usernameRegistration', diff --git a/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php b/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php index 34f46191f..0998e7fcf 100644 --- a/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php +++ b/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php @@ -16,7 +16,6 @@ use App\Services\Transactions\Aggregates\Type\ValidatorRegistrationAggregate; use App\Services\Transactions\Aggregates\Type\ValidatorResignationAggregate; use App\Services\Transactions\Aggregates\Type\VoteAggregate; -use App\Services\Transactions\Aggregates\Type\VoteCombinationAggregate; it('should create an instance that matches the period', function (string $type, string $class) { expect(HistoricalAggregateFactory::period($type))->toBeInstanceOf($class); @@ -40,7 +39,6 @@ [StatsTransactionType::MULTIPAYMENT, MultipaymentAggregate::class], [StatsTransactionType::VOTE, VoteAggregate::class], [StatsTransactionType::UNVOTE, UnvoteAggregate::class], - [StatsTransactionType::SWITCH_VOTE, VoteCombinationAggregate::class], [StatsTransactionType::VALIDATOR_REGISTRATION, ValidatorRegistrationAggregate::class], [StatsTransactionType::VALIDATOR_RESIGNATION, ValidatorResignationAggregate::class], ]); diff --git a/tests/Unit/Services/Transactions/Aggregates/Type/VoteCombinationAggregateTest.php b/tests/Unit/Services/Transactions/Aggregates/Type/VoteCombinationAggregateTest.php deleted file mode 100644 index a5a95e530..000000000 --- a/tests/Unit/Services/Transactions/Aggregates/Type/VoteCombinationAggregateTest.php +++ /dev/null @@ -1,16 +0,0 @@ -aggregate())->toBe(0); - - Transaction::factory(10) - ->voteCombination() - ->create(); - - expect((new VoteCombinationAggregate())->aggregate())->toBe(10); -}); diff --git a/tests/Unit/Services/Transactions/TransactionTypeTest.php b/tests/Unit/Services/Transactions/TransactionTypeTest.php index 96ecf7a95..75ddf9a05 100644 --- a/tests/Unit/Services/Transactions/TransactionTypeTest.php +++ b/tests/Unit/Services/Transactions/TransactionTypeTest.php @@ -28,10 +28,6 @@ 'unvote', 'unvote', ], - [ - 'voteCombination', - 'vote-combination', - ], [ 'multiSignature', 'multi-signature', @@ -74,7 +70,6 @@ ['validatorRegistration'], ['vote'], ['unvote'], - ['voteCombination'], ['multiSignature'], ['validatorResignation'], ['multiPayment'], diff --git a/tests/Unit/ViewModels/TransactionViewModelTest.php b/tests/Unit/ViewModels/TransactionViewModelTest.php index 160831df7..efa8e95d5 100644 --- a/tests/Unit/ViewModels/TransactionViewModelTest.php +++ b/tests/Unit/ViewModels/TransactionViewModelTest.php @@ -496,7 +496,6 @@ ['validatorRegistration'], ['vote'], ['unvote'], - ['voteCombination'], ['multiSignature'], ['validatorResignation'], ['multiPayment'], @@ -521,7 +520,6 @@ ['validatorRegistration'], ['vote'], ['unvote'], - ['voteCombination'], ['validatorResignation'], ['usernameRegistration'], ['usernameResignation'], @@ -1110,7 +1108,6 @@ 'validatorResignation', 'multisignature', 'multiPayment', - 'voteCombination', 'vote', 'unvote', 'usernameRegistration', From eeee5e2bfd2d92b920c2238b73f3ca0f7926792b Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:57:17 +0000 Subject: [PATCH 12/21] remove legacy & subcategory handling --- .../Concerns/Transaction/HasMethod.php | 41 ------------------- resources/lang/en/general.php | 1 - resources/lang/en/pages.php | 9 ---- .../encapsulated/transaction-type.blade.php | 12 ++---- .../page/section-detail/row.blade.php | 2 - .../page/transaction-type.blade.php | 6 --- .../ViewModels/TransactionViewModelTest.php | 25 ----------- 7 files changed, 4 insertions(+), 92 deletions(-) diff --git a/app/ViewModels/Concerns/Transaction/HasMethod.php b/app/ViewModels/Concerns/Transaction/HasMethod.php index 0f992fc37..135baaae5 100644 --- a/app/ViewModels/Concerns/Transaction/HasMethod.php +++ b/app/ViewModels/Concerns/Transaction/HasMethod.php @@ -66,47 +66,6 @@ public function isUsernameResignation(): bool return $this->method->isUsernameResignation(); } - public function isLegacy(): bool - { - if ($this->isValidatorRegistration()) { - return false; - } - - if ($this->isValidatorResignation()) { - return false; - } - - // if ($this->isUsernameRegistration()) { - // return false; - // } - - // if ($this->isUsernameResignation()) { - // return false; - // } - - // if ($this->isMultiPayment()) { - // return false; - // } - - if ($this->isVote()) { - return false; - } - - if ($this->isUnvote()) { - return false; - } - - if ($this->isTransfer()) { - return false; - } - - // if ($this->isMultiSignature()) { - // return false; - // } - - return true; - } - public function isUnknown(): bool { return $this->method->isUnknown(); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 71b5e3078..144c3a8d3 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -129,7 +129,6 @@ 'unvote' => 'Unvote', 'vote' => 'Vote', 'unknown' => 'Unknown', - 'legacy' => 'Legacy', ], ], diff --git a/resources/lang/en/pages.php b/resources/lang/en/pages.php index 66aefac44..fcb965eae 100644 --- a/resources/lang/en/pages.php +++ b/resources/lang/en/pages.php @@ -112,7 +112,6 @@ 'address' => 'Address', 'signatures' => 'Signatures', 'hash' => 'Hash', - 'sub_category' => 'Sub-Category', 'from' => 'From', 'to' => 'To', 'amount' => 'Amount', @@ -127,14 +126,6 @@ 'multiple_x' => 'Multiple ()', ], - 'types' => [ - ...trans('general.transaction.types'), - - 'legacy-business-registration' => 'Business Registration', - 'legacy-business-resignation' => 'Business Resignation', - 'legacy-business-update' => 'Business Update', - ], - 'code-block' => [ 'copy_code' => 'Copy Code', diff --git a/resources/views/components/general/encapsulated/transaction-type.blade.php b/resources/views/components/general/encapsulated/transaction-type.blade.php index ca9b2c8d4..d0c986895 100644 --- a/resources/views/components/general/encapsulated/transaction-type.blade.php +++ b/resources/views/components/general/encapsulated/transaction-type.blade.php @@ -7,12 +7,8 @@ ]); @endphp -@unless ($transaction->isLegacy()) - @if ($isVoteType) - - @else - @lang('general.transaction.types.'.$transaction->typeName()) - @endif +@if ($isVoteType) + @else - @lang('general.transaction.types.legacy') -@endunless + @lang('general.transaction.types.'.$transaction->typeName()) +@endif diff --git a/resources/views/components/transaction/page/section-detail/row.blade.php b/resources/views/components/transaction/page/section-detail/row.blade.php index 89c7c0c0c..441d7be89 100644 --- a/resources/views/components/transaction/page/section-detail/row.blade.php +++ b/resources/views/components/transaction/page/section-detail/row.blade.php @@ -11,8 +11,6 @@ $headerWidth = 'w-[87px]'; if ($transaction->hasPayload()) { $headerWidth = 'w-[132px]'; - } elseif ($transaction->isLegacy()) { - $headerWidth = 'w-[110px]'; } @endphp diff --git a/resources/views/components/transaction/page/transaction-type.blade.php b/resources/views/components/transaction/page/transaction-type.blade.php index bb011f36f..d717fc7a1 100644 --- a/resources/views/components/transaction/page/transaction-type.blade.php +++ b/resources/views/components/transaction/page/transaction-type.blade.php @@ -47,11 +47,5 @@ class="inline text-theme-secondary-700 dark:text-theme-dark-200" :value="$transaction->username()" :transaction="$transaction" /> - @elseif ($transaction->isLegacy()) - @endif
diff --git a/tests/Unit/ViewModels/TransactionViewModelTest.php b/tests/Unit/ViewModels/TransactionViewModelTest.php index efa8e95d5..f9b70ab51 100644 --- a/tests/Unit/ViewModels/TransactionViewModelTest.php +++ b/tests/Unit/ViewModels/TransactionViewModelTest.php @@ -1098,31 +1098,6 @@ expect($this->subject->multiSignatureMinimum())->toBe(3); }); -it('should determine a non-legacy transaction', function ($transaction) { - $transaction = new TransactionViewModel(Transaction::factory()->{$transaction}()->create()); - - expect($transaction->isLegacy())->toBeFalse(); -})->with([ - 'transfer', - 'validatorRegistration', - 'validatorResignation', - 'multisignature', - 'multiPayment', - 'vote', - 'unvote', - 'usernameRegistration', - 'usernameResignation', -]); - -it('should determine a legacy transaction', function () { - $transaction = new TransactionViewModel(Transaction::factory()->create([ - 'type' => '12345', - 'type_group' => '55555', - ])); - - expect($transaction->isLegacy())->toBeTrue(); -}); - describe('HasPayload trait', function () { it('should determine if a transaction has a payload', function () { $transaction = new TransactionViewModel(Transaction::factory()->create([ From 7f5a0edd1a5a60e48bebc5d63b76420e13168ea9 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:41:33 +0000 Subject: [PATCH 13/21] output method has & update transaction page headings --- app/Services/Transactions/TransactionMethod.php | 4 ++-- resources/lang/en/forms.php | 2 +- resources/lang/en/pages.php | 4 ++-- .../encapsulated/transaction-type.blade.php | 6 +++--- .../general/encapsulated/vote-type.blade.php | 16 ++++++++++------ .../transaction/page/transaction-type.blade.php | 12 ++++++++---- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/Services/Transactions/TransactionMethod.php b/app/Services/Transactions/TransactionMethod.php index eed151815..0bc7da8ed 100644 --- a/app/Services/Transactions/TransactionMethod.php +++ b/app/Services/Transactions/TransactionMethod.php @@ -37,11 +37,11 @@ public function name(): string { foreach ($this->types as $method => $name) { if ((bool) call_user_func_safe([$this, $method])) { - return $name; + return trans('general.transaction.types.'.$name); } } - return 'unknown'; + return '0x'.$this->methodHash; } public function isTransfer(): bool diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index d8afb7828..4efaeff29 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -27,7 +27,7 @@ 'term_placeholder' => 'Find a block, transaction, address or validator ...', 'term_placeholder_mobile' => 'Search ...', 'type' => 'Search Type', - 'transaction_method' => 'Transaction Method', + 'action' => 'Action', 'transaction_types' => [ 'all' => 'All', 'validatorRegistration' => 'Validator Registration', diff --git a/resources/lang/en/pages.php b/resources/lang/en/pages.php index fcb965eae..47d64b48d 100644 --- a/resources/lang/en/pages.php +++ b/resources/lang/en/pages.php @@ -86,7 +86,7 @@ ], 'transaction' => [ - 'transaction_method' => 'Transaction Method', + 'action' => 'Action', 'transaction_id' => 'Transaction ID', 'transaction_id_copied' => 'Transaction ID Copied', 'transaction_details' => 'Transaction Details', @@ -104,7 +104,7 @@ 'timestamp' => 'Timestamp', 'block' => 'Block', 'nonce' => 'Nonce', - 'category' => 'Category', + 'method' => 'Method', 'validator' => 'Validator', 'username' => 'Name', 'old_validator' => 'Old Validator', diff --git a/resources/views/components/general/encapsulated/transaction-type.blade.php b/resources/views/components/general/encapsulated/transaction-type.blade.php index d0c986895..39add1a6a 100644 --- a/resources/views/components/general/encapsulated/transaction-type.blade.php +++ b/resources/views/components/general/encapsulated/transaction-type.blade.php @@ -2,13 +2,13 @@ @php $isVoteType = in_array($transaction->typeName(), [ - 'vote', - 'unvote', + 'Vote', + 'Unvote', ]); @endphp @if ($isVoteType) @else - @lang('general.transaction.types.'.$transaction->typeName()) + {{ $transaction->typeName() }} @endif diff --git a/resources/views/components/general/encapsulated/vote-type.blade.php b/resources/views/components/general/encapsulated/vote-type.blade.php index ea6ec2981..e5bca9b3f 100644 --- a/resources/views/components/general/encapsulated/vote-type.blade.php +++ b/resources/views/components/general/encapsulated/vote-type.blade.php @@ -1,15 +1,19 @@ @props(['transaction']) @if($transaction->isVote()) + @php($votedValidator = $transaction->voted()) + hasUsername()) + data-tippy-html-content="{{ trans('general.transaction.vote_validator', ['validator' => $votedValidator->username()]) }}" + @elseif ($votedValidator) + data-tippy-html-content="{{ trans('general.transaction.vote_validator', ['validator' => $votedValidator->address()]) }}" + @endif > - @lang('general.transaction.types.'.$transaction->typeName()) + {{ $transaction->typeName() }} @else - - @lang('general.transaction.types.'.$transaction->typeName()) + + {{ $transaction->typeName() }} @endif diff --git a/resources/views/components/transaction/page/transaction-type.blade.php b/resources/views/components/transaction/page/transaction-type.blade.php index d717fc7a1..e02651364 100644 --- a/resources/views/components/transaction/page/transaction-type.blade.php +++ b/resources/views/components/transaction/page/transaction-type.blade.php @@ -1,8 +1,8 @@ @props(['transaction']) - + @@ -12,12 +12,16 @@ class="inline text-theme-secondary-700 dark:text-theme-dark-200" /> - @if ($transaction->isVote() || $transaction->isUnvote()) + @if ($transaction->isVote()) + @php($votedValidator = $transaction->voted()) + - {{-- --}} + @if ($votedValidator) + + @endif @elseif ($transaction->isMultisignature()) Date: Wed, 13 Nov 2024 15:42:50 +0000 Subject: [PATCH 14/21] get voted validator from payload --- .../Transaction/InteractsWithVotes.php | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php b/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php index 5c2870eb5..7ab774d62 100644 --- a/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php +++ b/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php @@ -4,9 +4,9 @@ namespace App\ViewModels\Concerns\Transaction; -use App\Facades\Wallets; +use App\Models\Wallet; use App\ViewModels\WalletViewModel; -use Illuminate\Support\Arr; +use ArkEcosystem\Crypto\Utils\AbiDecoder; trait InteractsWithVotes { @@ -16,31 +16,16 @@ public function voted(): ?WalletViewModel return null; } - return null; + $method = (new AbiDecoder())->decodeFunctionData($this->rawPayload()); - // /** @var array */ - // $votes = Arr::get($this->transaction->asset ?? [], 'votes'); + /** @var string $address */ + $address = $method['args'][0]; - // /** @var string */ - // $address = collect($votes)->firstOrFail(); - - // return new WalletViewModel(Wallets::findByPublicKey($address)); - } - - public function unvoted(): ?WalletViewModel - { - if (! $this->isUnvote()) { + $wallet = Wallet::where('address', $address)->first(); + if ($wallet === null) { return null; } - return null; - - // /** @var array */ - // $votes = Arr::get($this->transaction->asset ?? [], 'unvotes'); - - // /** @var string */ - // $address = collect($votes)->firstOrFail(); - - // return new WalletViewModel(Wallets::findByPublicKey($address)); + return new WalletViewModel($wallet); } } From b16988513cda0e9546d051e3d5f670e60eb3a2a5 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:59:36 +0000 Subject: [PATCH 15/21] add vote address tooltip wrapping --- resources/lang/en/general.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 144c3a8d3..bf12d355e 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -115,8 +115,7 @@ 'block_id' => 'Block ID', 'well-confirmed' => 'Well Confirmed', 'voting_validator' => 'Voting for :validator', - 'vote_validator' => 'Vote: :validator', - 'unvote_validator' => 'Unvote: :validator', + 'vote_validator' => 'Vote::validator', 'types' => [ 'validator-registration' => 'Registration', From 312f2c4716486eea321f757991122f6514be83ed Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:02:18 +0000 Subject: [PATCH 16/21] chore: stanley --- app/Models/Transaction.php | 1 + app/ViewModels/Concerns/Transaction/HasPayload.php | 9 +++++++-- .../Concerns/Transaction/InteractsWithVotes.php | 11 ++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 35dbd6276..fa11bc135 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -39,6 +39,7 @@ * @property string|null $recipient_address * @property string $sender_public_key * @property int $block_height + * @property resource|null $data * @property resource|string|null $vendor_field * @property int $nonce * @property Wallet $sender diff --git a/app/ViewModels/Concerns/Transaction/HasPayload.php b/app/ViewModels/Concerns/Transaction/HasPayload.php index 82dbf3a68..5dbdd5845 100644 --- a/app/ViewModels/Concerns/Transaction/HasPayload.php +++ b/app/ViewModels/Concerns/Transaction/HasPayload.php @@ -18,8 +18,13 @@ public function rawPayload(): ?string return null; } - $payload = bin2hex(stream_get_contents($payload, offset: 0)); - if (is_string($payload) && strlen($payload) === 0) { + $payloadContent = stream_get_contents($payload, offset: 0); + if ($payloadContent === false) { + return null; + } + + $payload = bin2hex($payloadContent); + if (strlen($payload) === 0) { return null; } diff --git a/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php b/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php index 7ab774d62..918b836cc 100644 --- a/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php +++ b/app/ViewModels/Concerns/Transaction/InteractsWithVotes.php @@ -16,7 +16,16 @@ public function voted(): ?WalletViewModel return null; } - $method = (new AbiDecoder())->decodeFunctionData($this->rawPayload()); + $payload = $this->rawPayload(); + if ($payload === null) { + return null; + } + + $method = (new AbiDecoder())->decodeFunctionData($payload); + + if (count($method['args']) === 0) { + return null; + } /** @var string $address */ $address = $method['args'][0]; From b5765fae39b425aa9580a6848e9cb361b509480f Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:04:50 +0000 Subject: [PATCH 17/21] remove vendorfield --- app/Models/Transaction.php | 13 ----- app/Services/VendorField.php | 54 ------------------- .../Transaction/InteractsWithVendorField.php | 13 ----- app/ViewModels/TransactionViewModel.php | 2 - resources/views/app/transaction.blade.php | 4 -- .../transaction/page/memo.blade.php | 18 ------- .../transaction/page/more-details.blade.php | 2 - tests/Unit/Models/TransactionTest.php | 21 -------- tests/Unit/Services/VendorFieldTest.php | 51 ------------------ .../ViewModels/TransactionViewModelTest.php | 28 ---------- 10 files changed, 206 deletions(-) delete mode 100644 app/Services/VendorField.php delete mode 100644 app/ViewModels/Concerns/Transaction/InteractsWithVendorField.php delete mode 100644 resources/views/components/transaction/page/memo.blade.php delete mode 100644 tests/Unit/Services/VendorFieldTest.php diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index fa11bc135..cfc56c540 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -18,7 +18,6 @@ use App\Models\Scopes\ValidatorResignationScope; use App\Models\Scopes\VoteScope; use App\Services\BigNumber; -use App\Services\VendorField; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -40,7 +39,6 @@ * @property string $sender_public_key * @property int $block_height * @property resource|null $data - * @property resource|string|null $vendor_field * @property int $nonce * @property Wallet $sender * @method static \Illuminate\Database\Eloquent\Builder withScope(string $scope) @@ -110,8 +108,6 @@ final class Transaction extends Model 'receipt', ]; - private bool|string|null $vendorFieldContent = false; - /** * Get the indexable data array for the model. * @@ -225,15 +221,6 @@ public function recipient(): Wallet return Wallet::where('address', $vote)->firstOrFail(); } - public function vendorField(): string|null - { - if (is_bool($this->vendorFieldContent)) { - $this->vendorFieldContent = VendorField::parse($this->vendor_field); - } - - return $this->vendorFieldContent; - } - public function fee(): BigNumber { $gasPrice = clone $this->gas_price; diff --git a/app/Services/VendorField.php b/app/Services/VendorField.php deleted file mode 100644 index c19fa1943..000000000 --- a/app/Services/VendorField.php +++ /dev/null @@ -1,54 +0,0 @@ -transaction->vendorField(); - } -} diff --git a/app/ViewModels/TransactionViewModel.php b/app/ViewModels/TransactionViewModel.php index 8879629af..799ff8773 100644 --- a/app/ViewModels/TransactionViewModel.php +++ b/app/ViewModels/TransactionViewModel.php @@ -19,7 +19,6 @@ use App\ViewModels\Concerns\Transaction\InteractsWithMultiPayment; use App\ViewModels\Concerns\Transaction\InteractsWithMultiSignature; use App\ViewModels\Concerns\Transaction\InteractsWithUsernames; -use App\ViewModels\Concerns\Transaction\InteractsWithVendorField; use App\ViewModels\Concerns\Transaction\InteractsWithVotes; use App\ViewModels\Concerns\Transaction\InteractsWithWallets; use ArkEcosystem\Crypto\Utils\UnitConverter; @@ -35,7 +34,6 @@ final class TransactionViewModel implements ViewModel use InteractsWithMultiPayment; use InteractsWithMultiSignature; use InteractsWithUsernames; - use InteractsWithVendorField; use InteractsWithVotes; use InteractsWithWallets; diff --git a/resources/views/app/transaction.blade.php b/resources/views/app/transaction.blade.php index 2694d4988..53ac50801 100644 --- a/resources/views/app/transaction.blade.php +++ b/resources/views/app/transaction.blade.php @@ -15,10 +15,6 @@ - @if ($transaction->isTransfer() || $transaction->isMultiPayment()) - - @endif - @if ($transaction->isMultiPayment()) diff --git a/resources/views/components/transaction/page/memo.blade.php b/resources/views/components/transaction/page/memo.blade.php deleted file mode 100644 index 7b46c7bec..000000000 --- a/resources/views/components/transaction/page/memo.blade.php +++ /dev/null @@ -1,18 +0,0 @@ -@props(['transaction']) - -@php ($vendorField = $transaction->vendorField()) - - - @if (! $vendorField) - - @lang('general.na') - - @else -
- {{ $vendorField }} -
- @endif -
diff --git a/resources/views/components/transaction/page/more-details.blade.php b/resources/views/components/transaction/page/more-details.blade.php index 769f24345..2c691d14d 100644 --- a/resources/views/components/transaction/page/more-details.blade.php +++ b/resources/views/components/transaction/page/more-details.blade.php @@ -1,7 +1,5 @@ @props(['transaction']) -@php ($vendorField = $transaction->vendorField()) -
{{-- Mobile --}} recipient())->toEqual($validator->fresh()); }); -it('should get vendorfield value multiple times despite resource', function () { - $transaction = Transaction::factory()->transfer()->create([ - 'recipient_id' => 'DENGkAwEfRvhhHKZYdEfQ1P3MEoRvPkHYj', - 'fee' => 0.1 * 1e18, // 0.1 - 'amount' => 2 * 1e18, // 2 - 'vendor_field' => '0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0', - ]); - - expect($transaction->vendor_field)->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); - expect($transaction->vendorField())->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); - - $transaction = Transaction::find($transaction->id); - - expect(is_resource($transaction->vendor_field))->toBeTrue(); - expect($transaction->vendorField())->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); - expect($transaction->vendorField())->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); - expect($transaction->vendorField())->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); - expect($transaction->vendorField())->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); - expect($transaction->vendorField())->toBe('0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'); -}); - it('makes transactions searchable', function () { $transaction = Transaction::factory()->create(); diff --git a/tests/Unit/Services/VendorFieldTest.php b/tests/Unit/Services/VendorFieldTest.php deleted file mode 100644 index e9f8072bd..000000000 --- a/tests/Unit/Services/VendorFieldTest.php +++ /dev/null @@ -1,51 +0,0 @@ -toBe($expected); -})->with([ - ['0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0', '3078524b656f495a394b6832673448736c6765487235423979626c48626e77575967666546674f33366e30'], - ['1', '31'], - [21, '3231'], - [null, null], - [1.4, '312e34'], - [true, null], - ['', null], -]); - -it('should convert resource to hex', function () { - $resource = fopen('data:text/plain;base64,'.base64_encode('this is a test stream'), 'rb'); - - expect(VendorField::toHex($resource))->toBe('74686973206973206120746573742073747265616d'); -}); - -it('should parse vendor field value', function ($content, $expected) { - expect(VendorField::parse($content))->toBe($expected); -})->with([ - ['3078524b656f495a394b6832673448736c6765487235423979626c48626e77575967666546674f33366e30', '3078524b656f495a394b6832673448736c6765487235423979626c48626e77575967666546674f33366e30'], - ['31', '31'], - ['3231', '3231'], - [184, '184'], - ['0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0', '0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'], - ['Random vendorfield value', 'Random vendorfield value'], - [null, null], - [1.4, null], - ['1.4', '1.4'], - [true, null], - ['', null], -]); - -it('should parse resource', function ($content, $expected) { - $resource = fopen('data:text/plain;base64,'.base64_encode($content), 'rb'); - - expect(VendorField::parse($resource))->toBe($expected); -})->with([ - ['3078524b656f495a394b6832673448736c6765487235423979626c48626e77575967666546674f33366e30', '3078524b656f495a394b6832673448736c6765487235423979626c48626e77575967666546674f33366e30'], - ['31', '31'], - ['3231', '3231'], - ['0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0', '0xRKeoIZ9Kh2g4HslgeHr5B9yblHbnwWYgfeFgO36n0'], - ['Random vendorfield value', 'Random vendorfield value'], -]); diff --git a/tests/Unit/ViewModels/TransactionViewModelTest.php b/tests/Unit/ViewModels/TransactionViewModelTest.php index f9b70ab51..c25d8c7ea 100644 --- a/tests/Unit/ViewModels/TransactionViewModelTest.php +++ b/tests/Unit/ViewModels/TransactionViewModelTest.php @@ -989,34 +989,6 @@ expect($subject->username())->toBeNull(); }); -it('should get the vendor field', function () { - $transaction = Transaction::factory()->create([]); - - DB::connection('explorer')->update('UPDATE transactions SET vendor_field = ? WHERE id = ?', ['Hello World', $transaction->id]); - - $this->subject = new TransactionViewModel($transaction->fresh()); - - expect($this->subject->vendorField())->toBe('Hello World'); -}); - -it('should fail to get the vendor field if it is empty', function () { - $transaction = Transaction::factory()->create(['vendor_field' => null]); - - $this->subject = new TransactionViewModel($transaction->fresh()); - - expect($this->subject->vendorField())->toBeNull(); -}); - -it('should fail to get the vendor field if it is empty after reading it', function () { - $transaction = Transaction::factory()->create([]); - - DB::connection('explorer')->update('UPDATE transactions SET vendor_field = ? WHERE id = ?', ['', $transaction->id]); - - $this->subject = new TransactionViewModel($transaction->fresh()); - - expect($this->subject->vendorField())->toBeNull(); -}); - it('should get the address of legacy multi signature transactions', function () { $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ 'sender_public_key' => $this->sender->public_key, From dddd3e7a17fb41521f492babbecfe7d725e30462 Mon Sep 17 00:00:00 2001 From: alexbarnsley Date: Thu, 14 Nov 2024 14:06:07 +0000 Subject: [PATCH 18/21] style: resolve style guide violations --- tests/Unit/ViewModels/TransactionViewModelTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/ViewModels/TransactionViewModelTest.php b/tests/Unit/ViewModels/TransactionViewModelTest.php index c25d8c7ea..ab6700334 100644 --- a/tests/Unit/ViewModels/TransactionViewModelTest.php +++ b/tests/Unit/ViewModels/TransactionViewModelTest.php @@ -17,7 +17,6 @@ use ArkEcosystem\Crypto\Identities\Address; use Carbon\Carbon; use Illuminate\Support\Facades\Config; -use Illuminate\Support\Facades\DB; use function Spatie\Snapshots\assertMatchesSnapshot; beforeEach(function () { From d654a94c78019c0691851e3ff249f73456c1a3c1 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:22:22 +0000 Subject: [PATCH 19/21] transaction method test --- .../Transactions/TransactionMethodTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Unit/Services/Transactions/TransactionMethodTest.php diff --git a/tests/Unit/Services/Transactions/TransactionMethodTest.php b/tests/Unit/Services/Transactions/TransactionMethodTest.php new file mode 100644 index 000000000..c7e172bed --- /dev/null +++ b/tests/Unit/Services/Transactions/TransactionMethodTest.php @@ -0,0 +1,35 @@ +{$type}()->create(); + $transactionMethod = new TransactionMethod($transaction); + + expect($transactionMethod->{'is'.ucfirst($type)}())->toBeTrue(); + expect($transactionMethod->name())->toBe($expected); +})->with([ + [ + 'transfer', + 'transfer', + ], + [ + 'validatorRegistration', + 'validator-registration', + ], + [ + 'vote', + 'vote', + ], + [ + 'unvote', + 'unvote', + ], + [ + 'validatorResignation', + 'validator-resignation', + ], +]); From 3f906c76b38d6efe4a00161c6eb768e19d2defb0 Mon Sep 17 00:00:00 2001 From: alexbarnsley Date: Thu, 14 Nov 2024 16:23:51 +0000 Subject: [PATCH 20/21] style: resolve style guide violations --- tests/Unit/Services/Transactions/TransactionMethodTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Services/Transactions/TransactionMethodTest.php b/tests/Unit/Services/Transactions/TransactionMethodTest.php index c7e172bed..116d13be8 100644 --- a/tests/Unit/Services/Transactions/TransactionMethodTest.php +++ b/tests/Unit/Services/Transactions/TransactionMethodTest.php @@ -6,7 +6,7 @@ use App\Services\Transactions\TransactionMethod; it('should determine the type', function (string $type, string $expected) { - $transaction = Transaction::factory()->{$type}()->create(); + $transaction = Transaction::factory()->{$type}()->create(); $transactionMethod = new TransactionMethod($transaction); expect($transactionMethod->{'is'.ucfirst($type)}())->toBeTrue(); From 34029970963a974d3f03e3d8db532a35227ca217 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:33:07 +0000 Subject: [PATCH 21/21] refactor: remove unused transaction types (#1001) --- .../Commands/CacheAnnualStatistics.php | 4 - app/Console/Commands/CacheDevelopmentData.php | 3 +- ...cheUsernames.php => CacheKnownWallets.php} | 18 +- .../Commands/CacheMultiSignatureAddresses.php | 37 - .../Commands/CacheValidatorStatistics.php | 31 - app/Console/Kernel.php | 7 +- app/Console/Playbooks/TransactionPlaybook.php | 4 - app/Contracts/WalletRepository.php | 6 - app/DTO/MemoryWallet.php | 6 +- app/DTO/Payment.php | 14 +- app/Enums/StatsTransactionType.php | 3 - app/Enums/TransactionTypeEnum.php | 24 - app/Facades/Wallets.php | 3 - app/Http/Livewire/Modals/ExportBlocks.php | 6 - .../Livewire/Transaction/RecipientList.php | 63 -- app/Http/Livewire/TransactionTable.php | 18 +- app/Http/Livewire/Validators/MissedBlocks.php | 1 - app/Http/Livewire/Validators/RecentVotes.php | 3 +- app/Http/Livewire/Validators/Validators.php | 1 - app/Http/Livewire/WalletTables.php | 2 - app/Http/Livewire/WalletTransactionTable.php | 6 - app/Jobs/CacheMultiSignatureAddress.php | 34 - .../Concerns/ForgingStats/CanBeSorted.php | 23 - .../Concerns/Transaction/CanBeSorted.php | 19 - app/Models/Concerns/Wallet/CanBeSorted.php | 5 - app/Models/Scopes/ActiveValidatorScope.php | 1 - app/Models/Scopes/MultiPaymentScope.php | 18 - app/Models/Scopes/MultiSignatureScope.php | 18 - app/Models/Scopes/ResignedValidatorScope.php | 1 - app/Models/Scopes/StandbyValidatorScope.php | 1 - app/Models/Scopes/TransferScope.php | 18 - app/Models/Scopes/UnvoteSingleScope.php | 19 - .../Scopes/UsernameRegistrationScope.php | 18 - .../Scopes/UsernameResignationScope.php | 18 - .../Scopes/ValidatorRegistrationScope.php | 18 - .../Scopes/ValidatorResignationScope.php | 18 - app/Models/Scopes/VoteScope.php | 18 - app/Models/Scopes/VoteSingleScope.php | 19 - app/Models/Transaction.php | 25 - app/Models/Wallet.php | 11 - app/Providers/RouteServiceProvider.php | 4 +- app/Repositories/WalletRepository.php | 26 - .../WalletRepositoryWithCache.php | 15 - app/Services/Cache/WalletCache.php | 31 +- app/Services/Forms.php | 4 - app/Services/Search/Traits/ValidatesTerm.php | 19 - app/Services/Search/WalletSearch.php | 10 +- .../Aggregates/Concerns/HasQueries.php | 5 - .../Aggregates/HistoricalAggregateFactory.php | 7 +- .../LargestTransactionAggregate.php | 2 +- .../Aggregates/Type/MultipaymentAggregate.php | 15 - .../Concerns/ManagesTransactionTypes.php | 8 - .../Transactions/TransactionMethod.php | 86 -- .../Concerns/Block/HasValidator.php | 4 +- .../Concerns/Transaction/HasDirection.php | 4 +- .../Concerns/Transaction/HasMethod.php | 41 - .../Transaction/InteractsWithMultiPayment.php | 45 - .../InteractsWithMultiSignature.php | 106 --- .../Transaction/InteractsWithUsernames.php | 15 - .../Concerns/Wallet/CanBeKnownWallet.php | 23 + .../Concerns/Wallet/CanHaveUsername.php | 43 - app/ViewModels/Concerns/Wallet/HasType.php | 19 - app/ViewModels/ForgingStatsViewModel.php | 4 +- app/ViewModels/TransactionViewModel.php | 34 +- app/ViewModels/WalletViewModel.php | 4 +- config/scout.php | 2 +- database/factories/TransactionFactory.php | 92 -- database/factories/WalletFactory.php | 21 - docker/entrypoint.sh | 3 +- resources/icons/second-signature.svg | 1 - resources/js/includes/enums.js | 11 - resources/js/transactions-export.js | 60 +- resources/js/wallet.js | 5 - resources/lang/en/forms.php | 5 - resources/lang/en/general.php | 4 - resources/lang/en/labels.php | 3 - resources/lang/en/pages.php | 17 +- resources/lang/en/tables.php | 22 +- resources/scripts/vote-report.sh | 6 +- resources/views/app/transaction.blade.php | 6 - resources/views/app/wallet.blade.php | 2 +- .../general/encapsulated/vote-type.blade.php | 4 +- .../general/identity-iconless.blade.php | 4 +- .../components/general/identity.blade.php | 48 +- .../page-section/data/validator.blade.php | 20 +- .../results/mobile/transaction-type.blade.php | 2 - .../transaction-types/multi-payment.blade.php | 29 - .../search/results/transaction.blade.php | 6 - .../transaction-recipients.blade.php | 33 - .../insights/desktop/validator-row.blade.php | 2 +- .../insights/mobile/validator-row.blade.php | 2 +- .../skeleton/transaction-recipients.blade.php | 20 - .../tables/desktop/top-accounts.blade.php | 6 +- .../transaction-participants.blade.php | 30 - .../desktop/transaction-recipients.blade.php | 36 - .../filters/transactions-generic.blade.php | 5 - .../tables/filters/transactions.blade.php | 5 - .../mobile/encapsulated/address.blade.php | 6 +- .../skeleton/transaction-recipients.blade.php | 4 - .../tables/mobile/top-accounts.blade.php | 7 - .../mobile/transaction-participants.blade.php | 19 - .../mobile/transaction-recipients.blade.php | 25 - .../tables/mobile/wallet-voters.blade.php | 5 +- .../desktop/encapsulated/address.blade.php | 2 - .../encapsulated/addressing-generic.blade.php | 66 +- .../desktop/encapsulated/addressing.blade.php | 29 +- .../desktop/encapsulated/username.blade.php | 7 - .../desktop/encapsulated/voting.blade.php | 2 +- .../tables/rows/desktop/wallet-type.blade.php | 12 - .../mobile/encapsulated/username.blade.php | 16 - .../mobile/transaction-recipients.blade.php | 16 - .../transaction/page/addressing.blade.php | 10 - .../page/participant-list.blade.php | 11 - .../transaction/page/recipient-list.blade.php | 12 - .../page/section-detail/recipients.blade.php | 5 - .../transaction/page/summary.blade.php | 2 +- .../page/transaction-type.blade.php | 24 +- .../validators/monitor/data-boxes.blade.php | 6 +- .../wallet/overview/wallet.blade.php | 2 +- .../livewire/modals/export-blocks.blade.php | 8 +- .../transaction/recipient-list.blade.php | 18 - .../ShowTransactionControllerTest.php | 3 - .../Controllers/ShowWalletControllerTest.php | 8 +- .../Feature/Http/Livewire/BlockTableTest.php | 1 - .../Feature/Http/Livewire/Home/BlocksTest.php | 1 - .../Http/Livewire/Modals/ExportBlocksTest.php | 4 - .../Http/Livewire/Navbar/SearchTest.php | 21 - .../Feature/Http/Livewire/SearchModalTest.php | 19 - .../Livewire/Stats/CurrentAverageFeeTest.php | 55 +- .../Transaction/RecipientListTest.php | 75 -- .../Http/Livewire/TransactionTableTest.php | 106 +-- .../Http/Livewire/Validators/MonitorTest.php | 8 +- .../Http/Livewire/WalletTablesTest.php | 30 +- .../Livewire/WalletTransactionTableTest.php | 371 ++------ .../Commands/CacheKnownWalletsTest.php | 31 + .../CacheMultiSignatureAddressesTest.php | 20 - .../Console/Commands/CacheUsernamesTest.php | 98 -- tests/Unit/DTO/MemoryWalletTest.php | 8 +- tests/Unit/DTO/PaymentTest.php | 1 - .../Jobs/CacheMultiSignatureAddressTest.php | 33 - .../Models/Scopes/MultiPaymentScopeTest.php | 23 - .../Models/Scopes/MultiSignatureScopeTest.php | 23 - .../Repositories/WalletRepositoryTest.php | 4 - .../WalletRepositoryWithCacheTest.php | 4 - .../Aggregates/LatestWalletAggregateTest.php | 317 ------- tests/Unit/Services/Cache/WalletCacheTest.php | 16 - tests/Unit/Services/FormsTest.php | 4 - .../HistoricalAggregateFactoryTest.php | 2 - .../LargestTransactionAggregateTest.php | 17 - .../Type/MultipaymentAggregateTest.php | 16 - .../Transactions/TransactionTypeTest.php | 78 -- tests/Unit/ViewModels/BlockViewModelTest.php | 12 +- .../ViewModels/ForgingStatsViewModelTest.php | 6 +- .../ViewModels/TransactionViewModelTest.php | 836 +----------------- tests/Unit/ViewModels/WalletViewModelTest.php | 94 +- tests/fixtures/fees.json | 24 - 156 files changed, 316 insertions(+), 4015 deletions(-) rename app/Console/Commands/{CacheUsernames.php => CacheKnownWallets.php} (63%) delete mode 100644 app/Console/Commands/CacheMultiSignatureAddresses.php delete mode 100644 app/Enums/TransactionTypeEnum.php delete mode 100644 app/Http/Livewire/Transaction/RecipientList.php delete mode 100644 app/Jobs/CacheMultiSignatureAddress.php delete mode 100644 app/Models/Scopes/MultiPaymentScope.php delete mode 100644 app/Models/Scopes/MultiSignatureScope.php delete mode 100644 app/Models/Scopes/TransferScope.php delete mode 100644 app/Models/Scopes/UnvoteSingleScope.php delete mode 100644 app/Models/Scopes/UsernameRegistrationScope.php delete mode 100644 app/Models/Scopes/UsernameResignationScope.php delete mode 100644 app/Models/Scopes/ValidatorRegistrationScope.php delete mode 100644 app/Models/Scopes/ValidatorResignationScope.php delete mode 100644 app/Models/Scopes/VoteScope.php delete mode 100644 app/Models/Scopes/VoteSingleScope.php delete mode 100644 app/Services/Transactions/Aggregates/Type/MultipaymentAggregate.php delete mode 100644 app/ViewModels/Concerns/Transaction/InteractsWithMultiPayment.php delete mode 100644 app/ViewModels/Concerns/Transaction/InteractsWithMultiSignature.php delete mode 100644 app/ViewModels/Concerns/Transaction/InteractsWithUsernames.php create mode 100644 app/ViewModels/Concerns/Wallet/CanBeKnownWallet.php delete mode 100644 app/ViewModels/Concerns/Wallet/CanHaveUsername.php delete mode 100644 resources/icons/second-signature.svg delete mode 100644 resources/views/components/search/results/transaction-types/multi-payment.blade.php delete mode 100644 resources/views/components/skeletons/transaction-recipients.blade.php delete mode 100644 resources/views/components/tables/desktop/skeleton/transaction-recipients.blade.php delete mode 100644 resources/views/components/tables/desktop/transaction-participants.blade.php delete mode 100644 resources/views/components/tables/desktop/transaction-recipients.blade.php delete mode 100644 resources/views/components/tables/mobile/skeleton/transaction-recipients.blade.php delete mode 100644 resources/views/components/tables/mobile/transaction-participants.blade.php delete mode 100644 resources/views/components/tables/mobile/transaction-recipients.blade.php delete mode 100644 resources/views/components/tables/rows/desktop/encapsulated/username.blade.php delete mode 100644 resources/views/components/tables/rows/mobile/encapsulated/username.blade.php delete mode 100644 resources/views/components/tables/skeletons/encapsulated/mobile/transaction-recipients.blade.php delete mode 100644 resources/views/components/transaction/page/participant-list.blade.php delete mode 100644 resources/views/components/transaction/page/recipient-list.blade.php delete mode 100644 resources/views/components/transaction/page/section-detail/recipients.blade.php delete mode 100644 resources/views/livewire/transaction/recipient-list.blade.php delete mode 100644 tests/Feature/Http/Livewire/Transaction/RecipientListTest.php create mode 100644 tests/Unit/Console/Commands/CacheKnownWalletsTest.php delete mode 100644 tests/Unit/Console/Commands/CacheMultiSignatureAddressesTest.php delete mode 100644 tests/Unit/Console/Commands/CacheUsernamesTest.php delete mode 100644 tests/Unit/Jobs/CacheMultiSignatureAddressTest.php delete mode 100644 tests/Unit/Models/Scopes/MultiPaymentScopeTest.php delete mode 100644 tests/Unit/Models/Scopes/MultiSignatureScopeTest.php delete mode 100644 tests/Unit/Services/Transactions/Aggregates/Type/MultipaymentAggregateTest.php delete mode 100644 tests/Unit/Services/Transactions/TransactionTypeTest.php diff --git a/app/Console/Commands/CacheAnnualStatistics.php b/app/Console/Commands/CacheAnnualStatistics.php index 4d7935e0c..15ac4df93 100644 --- a/app/Console/Commands/CacheAnnualStatistics.php +++ b/app/Console/Commands/CacheAnnualStatistics.php @@ -66,8 +66,6 @@ private function cacheAllYears(StatisticsCache $cache): void ->orderBy('year') ->get(); - // TODO: handle multipayment transactions - $blocksData = DB::connection('explorer') ->query() ->select([ @@ -119,8 +117,6 @@ private function cacheCurrentYear(StatisticsCache $cache): void ->where('timestamp', '>=', $startOfYear) ->first(); - // TODO: handle multipayment transactions - $blocksData = DB::connection('explorer') ->query() ->from('blocks') diff --git a/app/Console/Commands/CacheDevelopmentData.php b/app/Console/Commands/CacheDevelopmentData.php index 43fcc829f..cd0e24df3 100644 --- a/app/Console/Commands/CacheDevelopmentData.php +++ b/app/Console/Commands/CacheDevelopmentData.php @@ -36,11 +36,10 @@ public function handle(): void 'explorer:cache-validator-performance', 'explorer:cache-validator-productivity', 'explorer:cache-validator-resignation-ids', - 'explorer:cache-usernames', + 'explorer:cache-known-wallets', 'explorer:cache-validator-wallets', 'explorer:cache-validators-with-voters', 'explorer:cache-validator-voter-counts', - 'explorer:cache-multi-signature-addresses', 'explorer:cache-blocks', 'explorer:cache-transactions', 'explorer:cache-address-statistics', diff --git a/app/Console/Commands/CacheUsernames.php b/app/Console/Commands/CacheKnownWallets.php similarity index 63% rename from app/Console/Commands/CacheUsernames.php rename to app/Console/Commands/CacheKnownWallets.php index 1eb6e0a38..ef7096199 100644 --- a/app/Console/Commands/CacheUsernames.php +++ b/app/Console/Commands/CacheKnownWallets.php @@ -5,27 +5,26 @@ namespace App\Console\Commands; use App\Facades\Network; -use App\Facades\Wallets; use App\Models\Wallet; use App\Services\Cache\WalletCache; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Model; -final class CacheUsernames extends Command +final class CacheKnownWallets extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'explorer:cache-usernames'; + protected $signature = 'explorer:cache-known-wallets'; /** * The console command description. * * @var string|null */ - protected $description = 'Cache all usernames by their address and public key.'; + protected $description = 'Cache all known wallets by their address.'; public function handle(): void { @@ -33,11 +32,9 @@ public function handle(): void $knownWallets = collect(Network::knownWallets()); - Wallets::allWithUsername() - ->orWhereIn('address', $knownWallets->pluck('address')) + Wallet::whereIn('address', $knownWallets->pluck('address')) ->select([ 'address', - 'public_key', 'attributes', ]) ->get() @@ -45,17 +42,14 @@ public function handle(): void /** @var Wallet $wallet */ $knownWallet = $knownWallets->firstWhere('address', $wallet->address); + $username = null; if (! is_null($knownWallet)) { $username = $knownWallet['name']; - } else { - $username = $wallet->username(); } if (! is_null($username)) { - $cache->setUsernameByAddress($wallet->address, $username); + $cache->setWalletNameByAddress($wallet->address, $username); } }); - - // TODO: re-add username resignation scope to forget usernames which have resigned - https://app.clickup.com/t/86duvqbd4 } } diff --git a/app/Console/Commands/CacheMultiSignatureAddresses.php b/app/Console/Commands/CacheMultiSignatureAddresses.php deleted file mode 100644 index 221503592..000000000 --- a/app/Console/Commands/CacheMultiSignatureAddresses.php +++ /dev/null @@ -1,37 +0,0 @@ -cursor() - ->each(function ($wallet) { - /** @var Wallet $wallet */ - CacheMultiSignatureAddress::dispatch($wallet->toArray())->onQueue('musig'); - }); - } -} diff --git a/app/Console/Commands/CacheValidatorStatistics.php b/app/Console/Commands/CacheValidatorStatistics.php index b001a7407..cef9b5036 100644 --- a/app/Console/Commands/CacheValidatorStatistics.php +++ b/app/Console/Commands/CacheValidatorStatistics.php @@ -4,10 +4,7 @@ namespace App\Console\Commands; -use App\Enums\TransactionTypeEnum; -use App\Facades\Rounds; use App\Models\Block; -use App\Models\Transaction; use App\Services\Cache\StatisticsCache; use App\Services\Cache\WalletCache; use App\Services\Wallets\Aggregates\UniqueVotersAggregate; @@ -46,34 +43,6 @@ public function handle(StatisticsCache $cache, WalletCache $walletCache): void $walletCache->setVoterCount($leastVotedValidator['address'], $leastVotedValidator['voter_count']); } - $activeValidators = Rounds::current()->validators; - - $newestActiveValidatorTx = Transaction::where('type', '=', TransactionTypeEnum::VALIDATOR_REGISTRATION) - ->whereIn('sender_public_key', $activeValidators) - ->orderBy('timestamp', 'desc') - ->limit(1) - ->first(); - - if ($newestActiveValidatorTx !== null) { - $cache->setNewestActiveValidator( - $newestActiveValidatorTx->sender_public_key, - $newestActiveValidatorTx->timestamp - ); - } - - $oldestActiveValidatorTx = Transaction::where('type', '=', TransactionTypeEnum::VALIDATOR_REGISTRATION) - ->whereIn('sender_public_key', $activeValidators) - ->orderBy('timestamp', 'asc') - ->limit(1) - ->first(); - - if ($oldestActiveValidatorTx !== null) { - $cache->setOldestActiveValidator( - $oldestActiveValidatorTx->sender_public_key, - $oldestActiveValidatorTx->timestamp - ); - } - $mostBlocksForged = Block::select(DB::raw('COUNT(*), generator_address')) ->groupBy('generator_address') ->orderBy('count', 'desc') diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e0eddfe39..91d7f8a78 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -9,12 +9,11 @@ use App\Console\Commands\CacheAnnualStatistics; use App\Console\Commands\CacheCurrenciesData; use App\Console\Commands\CacheFees; +use App\Console\Commands\CacheKnownWallets; use App\Console\Commands\CacheMarketDataStatistics; -use App\Console\Commands\CacheMultiSignatureAddresses; use App\Console\Commands\CacheNetworkAggregates; use App\Console\Commands\CachePrices; use App\Console\Commands\CacheTransactions; -use App\Console\Commands\CacheUsernames; use App\Console\Commands\CacheValidatorAggregates; use App\Console\Commands\CacheValidatorPerformance; use App\Console\Commands\CacheValidatorProductivity; @@ -66,9 +65,7 @@ protected function schedule(Schedule $schedule) $schedule->command(CacheFees::class)->everyFiveMinutes(); - $schedule->command(CacheUsernames::class)->everyMinute(); - - $schedule->command(CacheMultiSignatureAddresses::class)->everyMinute(); + $schedule->command(CacheKnownWallets::class)->everyMinute(); $schedule->command(CacheValidatorsWithVoters::class)->everyMinute(); diff --git a/app/Console/Playbooks/TransactionPlaybook.php b/app/Console/Playbooks/TransactionPlaybook.php index 59751f7ab..cc15f2d3c 100644 --- a/app/Console/Playbooks/TransactionPlaybook.php +++ b/app/Console/Playbooks/TransactionPlaybook.php @@ -24,10 +24,6 @@ public function run(InputInterface $input, OutputInterface $output): void Transaction::factory(10)->vote()->create(); - Transaction::factory(10)->multiSignature()->create(); - - Transaction::factory(10)->multiPayment()->create(); - Transaction::factory(10)->validatorResignation()->create(); foreach (range(1, 365) as $day) { diff --git a/app/Contracts/WalletRepository.php b/app/Contracts/WalletRepository.php index 4b9373bb6..2025f774a 100644 --- a/app/Contracts/WalletRepository.php +++ b/app/Contracts/WalletRepository.php @@ -10,23 +10,17 @@ interface WalletRepository { - public function allWithUsername(): Builder; - public function allWithValidatorPublicKey(): Builder; public function allWithVote(): Builder; public function allWithPublicKey(): Builder; - public function allWithMultiSignature(): Builder; - public function findByAddress(string $address): Wallet; public function findByPublicKey(string $publicKey): Wallet; public function findByPublicKeys(array $publicKey): Collection; - public function findByUsername(string $username, bool $caseSensitive = true): Wallet; - public function findByIdentifier(string $identifier): Wallet; } diff --git a/app/DTO/MemoryWallet.php b/app/DTO/MemoryWallet.php index dbe461081..eb3a2fa5a 100644 --- a/app/DTO/MemoryWallet.php +++ b/app/DTO/MemoryWallet.php @@ -35,12 +35,12 @@ public function publicKey(): ?string public function hasUsername(): bool { - return $this->username() !== null; + return $this->walletName() !== null; } - public function username(): ?string + public function walletName(): ?string { - return (new WalletCache())->getUsernameByAddress($this->address); + return (new WalletCache())->getWalletNameByAddress($this->address); } public function isValidator(): bool diff --git a/app/DTO/Payment.php b/app/DTO/Payment.php index 3972b8c65..294c5eaea 100644 --- a/app/DTO/Payment.php +++ b/app/DTO/Payment.php @@ -4,9 +4,7 @@ namespace App\DTO; -use App\Facades\Wallets; use App\Services\ExchangeRate; -use Illuminate\Support\Arr; final class Payment { @@ -14,13 +12,10 @@ final class Payment private string $address; - private ?string $username = null; - public function __construct(private int $timestamp, array $payment) { - $this->amount = $payment['amount'] / config('currencies.notation.crypto', 1e18); - $this->address = $payment['recipientId']; - $this->username = Arr::get(Wallets::findByAddress($payment['recipientId']), 'attributes.username'); + $this->amount = $payment['amount'] / config('currencies.notation.crypto', 1e18); + $this->address = $payment['recipientId']; } public function amount(): float @@ -38,11 +33,6 @@ public function address(): string return $this->address; } - public function username(): ?string - { - return $this->username; - } - public function recipient(): self { return $this; diff --git a/app/Enums/StatsTransactionType.php b/app/Enums/StatsTransactionType.php index 28647899b..c3fadac37 100644 --- a/app/Enums/StatsTransactionType.php +++ b/app/Enums/StatsTransactionType.php @@ -10,8 +10,6 @@ enum StatsTransactionType { public const TRANSFER = 'transfer'; - public const MULTIPAYMENT = 'multipayment'; - public const VOTE = 'vote'; public const UNVOTE = 'unvote'; @@ -24,7 +22,6 @@ public static function all(): Collection { return new Collection([ self::TRANSFER, - self::MULTIPAYMENT, self::VOTE, self::UNVOTE, self::VALIDATOR_REGISTRATION, diff --git a/app/Enums/TransactionTypeEnum.php b/app/Enums/TransactionTypeEnum.php deleted file mode 100644 index 5fc4a5f1d..000000000 --- a/app/Enums/TransactionTypeEnum.php +++ /dev/null @@ -1,24 +0,0 @@ -publicKey(); $this->publicKey = $publicKey; - - if ($wallet->hasUsername()) { - $this->username = $wallet->username(); - } } public function render(): View diff --git a/app/Http/Livewire/Transaction/RecipientList.php b/app/Http/Livewire/Transaction/RecipientList.php deleted file mode 100644 index e7367c10b..000000000 --- a/app/Http/Livewire/Transaction/RecipientList.php +++ /dev/null @@ -1,63 +0,0 @@ - '$refresh', - ]; - - public function mount(string $transactionId): void - { - $this->transactionId = $transactionId; - } - - public function render(): View - { - return view('livewire.transaction.recipient-list', [ - 'recipients' => $this->recipients, - ]); - } - - public function getRecipientsProperty(): LengthAwarePaginator - { - if (! $this->isReady) { - return new LengthAwarePaginator([], 0, $this->perPage); - } - - $recipients = new Collection( - (new TransactionViewModel(Transaction::findOrFail($this->transactionId))) - ->payments(true) - ); - - $totalCount = $recipients->count(); - - $items = $recipients->chunk($this->perPage) - ->get($this->getPage() - 1); - - return new LengthAwarePaginator($items, $totalCount, $this->perPage, $this->getPage(), [ - 'pageName' => 'page', - ]); - } -} diff --git a/app/Http/Livewire/TransactionTable.php b/app/Http/Livewire/TransactionTable.php index a25b3652d..62d02a9fb 100644 --- a/app/Http/Livewire/TransactionTable.php +++ b/app/Http/Livewire/TransactionTable.php @@ -25,10 +25,9 @@ final class TransactionTable extends Component use HasTablePagination; public array $filter = [ - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]; /** @var mixed */ @@ -40,10 +39,9 @@ final class TransactionTable extends Component public function queryString(): array { return [ - 'transfers' => ['except' => true], - 'votes' => ['except' => true], - 'multipayments' => ['except' => true], - 'others' => ['except' => true], + 'transfers' => ['except' => true], + 'votes' => ['except' => true], + 'others' => ['except' => true], ]; } @@ -92,10 +90,6 @@ private function hasTransactionTypeFilters(): bool return true; } - if ($this->filter['multipayments'] === true) { - return true; - } - return $this->filter['others'] === true; } } diff --git a/app/Http/Livewire/Validators/MissedBlocks.php b/app/Http/Livewire/Validators/MissedBlocks.php index 36f40c3cc..8b44b76c6 100644 --- a/app/Http/Livewire/Validators/MissedBlocks.php +++ b/app/Http/Livewire/Validators/MissedBlocks.php @@ -77,7 +77,6 @@ private function getMissedBlocksQuery(): Builder return ForgingStats::query() ->when($this->sortKey === 'height', fn ($query) => $query->sortByHeight($sortDirection)) ->when($this->sortKey === 'age', fn ($query) => $query->sortByAge($sortDirection)) - ->when($this->sortKey === 'name', fn ($query) => $query->sortByUsername($sortDirection)) ->when($this->sortKey === 'votes' || $this->sortKey === 'percentage_votes', fn ($query) => $query->sortByVoteCount($sortDirection)) ->when($this->sortKey === 'no_of_voters', fn ($query) => $query->sortByNumberOfVoters($sortDirection)) ->whereNotNull('missed_height'); diff --git a/app/Http/Livewire/Validators/RecentVotes.php b/app/Http/Livewire/Validators/RecentVotes.php index 6489eb896..2a746e3e4 100644 --- a/app/Http/Livewire/Validators/RecentVotes.php +++ b/app/Http/Livewire/Validators/RecentVotes.php @@ -119,7 +119,6 @@ private function getRecentVotesQuery(): Builder }) ->when($this->sortKey === 'age', fn ($query) => $query->sortByAge($sortDirection)) ->when($this->sortKey === 'address', fn ($query) => $query->sortByAddress($sortDirection)) - ->when($this->sortKey === 'type', fn ($query) => $query->sortByType($sortDirection)) - ->when($this->sortKey === 'name', fn ($query) => $query->sortByUsername($sortDirection)); + ->when($this->sortKey === 'type', fn ($query) => $query->sortByType($sortDirection)); } } diff --git a/app/Http/Livewire/Validators/Validators.php b/app/Http/Livewire/Validators/Validators.php index 77a5c019a..a7fe26c7a 100644 --- a/app/Http/Livewire/Validators/Validators.php +++ b/app/Http/Livewire/Validators/Validators.php @@ -135,7 +135,6 @@ private function getValidatorsQuery(): Builder ->orWhere(fn ($query) => $query->when($this->filter['resigned'] === true, fn ($query) => $query->where('attributes->validatorResigned', true))); })) ->when($this->sortKey === 'rank', fn ($query) => $query->sortByRank($sortDirection)) - ->when($this->sortKey === 'name', fn ($query) => $query->sortByUsername($sortDirection)) ->when($this->sortKey === 'votes' || $this->sortKey === 'percentage_votes', fn ($query) => $query->sortByVoteCount($sortDirection)) ->when($this->sortKey === 'no_of_voters', fn ($query) => $query->sortByNumberOfVoters($sortDirection)) ->when($this->sortKey === 'missed_blocks', fn ($query) => $query->sortByMissedBlocks($sortDirection)); diff --git a/app/Http/Livewire/WalletTables.php b/app/Http/Livewire/WalletTables.php index de435b110..0540651b2 100644 --- a/app/Http/Livewire/WalletTables.php +++ b/app/Http/Livewire/WalletTables.php @@ -55,7 +55,6 @@ public function queryString(): array 'incoming' => ['except' => true, 'history' => true], 'transfers' => ['except' => true, 'history' => true], 'votes' => ['except' => true, 'history' => true], - 'multipayments' => ['except' => true, 'history' => true], 'others' => ['except' => true, 'history' => true], ]; } @@ -72,7 +71,6 @@ public function mount(WalletViewModel $wallet): void 'incoming' => true, 'transfers' => true, 'votes' => true, - 'multipayments' => true, 'others' => true, 'paginators' => [ diff --git a/app/Http/Livewire/WalletTransactionTable.php b/app/Http/Livewire/WalletTransactionTable.php index f2b7f95ce..ff89698ac 100644 --- a/app/Http/Livewire/WalletTransactionTable.php +++ b/app/Http/Livewire/WalletTransactionTable.php @@ -32,7 +32,6 @@ final class WalletTransactionTable extends TabbedTableComponent 'incoming' => true, 'transfers' => true, 'votes' => true, - 'multipayments' => true, 'others' => true, ]; @@ -50,7 +49,6 @@ public function queryString(): array 'filter.incoming' => ['as' => 'incoming', 'except' => true], 'filter.transfers' => ['as' => 'transfers', 'except' => true], 'filter.votes' => ['as' => 'votes', 'except' => true], - 'filter.multipayments' => ['as' => 'multipayments', 'except' => true], 'filter.others' => ['as' => 'others', 'except' => true], ]; } @@ -129,10 +127,6 @@ private function hasTransactionTypeFilters(): bool return true; } - if ($this->filter['multipayments'] === true) { - return true; - } - return $this->filter['others'] === true; } diff --git a/app/Jobs/CacheMultiSignatureAddress.php b/app/Jobs/CacheMultiSignatureAddress.php deleted file mode 100644 index bcd4b1bb6..000000000 --- a/app/Jobs/CacheMultiSignatureAddress.php +++ /dev/null @@ -1,34 +0,0 @@ -wallet, 'attributes.multiSignature.min', 0); - $publicKeys = Arr::get($this->wallet, 'attributes.multiSignature.publicKeys', []); - - (new WalletCache())->setMultiSignatureAddress($min, $publicKeys, fn () => Address::fromMultiSignatureAsset($min, $publicKeys)); - } -} diff --git a/app/Models/Concerns/ForgingStats/CanBeSorted.php b/app/Models/Concerns/ForgingStats/CanBeSorted.php index 50d5bd217..b952b8832 100644 --- a/app/Models/Concerns/ForgingStats/CanBeSorted.php +++ b/app/Models/Concerns/ForgingStats/CanBeSorted.php @@ -23,29 +23,6 @@ public function scopeSortByAge(mixed $query, SortDirection $sortDirection): Buil return $query->orderByRaw('timestamp '.$sortDirection->value); } - public function scopeSortByUsername(mixed $query, SortDirection $sortDirection): Builder - { - $missedBlockPublicKeys = ForgingStats::groupBy('address')->pluck('address'); - - $validatorNames = Wallet::whereIn('address', $missedBlockPublicKeys) - ->get() - ->pluck('attributes.username', 'address'); - - if (count($validatorNames) === 0) { - return $query->selectRaw('NULL AS validator_name') - ->selectRaw('forging_stats.*'); - } - - return $query->selectRaw('wallets.name AS validator_name') - ->selectRaw('forging_stats.*') - ->join(DB::raw(sprintf( - '(values %s) as wallets (address, name)', - $validatorNames->map(fn ($name, $publicKey) => sprintf('(\'%s\',\'%s\')', $publicKey, $name)) - ->join(','), - )), 'forging_stats.address', '=', 'wallets.address', 'left outer') - ->orderByRaw('validator_name '.$sortDirection->value.', timestamp DESC'); - } - public function scopeSortByVoteCount(mixed $query, SortDirection $sortDirection): Builder { $missedBlockAddresses = ForgingStats::groupBy('address')->pluck('address'); diff --git a/app/Models/Concerns/Transaction/CanBeSorted.php b/app/Models/Concerns/Transaction/CanBeSorted.php index 51884b55a..15c4d7536 100644 --- a/app/Models/Concerns/Transaction/CanBeSorted.php +++ b/app/Models/Concerns/Transaction/CanBeSorted.php @@ -6,7 +6,6 @@ use App\Enums\SortDirection; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Support\Facades\DB; trait CanBeSorted { @@ -37,22 +36,4 @@ public function scopeSortByType(mixed $query, SortDirection $sortDirection): Bui ->selectRaw('transactions.*') ->orderBy('transaction_type', $sortDirection->value); } - - public function scopeSortByUsername(mixed $query, SortDirection $sortDirection): Builder - { - return $query->select([ - 'validator_name' => fn ($query) => $query - ->selectRaw('wallets.attributes->\'username\'') - ->from(function ($query) { - $query - ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'-\') IS null) then substring(asset->\'votes\'->>0, 2) end as unvote') - ->selectRaw('case when (NULLIF(LEFT(asset->\'votes\'->>0, 1), \'+\') IS null) then substring(asset->\'votes\'->>0, 2) end as vote') - ->whereColumn('transactions.id', 'validator_transaction.id') - ->from('transactions', 'validator_transaction'); - }, 'validator_vote') - ->join('wallets', 'wallets.public_key', '=', DB::raw('coalesce(validator_vote.vote, validator_vote.unvote)')), - ]) - ->selectRaw('transactions.*') - ->orderBy('validator_name', $sortDirection->value); - } } diff --git a/app/Models/Concerns/Wallet/CanBeSorted.php b/app/Models/Concerns/Wallet/CanBeSorted.php index cba954147..aa0aba943 100644 --- a/app/Models/Concerns/Wallet/CanBeSorted.php +++ b/app/Models/Concerns/Wallet/CanBeSorted.php @@ -13,11 +13,6 @@ trait CanBeSorted { - public function scopeSortByUsername(mixed $query, SortDirection $sortDirection): Builder - { - return $query->orderByRaw("(\"attributes\"->>'username')::text ".$sortDirection->value.', ("attributes"->>\'validatorRank\')::numeric ASC'); - } - public function scopeSortByRank(mixed $query, SortDirection $sortDirection): Builder { return $query->orderByRaw("(\"attributes\"->>'validatorRank')::numeric ".$sortDirection->value); diff --git a/app/Models/Scopes/ActiveValidatorScope.php b/app/Models/Scopes/ActiveValidatorScope.php index 526f6ae03..6f7fb5446 100644 --- a/app/Models/Scopes/ActiveValidatorScope.php +++ b/app/Models/Scopes/ActiveValidatorScope.php @@ -13,7 +13,6 @@ final class ActiveValidatorScope implements Scope { public function apply(Builder $builder, Model $model) { - $builder->whereNotNull('attributes->validator->username'); $builder->whereRaw("(\"attributes\"->'validator'->>'rank')::numeric <= ?", [Network::validatorCount()]); $builder->orderByRaw("(\"attributes\"->'validator'->>'rank')::numeric ASC"); } diff --git a/app/Models/Scopes/MultiPaymentScope.php b/app/Models/Scopes/MultiPaymentScope.php deleted file mode 100644 index 51084cae0..000000000 --- a/app/Models/Scopes/MultiPaymentScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::MULTI_PAYMENT); - } -} diff --git a/app/Models/Scopes/MultiSignatureScope.php b/app/Models/Scopes/MultiSignatureScope.php deleted file mode 100644 index 92288ad74..000000000 --- a/app/Models/Scopes/MultiSignatureScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::MULTI_SIGNATURE); - } -} diff --git a/app/Models/Scopes/ResignedValidatorScope.php b/app/Models/Scopes/ResignedValidatorScope.php index 1af1bc050..3c76220a0 100644 --- a/app/Models/Scopes/ResignedValidatorScope.php +++ b/app/Models/Scopes/ResignedValidatorScope.php @@ -12,7 +12,6 @@ final class ResignedValidatorScope implements Scope { public function apply(Builder $builder, Model $model) { - $builder->whereNotNull('attributes->validator->username'); $builder->where('attributes->validator->resigned', true); } } diff --git a/app/Models/Scopes/StandbyValidatorScope.php b/app/Models/Scopes/StandbyValidatorScope.php index 8ed302c34..ce490aa98 100644 --- a/app/Models/Scopes/StandbyValidatorScope.php +++ b/app/Models/Scopes/StandbyValidatorScope.php @@ -13,7 +13,6 @@ final class StandbyValidatorScope implements Scope { public function apply(Builder $builder, Model $model) { - $builder->whereNotNull('attributes->validator->username'); $builder->whereRaw("(\"attributes\"->'validator'->>'rank')::numeric > ?", [Network::validatorCount()]); $builder->orderByRaw("(\"attributes\"->'validator'->>'rank')::numeric ASC"); } diff --git a/app/Models/Scopes/TransferScope.php b/app/Models/Scopes/TransferScope.php deleted file mode 100644 index 167e37e97..000000000 --- a/app/Models/Scopes/TransferScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::TRANSFER); - } -} diff --git a/app/Models/Scopes/UnvoteSingleScope.php b/app/Models/Scopes/UnvoteSingleScope.php deleted file mode 100644 index 76db34f0f..000000000 --- a/app/Models/Scopes/UnvoteSingleScope.php +++ /dev/null @@ -1,19 +0,0 @@ -withScope(VoteScope::class) - ->whereJsonLength('asset->votes', 0) - ->whereJsonLength('asset->unvotes', 1); - } -} diff --git a/app/Models/Scopes/UsernameRegistrationScope.php b/app/Models/Scopes/UsernameRegistrationScope.php deleted file mode 100644 index fd18c5df1..000000000 --- a/app/Models/Scopes/UsernameRegistrationScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::USERNAME_REGISTRATION); - } -} diff --git a/app/Models/Scopes/UsernameResignationScope.php b/app/Models/Scopes/UsernameResignationScope.php deleted file mode 100644 index eff78eda9..000000000 --- a/app/Models/Scopes/UsernameResignationScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::USERNAME_RESIGNATION); - } -} diff --git a/app/Models/Scopes/ValidatorRegistrationScope.php b/app/Models/Scopes/ValidatorRegistrationScope.php deleted file mode 100644 index 053d2e38e..000000000 --- a/app/Models/Scopes/ValidatorRegistrationScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::VALIDATOR_REGISTRATION); - } -} diff --git a/app/Models/Scopes/ValidatorResignationScope.php b/app/Models/Scopes/ValidatorResignationScope.php deleted file mode 100644 index 821c3413a..000000000 --- a/app/Models/Scopes/ValidatorResignationScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::VALIDATOR_RESIGNATION); - } -} diff --git a/app/Models/Scopes/VoteScope.php b/app/Models/Scopes/VoteScope.php deleted file mode 100644 index 370c7f18d..000000000 --- a/app/Models/Scopes/VoteScope.php +++ /dev/null @@ -1,18 +0,0 @@ -where('type', TransactionTypeEnum::VOTE); - } -} diff --git a/app/Models/Scopes/VoteSingleScope.php b/app/Models/Scopes/VoteSingleScope.php deleted file mode 100644 index 911ffdeb7..000000000 --- a/app/Models/Scopes/VoteSingleScope.php +++ /dev/null @@ -1,19 +0,0 @@ -withScope(VoteScope::class) - ->whereJsonLength('asset->votes', 1) - ->whereJsonLength('asset->unvotes', 0); - } -} diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index cfc56c540..eed3ee17e 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -9,14 +9,6 @@ use App\Models\Concerns\HasEmptyScope; use App\Models\Concerns\SearchesCaseInsensitive; use App\Models\Concerns\Transaction\CanBeSorted; -use App\Models\Scopes\MultiPaymentScope; -use App\Models\Scopes\MultiSignatureScope; -use App\Models\Scopes\TransferScope; -use App\Models\Scopes\UsernameRegistrationScope; -use App\Models\Scopes\UsernameResignationScope; -use App\Models\Scopes\ValidatorRegistrationScope; -use App\Models\Scopes\ValidatorResignationScope; -use App\Models\Scopes\VoteScope; use App\Services\BigNumber; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -51,23 +43,6 @@ final class Transaction extends Model use HasEmptyScope; use Searchable; - /** - * A list of transaction scopes used for filtering based on type. - * - * Exposed through the model to keep its usage consistent across - * all places that need to filter transactions by their type. - */ - public const TYPE_SCOPES = [ - 'validatorRegistration' => ValidatorRegistrationScope::class, - 'validatorResignation' => ValidatorResignationScope::class, - 'multiPayment' => MultiPaymentScope::class, - 'multiSignature' => MultiSignatureScope::class, - 'usernameRegistration' => UsernameRegistrationScope::class, - 'usernameResignation' => UsernameResignationScope::class, - 'transfer' => TransferScope::class, - 'vote' => VoteScope::class, - ]; - /** * The "type" of the primary key ID. * diff --git a/app/Models/Wallet.php b/app/Models/Wallet.php index a6f207dad..79cd2478a 100644 --- a/app/Models/Wallet.php +++ b/app/Models/Wallet.php @@ -13,7 +13,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; use Laravel\Scout\Searchable; @@ -24,7 +23,6 @@ * @property BigNumber $nonce * @property array $attributes * @property int $updated_at - * @property string $validator_username (only available when indexed by scout) * @property string $timestamp (only available when indexed by scout) * @property int $missed_blocks (only available when sorting validators by missed blocks) * @method static \Illuminate\Database\Eloquent\Builder withScope(string $scope) @@ -76,13 +74,6 @@ final class Wallet extends Model 'attributes' => 'array', ]; - public function username(): ?string - { - $attributes = json_decode($this->attributes['attributes'], true); - - return Arr::get($attributes, 'username', null); - } - /** * Get the value used to index the model. */ @@ -108,7 +99,6 @@ public function toSearchableArray(): array { return [ 'address' => $this->address, - 'username' => $this->username(), 'balance' => $this->balance->__toString(), 'timestamp' => $this->timestamp, ]; @@ -123,7 +113,6 @@ public static function getSearchableQuery(): Builder return $self->newQuery() ->select([ - DB::raw("wallets.attributes->>'username' AS validator_username"), 'wallets.address', 'wallets.attributes', 'wallets.balance', diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 61c86bc3a..4cdadc041 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -54,9 +54,7 @@ public function boot() } try { - return strlen($walletID) === Constants::ADDRESS_LENGTH - ? Wallets::findByAddress($walletID) - : Wallets::findByUsername($walletID); + return Wallets::findByAddress($walletID); } catch (Throwable) { throw (new WalletNotFoundException())->setModel(Wallet::class, [$walletID]); } diff --git a/app/Repositories/WalletRepository.php b/app/Repositories/WalletRepository.php index 711edf971..a40a23b6a 100644 --- a/app/Repositories/WalletRepository.php +++ b/app/Repositories/WalletRepository.php @@ -9,17 +9,11 @@ use App\Services\Search\Traits\ValidatesTerm; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; final class WalletRepository implements Contract { use ValidatesTerm; - public function allWithUsername(): Builder - { - return Wallet::whereNotNull('wallets.attributes->username'); - } - public function allWithValidatorPublicKey(): Builder { return Wallet::whereNotNull('wallets.attributes->validatorPublicKey'); @@ -35,11 +29,6 @@ public function allWithPublicKey(): Builder return Wallet::whereNotNull('public_key'); } - public function allWithMultiSignature(): Builder - { - return Wallet::whereNotNull('attributes->multiSignature'); - } - public function findByAddress(string $address): Wallet { return Wallet::where('address', $address)->firstOrFail(); @@ -55,18 +44,6 @@ public function findByPublicKeys(array $publicKeys): Collection return Wallet::whereIn('public_key', $publicKeys)->get(); } - public function findByUsername(string $username, bool $caseSensitive = true): Wallet - { - if ($caseSensitive === false) { - $username = substr(DB::getPdo()->quote($username), 1, -1); - - return Wallet::whereRaw('lower(attributes::text)::jsonb @> lower(\'{"username":"'.$username.'"}\')::jsonb') - ->firstOrFail(); - } - - return Wallet::where('attributes->username', $username)->firstOrFail(); - } - public function findByIdentifier(string $identifier): Wallet { $query = Wallet::query(); @@ -75,9 +52,6 @@ public function findByIdentifier(string $identifier): Wallet $query->whereLower('address', $identifier); } elseif ($this->couldBePublicKey($identifier)) { $query->whereLower('public_key', $identifier); - } elseif ($this->couldBeUsername($identifier)) { - $username = substr(DB::getPdo()->quote($identifier), 1, -1); - $query->orWhereRaw('lower(attributes::text)::jsonb @> lower(\'{"username":"'.$username.'"}\')::jsonb'); } else { $query->empty(); } diff --git a/app/Repositories/WalletRepositoryWithCache.php b/app/Repositories/WalletRepositoryWithCache.php index c2a6a7783..4037bb666 100644 --- a/app/Repositories/WalletRepositoryWithCache.php +++ b/app/Repositories/WalletRepositoryWithCache.php @@ -20,11 +20,6 @@ public function __construct(private WalletRepository $wallets) { } - public function allWithUsername(): Builder - { - return $this->wallets->allWithUsername(); - } - public function allWithValidatorPublicKey(): Builder { return $this->wallets->allWithValidatorPublicKey(); @@ -40,11 +35,6 @@ public function allWithPublicKey(): Builder return $this->wallets->allWithPublicKey(); } - public function allWithMultiSignature(): Builder - { - return $this->wallets->allWithMultiSignature(); - } - public function findByAddress(string $address): Wallet { return $this->remember(fn () => $this->wallets->findByAddress($address)); @@ -60,11 +50,6 @@ public function findByPublicKeys(array $publicKeys): Collection return $this->remember(fn () => $this->wallets->findByPublicKeys($publicKeys)); } - public function findByUsername(string $username, bool $caseSensitive = true): Wallet - { - return $this->remember(fn () => $this->wallets->findByUsername($username, $caseSensitive)); - } - public function findByIdentifier(string $identifier): Wallet { return $this->remember(fn () => $this->wallets->findByIdentifier($identifier)); diff --git a/app/Services/Cache/WalletCache.php b/app/Services/Cache/WalletCache.php index 6ee0524bc..ed254e18c 100644 --- a/app/Services/Cache/WalletCache.php +++ b/app/Services/Cache/WalletCache.php @@ -75,39 +75,24 @@ public function setVote(string $address, Wallet $value): void $this->put(sprintf('vote/%s', $address), $value); } - public function getMultiSignatureAddress(int $min, array $publicKeys): ?string - { - return $this->get(sprintf('multi_signature/%s/%s', $min, serialize($publicKeys))); - } - - public function setMultiSignatureAddress(int $min, array $publicKeys, Closure $callback): void - { - $this->remember(sprintf('multi_signature/%s/%s', $min, serialize($publicKeys)), now()->addHour(), $callback); - } - - public function getUsernameByAddress(string $address): ?string - { - return $this->get(sprintf('username_by_address/%s', $address)); - } - - public function setUsernameByAddress(string $address, string $username): void + public function getValidator(string $address): ?Wallet { - $this->put(sprintf('username_by_address/%s', $address), $username); + return $this->get(sprintf('validator/%s', $address)); } - public function forgetUsernameByAddress(string $address): void + public function setValidator(string $address, Wallet $wallet): void { - $this->forget(sprintf('username_by_address/%s', $address)); + $this->put(sprintf('validator/%s', $address), $wallet); } - public function getValidator(string $address): ?Wallet + public function getWalletNameByAddress(string $address): ?string { - return $this->get(sprintf('validator/%s', $address)); + return $this->get(sprintf('name_by_address/%s', $address)); } - public function setValidator(string $address, Wallet $wallet): void + public function setWalletNameByAddress(string $address, string $name): void { - $this->put(sprintf('validator/%s', $address), $wallet); + $this->put(sprintf('name_by_address/%s', $address), $name); } public function getVoterCount(string $address): int diff --git a/app/Services/Forms.php b/app/Services/Forms.php index fccbfd985..c175664e2 100644 --- a/app/Services/Forms.php +++ b/app/Services/Forms.php @@ -14,10 +14,6 @@ final class Forms 'validatorRegistration', 'validatorResignation', 'vote', - 'multiSignature', - 'multiPayment', - 'usernameRegistration', - 'usernameResignation', ]; /** diff --git a/app/Services/Search/Traits/ValidatesTerm.php b/app/Services/Search/Traits/ValidatesTerm.php index 153985e23..0e4a73ace 100644 --- a/app/Services/Search/Traits/ValidatesTerm.php +++ b/app/Services/Search/Traits/ValidatesTerm.php @@ -33,25 +33,6 @@ private function couldBePublicKey(string $term): bool return strlen($term) === 66 && $this->isHexadecimalString($term); } - /** - * Check if the query can be a username - * Regex source: https://github.com/ArkEcosystem/core/blob/4e149f039b59da97d224db1c593059dbc8e0f385/packages/core-api/src/handlers/shared/schemas/username.ts. - * - * @return bool - */ - private function couldBeUsername(string $term): bool - { - // "Known wallets" are not related to anything on-chain, they are set by ARK team and can be seen here: https://github.com/ArkEcosystem/common/tree/master/mainnet - // They are not related to validator usernames that are registered on-chain, meaning that they can be anything. - // Therefore 30 character restriction is not something that's actively enforced for those names - - $regex = '/^[a-zA-Z0-9!@$&_.()\[\] ]+$/'; - - return strlen($term) >= 1 - && strlen($term) <= 30 - && preg_match($regex, $term, $matches) > 0; - } - private function is64CharsHexadecimalString(string $term): bool { return $this->isOnlyNumbers($term) diff --git a/app/Services/Search/WalletSearch.php b/app/Services/Search/WalletSearch.php index 86e5b2d9d..f446c74be 100644 --- a/app/Services/Search/WalletSearch.php +++ b/app/Services/Search/WalletSearch.php @@ -8,7 +8,6 @@ use App\Models\Wallet; use App\Services\Search\Traits\ValidatesTerm; use Illuminate\Database\Eloquent\Collection as EloquentCollection; -use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Meilisearch\Contracts\SearchQuery; @@ -39,14 +38,7 @@ public function search(string $query, int $limit): EloquentCollection public static function mapMeilisearchResults(array $rawResults): Collection { - return collect($rawResults)->map(fn ($item) => new Wallet([ - ...$item, - 'attributes' => [ - 'validator' => [ - 'username' => Arr::get($item, 'username'), - ], - ], - ])); + return collect($rawResults)->map(fn ($item) => new Wallet($item)); } public static function buildSearchQueryForIndex(string $query, int $limit): ?SearchQuery diff --git a/app/Services/Transactions/Aggregates/Concerns/HasQueries.php b/app/Services/Transactions/Aggregates/Concerns/HasQueries.php index 0f3286eaf..7b32eed89 100644 --- a/app/Services/Transactions/Aggregates/Concerns/HasQueries.php +++ b/app/Services/Transactions/Aggregates/Concerns/HasQueries.php @@ -17,9 +17,4 @@ private function dateRangeQuery(Carbon $start, Carbon $end): Builder $end->getTimestampMs(), ]); } - - private function getScopeByType(string $type): ?string - { - return data_get(Transaction::TYPE_SCOPES, $type); - } } diff --git a/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php b/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php index 250dd094b..7d2d63d27 100644 --- a/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php +++ b/app/Services/Transactions/Aggregates/HistoricalAggregateFactory.php @@ -12,7 +12,6 @@ use App\Services\Transactions\Aggregates\Historical\QuarterAggregate; use App\Services\Transactions\Aggregates\Historical\WeekAggregate; use App\Services\Transactions\Aggregates\Historical\YearAggregate; -use App\Services\Transactions\Aggregates\Type\MultipaymentAggregate; use App\Services\Transactions\Aggregates\Type\TransferAggregate; use App\Services\Transactions\Aggregates\Type\UnvoteAggregate; use App\Services\Transactions\Aggregates\Type\ValidatorRegistrationAggregate; @@ -51,16 +50,12 @@ public static function period(string $period): DayAggregate | WeekAggregate | Mo throw new InvalidArgumentException('Invalid aggregate period.'); } - public static function type(string $type): TransferAggregate | MultipaymentAggregate | VoteAggregate | UnvoteAggregate | ValidatorRegistrationAggregate | ValidatorResignationAggregate + public static function type(string $type): TransferAggregate | VoteAggregate | UnvoteAggregate | ValidatorRegistrationAggregate | ValidatorResignationAggregate { if ($type === StatsTransactionType::TRANSFER) { return new TransferAggregate(); } - if ($type === StatsTransactionType::MULTIPAYMENT) { - return new MultipaymentAggregate(); - } - if ($type === StatsTransactionType::VOTE) { return new VoteAggregate(); } diff --git a/app/Services/Transactions/Aggregates/LargestTransactionAggregate.php b/app/Services/Transactions/Aggregates/LargestTransactionAggregate.php index 6bd5e5586..9a1c9d00f 100644 --- a/app/Services/Transactions/Aggregates/LargestTransactionAggregate.php +++ b/app/Services/Transactions/Aggregates/LargestTransactionAggregate.php @@ -10,7 +10,7 @@ final class LargestTransactionAggregate { public function aggregate(): ?Transaction { - // TODO: add transaction type for transfer/multi-payment - https://app.clickup.com/t/86dur8fj6 + // TODO: add transaction type for transfer - https://app.clickup.com/t/86dur8fj6 return Transaction::orderBy('amount', 'desc')->limit(1)->first(); } } diff --git a/app/Services/Transactions/Aggregates/Type/MultipaymentAggregate.php b/app/Services/Transactions/Aggregates/Type/MultipaymentAggregate.php deleted file mode 100644 index f0ac3879f..000000000 --- a/app/Services/Transactions/Aggregates/Type/MultipaymentAggregate.php +++ /dev/null @@ -1,15 +0,0 @@ - 'validator-registration', 'isUnvote' => 'unvote', 'isVote' => 'vote', - 'isMultiSignature' => 'multi-signature', 'isValidatorResignation' => 'validator-resignation', - 'isMultiPayment' => 'multi-payment', - 'isUsernameRegistration' => 'username-registration', - 'isUsernameResignation' => 'username-resignation', ]; private array $typesExact = [ @@ -23,10 +19,6 @@ trait ManagesTransactionTypes 'isValidatorRegistration' => 'validator-registration', 'isUnvote' => 'unvote', 'isVote' => 'vote', - 'isMultiSignature' => 'multi-signature', 'isValidatorResignation' => 'validator-resignation', - 'isMultiPayment' => 'multi-payment', - 'isUsernameRegistration' => 'username-registration', - 'isUsernameResignation' => 'username-resignation', ]; } diff --git a/app/Services/Transactions/TransactionMethod.php b/app/Services/Transactions/TransactionMethod.php index 0bc7da8ed..35650bbf5 100644 --- a/app/Services/Transactions/TransactionMethod.php +++ b/app/Services/Transactions/TransactionMethod.php @@ -5,10 +5,8 @@ namespace App\Services\Transactions; use App\Enums\PayloadSignature; -use App\Enums\TransactionTypeEnum; use App\Models\Transaction; use App\ViewModels\Concerns\Transaction\HasPayload; -use Illuminate\Support\Arr; final class TransactionMethod { @@ -19,13 +17,9 @@ final class TransactionMethod private array $types = [ 'isTransfer' => 'transfer', 'isValidatorRegistration' => 'validator-registration', - // 'isUsernameRegistration' => 'username-registration', - // 'isUsernameResignation' => 'username-resignation', 'isUnvote' => 'unvote', 'isVote' => 'vote', - // 'isMultiSignature' => 'multi-signature', 'isValidatorResignation' => 'validator-resignation', - // 'isMultiPayment' => 'multi-payment', ]; public function __construct(private Transaction $transaction) @@ -68,88 +62,8 @@ public function isUnvote(): bool return $this->methodHash === PayloadSignature::UNVOTE->value; } - // public function isMultiSignature(): bool - // { - // return $this->transaction->type === TransactionTypeEnum::MULTI_SIGNATURE; - // } - public function isValidatorResignation(): bool { return $this->methodHash === PayloadSignature::VALIDATOR_RESIGNATION->value; } - - // public function isMultiPayment(): bool - // { - // return $this->transaction->type === TransactionTypeEnum::MULTI_PAYMENT; - // } - - // public function isUsernameRegistration(): bool - // { - // return $this->transaction->type === TransactionTypeEnum::USERNAME_REGISTRATION; - // } - - // public function isUsernameResignation(): bool - // { - // return $this->transaction->type === TransactionTypeEnum::USERNAME_RESIGNATION; - // } - - public function isUnknown(): bool - { - if ($this->isTransfer()) { - return false; - } - - if ($this->isValidatorRegistration()) { - return false; - } - - if ($this->isUnvote()) { - return false; - } - - if ($this->isVote()) { - return false; - } - - // if ($this->isMultiSignature()) { - // return false; - // } - - if ($this->isValidatorResignation()) { - return false; - } - - // if ($this->isMultiPayment()) { - // return false; - // } - - // if ($this->isUsernameRegistration()) { - // return false; - // } - - // if ($this->isUsernameResignation()) { - // return false; - // } - - return true; - } - - // private function determineVoteTypes(): array - // { - // $containsVote = false; - // $containsUnvote = false; - - // if ($this->transaction->type !== TransactionTypeEnum::VOTE) { - // return [$containsVote, $containsUnvote]; - // } - - // if (! is_array($this->transaction->asset)) { - // return [$containsVote, $containsUnvote]; - // } - - // $containsVote = count(Arr::get($this->transaction->asset, 'votes', [])) !== 0; - // $containsUnvote = count(Arr::get($this->transaction->asset, 'unvotes', [])) !== 0; - - // return [$containsVote, $containsUnvote]; - // } } diff --git a/app/ViewModels/Concerns/Block/HasValidator.php b/app/ViewModels/Concerns/Block/HasValidator.php index a4ebf1fb3..b258d5685 100644 --- a/app/ViewModels/Concerns/Block/HasValidator.php +++ b/app/ViewModels/Concerns/Block/HasValidator.php @@ -18,8 +18,8 @@ public function address(): string return $this->validator()->address() ?? 'Genesis'; } - public function username(): string + public function walletName(): string { - return $this->validator()->username() ?? 'Genesis'; + return $this->validator()->walletName() ?? 'Genesis'; } } diff --git a/app/ViewModels/Concerns/Transaction/HasDirection.php b/app/ViewModels/Concerns/Transaction/HasDirection.php index 8a4e53bcc..085edc5ae 100644 --- a/app/ViewModels/Concerns/Transaction/HasDirection.php +++ b/app/ViewModels/Concerns/Transaction/HasDirection.php @@ -13,7 +13,7 @@ public function isSent(string $address): bool public function isSentToSelf(string $address): bool { - if (! $this->isTransfer() && ! $this->isMultiPayment()) { + if (! $this->isTransfer()) { return false; } @@ -21,7 +21,7 @@ public function isSentToSelf(string $address): bool return false; } - if ($this->isTransfer() && $this->recipient() !== null && $address === $this->recipient()->address) { + if ($this->recipient() !== null && $address === $this->recipient()->address) { return true; } diff --git a/app/ViewModels/Concerns/Transaction/HasMethod.php b/app/ViewModels/Concerns/Transaction/HasMethod.php index 135baaae5..ad1514a06 100644 --- a/app/ViewModels/Concerns/Transaction/HasMethod.php +++ b/app/ViewModels/Concerns/Transaction/HasMethod.php @@ -33,44 +33,11 @@ public function isUnvote(): bool return $this->method->isUnvote(); } - public function isMultiSignature(): bool - { - return false; - - return $this->method->isMultiSignature(); - } - public function isValidatorResignation(): bool { return $this->method->isValidatorResignation(); } - public function isMultiPayment(): bool - { - return false; - - return $this->method->isMultiPayment(); - } - - public function isUsernameRegistration(): bool - { - return false; - - return $this->method->isUsernameRegistration(); - } - - public function isUsernameResignation(): bool - { - return false; - - return $this->method->isUsernameResignation(); - } - - public function isUnknown(): bool - { - return $this->method->isUnknown(); - } - public function isSelfReceiving(): bool { if ($this->isValidatorRegistration()) { @@ -89,14 +56,6 @@ public function isSelfReceiving(): bool return true; } - // if ($this->isUsernameRegistration()) { - // return true; - // } - - // if ($this->isUsernameResignation()) { - // return true; - // } - return false; } } diff --git a/app/ViewModels/Concerns/Transaction/InteractsWithMultiPayment.php b/app/ViewModels/Concerns/Transaction/InteractsWithMultiPayment.php deleted file mode 100644 index 45d7e601e..000000000 --- a/app/ViewModels/Concerns/Transaction/InteractsWithMultiPayment.php +++ /dev/null @@ -1,45 +0,0 @@ -isMultiPayment()) { - return []; - } - - if (is_null($this->transaction->asset)) { - return []; - } - - /** @var array> */ - $payments = Arr::get($this->transaction->asset, 'payments', []); - - return collect($payments) - ->map(fn ($payment) => new Payment($this->transaction->timestamp, $payment)) - ->when($sortAmountDescending, fn ($collection) => $collection->sort(function ($a, $b) { - return $b->amount() <=> $a->amount(); - })) - ->toArray(); - } - - public function recipientsCount(): int - { - if (! $this->isMultiPayment()) { - return 0; - } - - if (is_null($this->transaction->asset)) { - return 0; - } - - return count(Arr::get($this->transaction->asset, 'payments')); - } -} diff --git a/app/ViewModels/Concerns/Transaction/InteractsWithMultiSignature.php b/app/ViewModels/Concerns/Transaction/InteractsWithMultiSignature.php deleted file mode 100644 index 795beee45..000000000 --- a/app/ViewModels/Concerns/Transaction/InteractsWithMultiSignature.php +++ /dev/null @@ -1,106 +0,0 @@ -multiSignatureAddress(); - - if (is_null($address)) { - return null; - } - - return new WalletViewModel(Wallets::findByAddress($address)); - } - - public function multiSignatureAddress(): ?string - { - if (! $this->isMultiSignature()) { - return null; - } - - if (is_null($this->transaction->asset)) { - return null; - } - - if (Arr::has($this->transaction->asset, 'multiSignature')) { - return Address::fromMultiSignatureAsset( - Arr::get($this->transaction->asset, 'multiSignature.min', 0), - Arr::get($this->transaction->asset, 'multiSignature.publicKeys', []) - ); - } - - return $this->transaction->sender->address; - } - - public function participants(): array - { - if (! $this->isMultiSignature()) { - return []; - } - - if (is_null($this->transaction->asset)) { - return []; - } - - $participants = null; - if (Arr::has($this->transaction->asset, 'multiSignatureLegacy')) { - /** @var string[] */ - $participants = Arr::get($this->transaction->asset, 'multiSignatureLegacy.keysgroup', []); - $participants = collect($participants) - ->map(fn ($publicKey) => substr($publicKey, 1)); - } else { - /** @var string[] */ - $participants = Arr::get($this->transaction->asset, 'multiSignature.publicKeys', []); - $participants = collect($participants); - } - - return $participants->map(fn ($publicKey) => Address::fromPublicKey($publicKey)) - ->map(fn ($address) => MemoryWallet::fromAddress($address)) - ->toArray(); - } - - public function multiSignatureMinimum(): ?int - { - if (! $this->isMultiSignature()) { - return null; - } - - if (is_null($this->transaction->asset)) { - return null; - } - - if (Arr::has($this->transaction->asset, 'multiSignatureLegacy')) { - return Arr::get($this->transaction->asset, 'multiSignatureLegacy.min', 0); - } - - return Arr::get($this->transaction->asset, 'multiSignature.min', 0); - } - - public function multiSignatureParticipantCount(): ?int - { - if (! $this->isMultiSignature()) { - return null; - } - - if (is_null($this->transaction->asset)) { - return null; - } - - if (Arr::has($this->transaction->asset, 'multiSignatureLegacy')) { - return count(Arr::get($this->transaction->asset, 'multiSignatureLegacy.keysgroup', [])); - } - - return count(Arr::get($this->transaction->asset, 'multiSignature.publicKeys', [])); - } -} diff --git a/app/ViewModels/Concerns/Transaction/InteractsWithUsernames.php b/app/ViewModels/Concerns/Transaction/InteractsWithUsernames.php deleted file mode 100644 index f385391e0..000000000 --- a/app/ViewModels/Concerns/Transaction/InteractsWithUsernames.php +++ /dev/null @@ -1,15 +0,0 @@ -transaction, 'asset.username'); - } -} diff --git a/app/ViewModels/Concerns/Wallet/CanBeKnownWallet.php b/app/ViewModels/Concerns/Wallet/CanBeKnownWallet.php new file mode 100644 index 000000000..3915801d3 --- /dev/null +++ b/app/ViewModels/Concerns/Wallet/CanBeKnownWallet.php @@ -0,0 +1,23 @@ +findWalletByKnown()); + } + + public function walletName(): ?string + { + $knownWallet = $this->findWalletByKnown(); + if (! is_null($knownWallet)) { + return $knownWallet['name']; + } + + return null; + } +} diff --git a/app/ViewModels/Concerns/Wallet/CanHaveUsername.php b/app/ViewModels/Concerns/Wallet/CanHaveUsername.php deleted file mode 100644 index 7ca12d96e..000000000 --- a/app/ViewModels/Concerns/Wallet/CanHaveUsername.php +++ /dev/null @@ -1,43 +0,0 @@ -username() !== null; - } - - public function username(): ?string - { - return $this->wallet->username(); - } - - public function usernameIfNotKnown(): ?string - { - $knownWallet = $this->findWalletByKnown(); - if (! is_null($knownWallet)) { - return $knownWallet['name']; - } - - return $this->username(); - } - - public function usernameBeforeKnown(): ?string - { - $username = $this->username(); - if ($username !== null) { - return $username; - } - - $knownWallet = $this->findWalletByKnown(); - if ($knownWallet !== null) { - return $knownWallet['name']; - } - - return null; - } -} diff --git a/app/ViewModels/Concerns/Wallet/HasType.php b/app/ViewModels/Concerns/Wallet/HasType.php index 6f307eb43..3d8da50f7 100644 --- a/app/ViewModels/Concerns/Wallet/HasType.php +++ b/app/ViewModels/Concerns/Wallet/HasType.php @@ -5,20 +5,9 @@ namespace App\ViewModels\Concerns\Wallet; use App\Facades\Network; -use Illuminate\Support\Arr; trait HasType { - public function hasSecondSignature(): bool - { - return Arr::has($this->wallet->attributes, 'secondPublicKey'); - } - - public function hasMultiSignature(): bool - { - return Arr::has($this->wallet->attributes, 'multiSignature'); - } - public function isKnown(): bool { return ! is_null($this->findWalletByKnown()); @@ -48,14 +37,6 @@ public function hasSpecialType(): bool return true; } - if ($this->hasMultiSignature()) { - return true; - } - - if ($this->hasSecondSignature()) { - return true; - } - return $this->isOwnedByExchange(); } diff --git a/app/ViewModels/ForgingStatsViewModel.php b/app/ViewModels/ForgingStatsViewModel.php index 8a0b09a47..efccb731f 100644 --- a/app/ViewModels/ForgingStatsViewModel.php +++ b/app/ViewModels/ForgingStatsViewModel.php @@ -29,9 +29,9 @@ public function address(): ?string return $this->validator()?->address(); } - public function username(): ?string + public function walletName(): ?string { - return $this->validator()?->username(); + return $this->validator()?->walletName(); } public function timestamp(): string diff --git a/app/ViewModels/TransactionViewModel.php b/app/ViewModels/TransactionViewModel.php index 799ff8773..e008da3d6 100644 --- a/app/ViewModels/TransactionViewModel.php +++ b/app/ViewModels/TransactionViewModel.php @@ -16,9 +16,6 @@ use App\ViewModels\Concerns\Transaction\HasMethod; use App\ViewModels\Concerns\Transaction\HasPayload; use App\ViewModels\Concerns\Transaction\HasState; -use App\ViewModels\Concerns\Transaction\InteractsWithMultiPayment; -use App\ViewModels\Concerns\Transaction\InteractsWithMultiSignature; -use App\ViewModels\Concerns\Transaction\InteractsWithUsernames; use App\ViewModels\Concerns\Transaction\InteractsWithVotes; use App\ViewModels\Concerns\Transaction\InteractsWithWallets; use ArkEcosystem\Crypto\Utils\UnitConverter; @@ -31,9 +28,6 @@ final class TransactionViewModel implements ViewModel use HasPayload; use HasState; use HasMethod; - use InteractsWithMultiPayment; - use InteractsWithMultiSignature; - use InteractsWithUsernames; use InteractsWithVotes; use InteractsWithWallets; @@ -130,42 +124,16 @@ public function amountExcludingItself(): float public function amount(): float { - if ($this->isMultiPayment()) { - /** @var array> */ - $payments = Arr::get($this->transaction, 'asset.payments', []); - - return collect($payments) - ->sum('amount') / config('currencies.notation.crypto', 1e18); - } - return $this->transaction->amount->toFloat(); } public function amountWithFee(): float { - $amount = $this->transaction->amount->toFloat(); - if ($this->isMultiPayment()) { - /** @var array> */ - $payments = Arr::get($this->transaction, 'asset.payments', []); - - return collect($payments) - ->sum('amount') / config('currencies.notation.crypto', 1e18); - } - - return $amount + $this->fee(); + return $this->transaction->amount->toFloat() + $this->fee(); } public function amountReceived(?string $wallet = null): float { - if ($this->isMultiPayment() && $wallet !== null) { - /** @var array> */ - $payments = Arr::get($this->transaction, 'asset.payments', []); - - return collect($payments) - ->where('recipientId', $wallet) - ->sum('amount') / config('currencies.notation.crypto', 1e18); - } - return $this->amount(); } diff --git a/app/ViewModels/WalletViewModel.php b/app/ViewModels/WalletViewModel.php index 6a90e333f..4d9681257 100644 --- a/app/ViewModels/WalletViewModel.php +++ b/app/ViewModels/WalletViewModel.php @@ -10,9 +10,9 @@ use App\Services\ArkVaultUrlBuilder; use App\Services\ExchangeRate; use App\ViewModels\Concerns\Wallet\CanBeCold; +use App\ViewModels\Concerns\Wallet\CanBeKnownWallet; use App\ViewModels\Concerns\Wallet\CanBeValidator; use App\ViewModels\Concerns\Wallet\CanForge; -use App\ViewModels\Concerns\Wallet\CanHaveUsername; use App\ViewModels\Concerns\Wallet\CanVote; use App\ViewModels\Concerns\Wallet\HasType; use App\ViewModels\Concerns\Wallet\HasVoters; @@ -21,9 +21,9 @@ final class WalletViewModel implements ViewModel { use CanBeCold; + use CanBeKnownWallet; use CanBeValidator; use CanForge; - use CanHaveUsername; use CanVote; use HasType; use HasVoters; diff --git a/config/scout.php b/config/scout.php index e58ce2d06..708f5b26b 100644 --- a/config/scout.php +++ b/config/scout.php @@ -142,7 +142,7 @@ // `php artisan scout:sync-index-settings` to apply the changes. 'index-settings' => [ Wallet::class => [ - 'searchableAttributes'=> ['address', 'username'], + 'searchableAttributes'=> ['address'], 'sortableAttributes' => ['timestamp'], 'typoTolerance' => [ 'enabled' => false, diff --git a/database/factories/TransactionFactory.php b/database/factories/TransactionFactory.php index 4325fb8d8..bad366926 100644 --- a/database/factories/TransactionFactory.php +++ b/database/factories/TransactionFactory.php @@ -4,7 +4,6 @@ namespace Database\Factories; -use App\Enums\TransactionTypeEnum; use App\Models\Block; use App\Models\Receipt; use App\Models\Transaction; @@ -23,8 +22,6 @@ public function definition() 'id' => $this->faker->transactionId, 'block_id' => fn () => Block::factory(), 'block_height' => $this->faker->numberBetween(1, 10000), - 'type' => $this->faker->numberBetween(1, 100), - 'type_group' => $this->faker->numberBetween(1, 100), 'sender_public_key' => fn () => $wallet->public_key, 'recipient_id' => fn () => $wallet->address, 'timestamp' => 1603083256000, @@ -38,93 +35,4 @@ public function withReceipt(int $gasUsed = 21000): Factory { return $this->has(Receipt::factory()->state(fn () => ['gas_used' => $gasUsed])); } - - public function transfer(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::TRANSFER, - 'type_group' => 1, - 'asset' => [], - ]); - } - - public function validatorRegistration(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::VALIDATOR_REGISTRATION, - 'type_group' => 1, - 'asset' => [], - ]); - } - - public function vote(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::VOTE, - 'type_group' => 1, - 'asset' => [ - 'votes' => ['address'], - 'unvotes' => [], - ], - ]); - } - - public function unvote(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::VOTE, - 'type_group' => 1, - 'asset' => [ - 'votes' => [], - 'unvotes' => ['address'], - ], - ]); - } - - public function multiSignature(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::MULTI_SIGNATURE, - 'type_group' => 1, - 'asset' => [], - ]); - } - - public function validatorResignation(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::VALIDATOR_RESIGNATION, - 'type_group' => 1, - 'asset' => [], - ]); - } - - public function multiPayment(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::MULTI_PAYMENT, - 'type_group' => 1, - 'asset' => [], - ]); - } - - public function usernameRegistration(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::USERNAME_REGISTRATION, - 'type_group' => 1, - 'asset' => [ - 'username' => 'bob', - ], - ]); - } - - public function usernameResignation(): Factory - { - return $this->state(fn () => [ - 'type' => TransactionTypeEnum::USERNAME_RESIGNATION, - 'type_group' => 1, - 'asset' => [], - ]); - } } diff --git a/database/factories/WalletFactory.php b/database/factories/WalletFactory.php index 02b86919e..7d4f67731 100644 --- a/database/factories/WalletFactory.php +++ b/database/factories/WalletFactory.php @@ -24,7 +24,6 @@ public function definition() 'nonce' => $this->faker->numberBetween(1, 1000), 'attributes' => [ 'secondPublicKey' => $this->faker->publicKey, - 'username' => $this->faker->userName, 'validatorVoteBalance' => $this->faker->numberBetween(1, 1000) * 1e18, 'validatorProducedBlocks' => $this->faker->numberBetween(1, 1000), 'validatorMissedBlocks' => $this->faker->numberBetween(1, 1000), @@ -38,7 +37,6 @@ public function activeValidator() return $this->state(function () { return [ 'attributes' => [ - 'username' => $this->faker->userName, 'validatorPublicKey' => $this->faker->publicKey, 'validatorRank' => $this->faker->numberBetween(1, Network::validatorCount()), 'validatorApproval' => $this->faker->randomFloat(2, 0, 2), @@ -59,7 +57,6 @@ public function standbyValidator(bool $isResigned = true) if ($isResigned) { return [ 'attributes' => [ - 'username' => $this->faker->userName, 'validatorResigned' => true, 'validatorPublicKey' => $this->faker->publicKey, 'validatorVoteBalance' => $this->faker->numberBetween(1, 100) * 1e18, @@ -69,7 +66,6 @@ public function standbyValidator(bool $isResigned = true) return [ 'attributes' => [ - 'username' => $this->faker->userName, 'validatorRank' => $this->faker->numberBetween(Network::validatorCount() + 1, (Network::validatorCount() * 2) - 1), 'validatorApproval' => $this->faker->randomFloat(2, 0, 2), 'validatorPublicKey' => $this->faker->publicKey, @@ -82,21 +78,4 @@ public function standbyValidator(bool $isResigned = true) ]; }); } - - public function multiSignature() - { - return $this->state(function () { - return [ - 'attributes' => [ - 'multiSignature' => [ - 'min' => 2, - 'publicKeys' => [ - '022a40ea35d53eedf0341ffa17574fca844d69665ce35f224e9a6b1385575044fd', - '037fde73baaa48eb75c013fe9ff52a74a096d48b9978351bdcb5b72331ca37487c', - ], - ], - ], - ]; - }); - } } diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 7f744097e..c36d1b375 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -28,11 +28,10 @@ php artisan explorer:cache-validator-aggregates php artisan explorer:cache-validator-performance php artisan explorer:cache-validator-productivity php artisan explorer:cache-validator-resignation-ids -php artisan explorer:cache-usernames +php artisan explorer:cache-known-wallets php artisan explorer:cache-validator-wallets php artisan explorer:cache-validators-with-voters php artisan explorer:cache-validator-voter-counts -php artisan explorer:cache-multi-signature-addresses php artisan explorer:cache-blocks php artisan explorer:cache-transactions php artisan explorer:cache-address-statistics diff --git a/resources/icons/second-signature.svg b/resources/icons/second-signature.svg deleted file mode 100644 index 37c13fecc..000000000 --- a/resources/icons/second-signature.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/js/includes/enums.js b/resources/js/includes/enums.js index b366807f5..d619ffb1d 100644 --- a/resources/js/includes/enums.js +++ b/resources/js/includes/enums.js @@ -1,14 +1,3 @@ -export const TransactionType = { - Transfer: 0, - ValidatorRegistration: 2, - Vote: 3, - MultiSignature: 4, - MultiPayment: 6, - ValidatorResignation: 7, - UsernameRegistration: 8, - UsernameResignation: 9, -}; - export const ExportStatus = { PendingExport: "PENDING_EXPORT", Error: "ERROR", diff --git a/resources/js/transactions-export.js b/resources/js/transactions-export.js index 71fc5e019..fad014ef1 100644 --- a/resources/js/transactions-export.js +++ b/resources/js/transactions-export.js @@ -11,7 +11,7 @@ import { getDateRange, queryTimestamp, } from "./includes/helpers"; -import { ExportStatus, TransactionType } from "./includes/enums"; +import { ExportStatus } from "./includes/enums"; import { TransactionsApi } from "./api/transactions"; @@ -43,25 +43,6 @@ const TransactionsExport = ({ const getTransactionAmount = (transaction) => { let amount = arktoshiToNumber(transaction.amount); - if (transaction.type === TransactionType.MultiPayment) { - return transaction.asset.payments.reduce( - (totalAmount, recipientData) => { - if (recipientData.recipientId === address) { - if (totalAmount < 0) { - totalAmount = 0; - } - - totalAmount += arktoshiToNumber(recipientData.amount); - } else if (totalAmount <= 0) { - totalAmount -= arktoshiToNumber(recipientData.amount); - } - - return totalAmount; - }, - 0 - ); - } - if (transaction.sender === address) { return -amount; } @@ -73,19 +54,7 @@ const TransactionsExport = ({ timestamp: (transaction) => dayjs(parseInt(transaction.timestamp)).format("L LTS"), recipient: (transaction) => { - if (transaction.type === TransactionType.Transfer) { - return transaction.recipient; - } - - if (transaction.type === TransactionType.Vote) { - return "Vote Transaction"; - } - - if (transaction.type === TransactionType.MultiPayment) { - return `Multiple (${transaction.asset.payments.length})`; - } - - return "Other"; + return transaction.recipient; }, amount: getTransactionAmount, fee: (transaction) => { @@ -142,7 +111,6 @@ const TransactionsExport = ({ types: { transfers: false, votes: false, - multipayments: false, others: false, }, @@ -248,7 +216,7 @@ const TransactionsExport = ({ return getDateRange(this.dateRange); }, - requestData(withoutTransactionTypes = false) { + requestData() { const [dateFrom, dateTo] = this.getDateRange(); const data = { @@ -261,28 +229,6 @@ const TransactionsExport = ({ data["timestamp.to"] = queryTimestamp(dateTo); } - if (this.types.transfers) { - data.type.push(TransactionType.Transfer); - } - - if (this.types.votes) { - data.type.push(TransactionType.Vote); - } - - if (this.types.multipayments) { - data.type.push(TransactionType.MultiPayment); - } - - if (this.types.others) { - data.type.push( - TransactionType.ValidatorRegistration, - TransactionType.MultiSignature, - TransactionType.ValidatorResignation, - TransactionType.UsernameRegistration, - TransactionType.UsernameResignation - ); - } - data.type = data.type.join(","); return data; diff --git a/resources/js/wallet.js b/resources/js/wallet.js index d464bb9d6..d51b91f1e 100644 --- a/resources/js/wallet.js +++ b/resources/js/wallet.js @@ -137,11 +137,6 @@ const Wallet = (network, xData = {}) => { return null; } - const username = this.votingFor.attributes?.delegate?.username; - if (username) { - return username; - } - return truncateMiddle(this.votingForAddress); }, diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 4efaeff29..9c11e57a0 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -12,7 +12,6 @@ 'block' => 'Block', 'transaction' => 'Transaction', 'wallet' => 'Wallet', - 'username' => 'Username', 'vote' => 'Voting for', 'balance_range' => 'Balance Range', 'height_range' => 'Height Range', @@ -32,10 +31,6 @@ 'all' => 'All', 'validatorRegistration' => 'Validator Registration', 'validatorResignation' => 'Validator Resignation', - 'usernameRegistration' => 'Username Registration', - 'usernameResignation' => 'Username Resignation', - 'multiPayment' => 'Multipayment', - 'multiSignature' => 'Multisignature', 'transfer' => 'Transfer', 'vote' => 'Vote', ], diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index bf12d355e..4f9d5fddd 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -120,10 +120,6 @@ 'types' => [ 'validator-registration' => 'Registration', 'validator-resignation' => 'Resignation', - 'multi-payment' => 'Multipayment', - 'multi-signature' => 'Multisignature', - 'username-registration' => 'Username Registration', - 'username-resignation' => 'Username Resignation', 'transfer' => 'Transfer', 'unvote' => 'Unvote', 'vote' => 'Vote', diff --git a/resources/lang/en/labels.php b/resources/lang/en/labels.php index 50d1cfcd1..900f460c8 100644 --- a/resources/lang/en/labels.php +++ b/resources/lang/en/labels.php @@ -26,12 +26,9 @@ 'timestamp' => 'Timestamp', 'transaction_count' => 'Transaction Count', 'transaction_id' => 'ID', - 'username' => 'Username', 'name' => 'Name', 'verified_address' => 'Verified Address', 'votes' => 'Votes', 'wallet_type' => 'Info', - 'multi_signature' => 'Multisignature', - 'second_signature' => 'Second Signature', 'percentage' => 'Percentage', ]; diff --git a/resources/lang/en/pages.php b/resources/lang/en/pages.php index 47d64b48d..40205cab1 100644 --- a/resources/lang/en/pages.php +++ b/resources/lang/en/pages.php @@ -92,8 +92,6 @@ 'transaction_details' => 'Transaction Details', 'addressing' => 'Addressing', 'memo' => 'Memo (SmartBridge)', - 'recipients_list' => 'Recipients List', - 'participants' => 'Participants', 'transaction_summary' => 'Transaction Summary', 'more_details' => 'More Details', 'gas_information' => 'Gas Information', @@ -106,7 +104,6 @@ 'nonce' => 'Nonce', 'method' => 'Method', 'validator' => 'Validator', - 'username' => 'Name', 'old_validator' => 'Old Validator', 'new_validator' => 'New Validator', 'address' => 'Address', @@ -122,10 +119,6 @@ 'position_in_block' => 'Position In Block', ], - 'value' => [ - 'multiple_x' => 'Multiple ()', - ], - 'code-block' => [ 'copy_code' => 'Copy Code', @@ -275,10 +268,9 @@ ], 'types-options' => [ - 'transfers' => 'Transfers', - 'votes' => 'Votes', - 'multipayments' => 'Multipayments', - 'others' => 'Others', + 'transfers' => 'Transfers', + 'votes' => 'Votes', + 'others' => 'Others', ], 'columns-options' => [ @@ -305,7 +297,7 @@ 'include_header_row' => 'Include Header Row', 'types_placeholder' => 'Select Types', 'columns_placeholder' => 'Select Columns', - 'success_toast' => ':username.csv has been saved successfully', + 'success_toast' => ':address.csv has been saved successfully', 'columns_x_selected' => [ 'singular' => 'Column Selected', @@ -499,7 +491,6 @@ 'header' => [ 'transfer' => 'Transfers', - 'multipayment' => 'Multipayments', 'vote' => 'Votes', 'unvote' => 'Unvotes', 'validator_registration' => 'Validator Registrations', diff --git a/resources/lang/en/tables.php b/resources/lang/en/tables.php index cec0d7693..010469391 100644 --- a/resources/lang/en/tables.php +++ b/resources/lang/en/tables.php @@ -18,7 +18,6 @@ 'to' => 'To', 'from' => 'From', 'contract' => 'Contract', - 'multiple' => 'Multiple', 'address' => 'Address', 'return' => 'Return', @@ -141,17 +140,16 @@ 'filters' => [ 'transactions' => [ - 'addressing' => 'Addressing', - 'types' => 'Types', - 'select_all' => 'Select All', - 'outgoing' => 'Outgoing', - 'incoming' => 'Incoming', - 'to' => 'To', - 'from' => 'From', - 'transfers' => 'Transfers', - 'votes' => 'Votes', - 'multipayments' => 'Multipayments', - 'others' => 'Others', + 'addressing'=> 'Addressing', + 'types' => 'Types', + 'select_all'=> 'Select All', + 'outgoing' => 'Outgoing', + 'incoming' => 'Incoming', + 'to' => 'To', + 'from' => 'From', + 'transfers' => 'Transfers', + 'votes' => 'Votes', + 'others' => 'Others', ], 'validators' => [ diff --git a/resources/scripts/vote-report.sh b/resources/scripts/vote-report.sh index 24675e4d5..5b760ac96 100644 --- a/resources/scripts/vote-report.sh +++ b/resources/scripts/vote-report.sh @@ -24,11 +24,11 @@ function GetVotersCount { function PrintJsonData { - echo $1 | jq -c -r '.data[] | { rank, username, votes, address, publicKey, production }' | while read Line; do + echo $1 | jq -c -r '.data[] | { rank, votes, address, publicKey, production }' | while read Line; do Rank=$( printf %02d $( echo $Line | jq -r '.rank' ) ) - Validator=$( printf %-25s $( echo $Line | jq -r '.username' ) ) + Validator=$( printf %-25s $( echo $Line | jq -r '.address' ) ) Approval=$( printf %0.2f $( echo $Line | jq -r '.production.approval' ) ) Vote=$( expr $( echo $Line | jq -r '.votes' ) / 100000000 ) @@ -58,7 +58,7 @@ function PrintTotalVotingWeightData { Voters=$( GetVotersCount $PublicKey ) TotalVoters=$( expr $TotalVoters + $Voters ) - done <<< "$( echo $1 | jq -c -r '.data[] | { rank, username, votes, address, publicKey, production }' )" + done <<< "$( echo $1 | jq -c -r '.data[] | { rank, votes, address, publicKey, production }' )" Percentage=$( bc <<< "scale=2; $TotalVote * 100 / $TotalArk" ) diff --git a/resources/views/app/transaction.blade.php b/resources/views/app/transaction.blade.php index 53ac50801..eeab48f8d 100644 --- a/resources/views/app/transaction.blade.php +++ b/resources/views/app/transaction.blade.php @@ -16,12 +16,6 @@ - - @if ($transaction->isMultiPayment()) - - @elseif ($transaction->isMultisignature()) - - @endif
@if ($transaction->hasPayload()) diff --git a/resources/views/app/wallet.blade.php b/resources/views/app/wallet.blade.php index bda17e813..9e364f1cd 100644 --- a/resources/views/app/wallet.blade.php +++ b/resources/views/app/wallet.blade.php @@ -1,5 +1,5 @@ @component('layouts.app') - + @section('content') diff --git a/resources/views/components/general/encapsulated/vote-type.blade.php b/resources/views/components/general/encapsulated/vote-type.blade.php index e5bca9b3f..0eaec7447 100644 --- a/resources/views/components/general/encapsulated/vote-type.blade.php +++ b/resources/views/components/general/encapsulated/vote-type.blade.php @@ -4,9 +4,7 @@ @php($votedValidator = $transaction->voted()) hasUsername()) - data-tippy-html-content="{{ trans('general.transaction.vote_validator', ['validator' => $votedValidator->username()]) }}" - @elseif ($votedValidator) + @if ($votedValidator) data-tippy-html-content="{{ trans('general.transaction.vote_validator', ['validator' => $votedValidator->address()]) }}" @endif > diff --git a/resources/views/components/general/identity-iconless.blade.php b/resources/views/components/general/identity-iconless.blade.php index e9977a71b..bf3805558 100644 --- a/resources/views/components/general/identity-iconless.blade.php +++ b/resources/views/components/general/identity-iconless.blade.php @@ -5,8 +5,8 @@ @endif - @if ($model->username()) - {{ $model->username() }} + @if ($model->isKnownWallet()) + {{ $model->walletName() }} @else @isset($withoutTruncate) {{ $model->address() }} diff --git a/resources/views/components/general/identity.blade.php b/resources/views/components/general/identity.blade.php index 0b84684b5..795db26bf 100644 --- a/resources/views/components/general/identity.blade.php +++ b/resources/views/components/general/identity.blade.php @@ -6,7 +6,6 @@ 'suffix' => false, 'withoutTruncate' => false, 'truncateLength' => null, - 'withoutUsername' => false, 'addressVisible' => false, 'containerClass' => null, 'contentClass' => null, @@ -33,37 +32,16 @@ @class(['font-semibold sm:hidden md:flex link', $linkClass]) > @endif - @if ($model->username() && !$withoutUsername) - @if ($prefix) -
- @elseif ($isListing) -
- @else -
- @endif - {{ $model->username() }} -
+ @if ($address) + {{ $address }} @else - @if ($address) - {{ $address }} + @if($withoutTruncate) + {{ $model->address() }} @else - @if($withoutTruncate) + {{ $model->address() }} - @else - - {{ $model->address() }} - - @endisset - @endif + + @endisset @endif @if ($withoutLink)
@@ -79,23 +57,13 @@ @class(['hidden font-semibold sm:flex md:hidden link', $linkClass]) > @endif - @if ($model->username() && !$withoutUsername) - {{ $model->username() }} - @else - {{ $model->address() }} - @endif + {{ $model->address() }} @if ($withoutLink)
@else
@endif - @if ($model->username() && !$withoutUsername && $addressVisible) - - {{ $model->address() }} - - @endif - @if ($suffix) {{ $suffix }} @endif diff --git a/resources/views/components/general/page-section/data/validator.blade.php b/resources/views/components/general/page-section/data/validator.blade.php index 3ede9a914..184b86963 100644 --- a/resources/views/components/general/page-section/data/validator.blade.php +++ b/resources/views/components/general/page-section/data/validator.blade.php @@ -5,18 +5,14 @@ href="{{ route('wallet', $validator->address()) }}" class="link" > - @if ($validator->hasUsername()) - {{ $validator->username() }} - @else - + -
- - {{ $validator->address() }} - -
- @endif +
+ + {{ $validator->address() }} + +
diff --git a/resources/views/components/search/results/mobile/transaction-type.blade.php b/resources/views/components/search/results/mobile/transaction-type.blade.php index 5e2dad427..50261bd6d 100644 --- a/resources/views/components/search/results/mobile/transaction-type.blade.php +++ b/resources/views/components/search/results/mobile/transaction-type.blade.php @@ -9,8 +9,6 @@ @elseif ($transaction->isVote() || $transaction->isUnvote()) - @elseif ($transaction->isMultiPayment()) - @else @endif diff --git a/resources/views/components/search/results/transaction-types/multi-payment.blade.php b/resources/views/components/search/results/transaction-types/multi-payment.blade.php deleted file mode 100644 index 9081231ad..000000000 --- a/resources/views/components/search/results/transaction-types/multi-payment.blade.php +++ /dev/null @@ -1,29 +0,0 @@ -@props(['transaction']) - -
-
- - @lang('general.search.from') - - - -
- -
- - @lang('general.search.to') - - - - @lang('tables.transactions.multiple') - - ({{ $transaction->recipientsCount() }}) - -
-
diff --git a/resources/views/components/search/results/transaction.blade.php b/resources/views/components/search/results/transaction.blade.php index 2fa3950db..22f151bd1 100644 --- a/resources/views/components/search/results/transaction.blade.php +++ b/resources/views/components/search/results/transaction.blade.php @@ -62,12 +62,6 @@ class="text-theme-secondary-900 dark:text-theme-dark-50" without-link class="text-theme-secondary-900 dark:text-theme-dark-50" /> - @elseif ($transaction->isMultiPayment()) - - @lang('tables.transactions.multiple') - - ({{ $transaction->recipientsCount() }}) - @else @lang('general.search.contract') diff --git a/resources/views/components/skeletons/transaction-recipients.blade.php b/resources/views/components/skeletons/transaction-recipients.blade.php deleted file mode 100644 index 375d929b7..000000000 --- a/resources/views/components/skeletons/transaction-recipients.blade.php +++ /dev/null @@ -1,33 +0,0 @@ -@props([ - 'rowCount' => 10, - 'paginator' => null, -]) - -@if (! $this->isReady) -
- - - -
-@else - - - - - - -
- - {{ $slot }} - -
-@endif diff --git a/resources/views/components/stats/insights/desktop/validator-row.blade.php b/resources/views/components/stats/insights/desktop/validator-row.blade.php index cc7a8d9c7..e7dc61b3c 100644 --- a/resources/views/components/stats/insights/desktop/validator-row.blade.php +++ b/resources/views/components/stats/insights/desktop/validator-row.blade.php @@ -20,7 +20,7 @@ href="{{ route('wallet', $model->model()) }}" class="link" > - {{ $model->username() }} + {{ $model->address() }} @endif diff --git a/resources/views/components/stats/insights/mobile/validator-row.blade.php b/resources/views/components/stats/insights/mobile/validator-row.blade.php index 8a6105961..14fc52539 100644 --- a/resources/views/components/stats/insights/mobile/validator-row.blade.php +++ b/resources/views/components/stats/insights/mobile/validator-row.blade.php @@ -19,7 +19,7 @@ href="{{ route('wallet', $model->model()) }}" class="link" > - {{ $model->username() }} + {{ $model->address() }} @endif
diff --git a/resources/views/components/tables/desktop/skeleton/transaction-recipients.blade.php b/resources/views/components/tables/desktop/skeleton/transaction-recipients.blade.php deleted file mode 100644 index 47a0d0fea..000000000 --- a/resources/views/components/tables/desktop/skeleton/transaction-recipients.blade.php +++ /dev/null @@ -1,20 +0,0 @@ -@props([ - 'rowCount' => 10, - 'paginator' => null, -]) - - diff --git a/resources/views/components/tables/desktop/top-accounts.blade.php b/resources/views/components/tables/desktop/top-accounts.blade.php index 3d54a834b..23de253ff 100644 --- a/resources/views/components/tables/desktop/top-accounts.blade.php +++ b/resources/views/components/tables/desktop/top-accounts.blade.php @@ -58,11 +58,7 @@ class="text-right" - - - - - +
- @elseif ($transaction->isMultiPayment()) - - - @endif
diff --git a/resources/views/components/transaction/page/participant-list.blade.php b/resources/views/components/transaction/page/participant-list.blade.php deleted file mode 100644 index 105a94ed7..000000000 --- a/resources/views/components/transaction/page/participant-list.blade.php +++ /dev/null @@ -1,11 +0,0 @@ -@props(['transaction']) - - - - - - diff --git a/resources/views/components/transaction/page/recipient-list.blade.php b/resources/views/components/transaction/page/recipient-list.blade.php deleted file mode 100644 index 7791550e6..000000000 --- a/resources/views/components/transaction/page/recipient-list.blade.php +++ /dev/null @@ -1,12 +0,0 @@ -@props(['transaction']) - - - - - - diff --git a/resources/views/components/transaction/page/section-detail/recipients.blade.php b/resources/views/components/transaction/page/section-detail/recipients.blade.php deleted file mode 100644 index 40c1c0a0c..000000000 --- a/resources/views/components/transaction/page/section-detail/recipients.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -@props(['transaction']) - - - @lang('pages.transaction.value.multiple_x', ['count' => $transaction->recipientsCount()]) - diff --git a/resources/views/components/transaction/page/summary.blade.php b/resources/views/components/transaction/page/summary.blade.php index 4754bb8ad..420541d99 100644 --- a/resources/views/components/transaction/page/summary.blade.php +++ b/resources/views/components/transaction/page/summary.blade.php @@ -1,7 +1,7 @@ @props(['transaction']) - @if ($transaction->isTransfer() || $transaction->isMultiPayment()) + @if ($transaction->isTransfer()) @endif - @elseif ($transaction->isMultisignature()) - - - - - @elseif ($transaction->isValidatorRegistration() || $transaction->isValidatorResignation()) - @elseif ($transaction->isUsernameRegistration() || $transaction->isUsernameResignation()) - @endif diff --git a/resources/views/components/validators/monitor/data-boxes.blade.php b/resources/views/components/validators/monitor/data-boxes.blade.php index 1c1e325d7..5b4c7c852 100644 --- a/resources/views/components/validators/monitor/data-boxes.blade.php +++ b/resources/views/components/validators/monitor/data-boxes.blade.php @@ -61,11 +61,7 @@ class="grid grid-cols-1 gap-2 w-full sm:grid-cols-2 md:gap-3 xl:grid-cols-4" href="{{ route('wallet', $statistics['nextValidator']->model()) }}" class="link" > - @if ($statistics['nextValidator']->hasUsername()) - {{ $statistics['nextValidator']->username() }} - @else - {{ $statistics['nextValidator']->address() }} - @endif + {{ $statistics['nextValidator']->address() }} @else diff --git a/resources/views/components/wallet/overview/wallet.blade.php b/resources/views/components/wallet/overview/wallet.blade.php index 57725f173..1874b4690 100644 --- a/resources/views/components/wallet/overview/wallet.blade.php +++ b/resources/views/components/wallet/overview/wallet.blade.php @@ -3,7 +3,7 @@ diff --git a/resources/views/livewire/modals/export-blocks.blade.php b/resources/views/livewire/modals/export-blocks.blade.php index 165885d50..10af6b9e6 100644 --- a/resources/views/livewire/modals/export-blocks.blade.php +++ b/resources/views/livewire/modals/export-blocks.blade.php @@ -59,9 +59,9 @@ class="flex justify-center items-center py-1.5 space-x-2 w-full sm:px-4 button-s
@@ -69,8 +69,8 @@ class="flex justify-center items-center py-1.5 space-x-2 w-full sm:px-4 button-s diff --git a/resources/views/livewire/transaction/recipient-list.blade.php b/resources/views/livewire/transaction/recipient-list.blade.php deleted file mode 100644 index b46aff39b..000000000 --- a/resources/views/livewire/transaction/recipient-list.blade.php +++ /dev/null @@ -1,18 +0,0 @@ -
- - - - - - - - - -
diff --git a/tests/Feature/Http/Controllers/ShowTransactionControllerTest.php b/tests/Feature/Http/Controllers/ShowTransactionControllerTest.php index 5007bf8c5..5d3fccf03 100644 --- a/tests/Feature/Http/Controllers/ShowTransactionControllerTest.php +++ b/tests/Feature/Http/Controllers/ShowTransactionControllerTest.php @@ -17,10 +17,7 @@ })->with([ 'transfer', 'validatorRegistration', - 'multiSignature', 'validatorResignation', - 'usernameRegistration', - 'usernameResignation', ]); it('should render the page for a vote/unvote transaction without any errors', function ($type) { diff --git a/tests/Feature/Http/Controllers/ShowWalletControllerTest.php b/tests/Feature/Http/Controllers/ShowWalletControllerTest.php index 9f3b96f9e..55120fafe 100644 --- a/tests/Feature/Http/Controllers/ShowWalletControllerTest.php +++ b/tests/Feature/Http/Controllers/ShowWalletControllerTest.php @@ -61,7 +61,7 @@ $response = $this ->get(route('wallet', $wallet)) - ->assertSee($wallet->username()) + ->assertSee($wallet->walletName()) ->assertSee('0 BTC'); $content = preg_replace('/\s+/', ' ', str_replace("\n", '', strip_tags($response->getContent()))); @@ -81,7 +81,7 @@ $response = $this ->get(route('wallet', $wallet)) - ->assertSee($wallet->username()) + ->assertSee($wallet->walletName()) ->assertSeeInOrder([ $wallet->balance->toFloat(), '£0.00', @@ -102,7 +102,7 @@ $this ->get(route('wallet', $wallet)) - ->assertSee($wallet->username()) + ->assertSee($wallet->walletName()) ->assertSeeInOrder([ 'Value', 'N/A', @@ -194,7 +194,7 @@ $this ->get(route('wallet', $wallet)) - ->assertSee($wallet->username()) + ->assertSee($wallet->walletName()) ->assertSeeInOrder([ '12,340 DARK', 'Vote', diff --git a/tests/Feature/Http/Livewire/BlockTableTest.php b/tests/Feature/Http/Livewire/BlockTableTest.php index d43c131e9..15e1b7cee 100644 --- a/tests/Feature/Http/Livewire/BlockTableTest.php +++ b/tests/Feature/Http/Livewire/BlockTableTest.php @@ -35,7 +35,6 @@ foreach (ViewModelFactory::paginate(Block::withScope(OrderByTimestampScope::class)->paginate())->items() as $block) { $component->assertSee($block->id()); $component->assertSee($block->timestamp()); - $component->assertSee($block->username()); $component->assertSee(NumberFormatter::number($block->height())); $component->assertSee(NumberFormatter::number($block->transactionCount())); $component->assertSeeInOrder([ diff --git a/tests/Feature/Http/Livewire/Home/BlocksTest.php b/tests/Feature/Http/Livewire/Home/BlocksTest.php index ce6de1ed1..cde933c15 100644 --- a/tests/Feature/Http/Livewire/Home/BlocksTest.php +++ b/tests/Feature/Http/Livewire/Home/BlocksTest.php @@ -21,7 +21,6 @@ foreach (ViewModelFactory::collection(Block::withScope(OrderByHeightScope::class)->take(15)->get()) as $block) { $component->assertSee($block->id()); $component->assertSee($block->timestamp()); - $component->assertSee($block->username()); $component->assertSee(NumberFormatter::number($block->height())); $component->assertSee(NumberFormatter::number($block->transactionCount())); $component->assertSeeInOrder([ diff --git a/tests/Feature/Http/Livewire/Modals/ExportBlocksTest.php b/tests/Feature/Http/Livewire/Modals/ExportBlocksTest.php index 4130c08d4..9f4587d7c 100644 --- a/tests/Feature/Http/Livewire/Modals/ExportBlocksTest.php +++ b/tests/Feature/Http/Livewire/Modals/ExportBlocksTest.php @@ -13,7 +13,6 @@ Livewire::test(ExportBlocks::class, [$wallet]) ->assertSet('publicKey', $wallet->publicKey()) - ->assertSet('username', $wallet->username()) ->assertSee(trans('actions.export')) ->assertDontSee(trans('pages.wallet.export-blocks-modal.title')); }); @@ -23,7 +22,6 @@ Livewire::test(ExportBlocks::class, [$wallet]) ->assertSet('publicKey', $wallet->publicKey()) - ->assertSet('username', null) ->assertSee(trans('actions.export')) ->assertDontSee(trans('pages.wallet.export-blocks-modal.title')); }); @@ -33,7 +31,6 @@ Livewire::test(ExportBlocks::class, [$wallet]) ->assertSet('publicKey', $wallet->publicKey()) - ->assertSet('username', $wallet->username()) ->assertSee(trans('actions.export')) ->assertDontSee(trans('pages.wallet.export-blocks-modal.title')) ->call('openModal') @@ -45,7 +42,6 @@ Livewire::test(ExportBlocks::class, [$wallet]) ->assertSet('publicKey', $wallet->publicKey()) - ->assertSet('username', $wallet->username()) ->assertSee(trans('actions.export')) ->call('openModal') ->assertSee(trans('pages.wallet.export-blocks-modal.title')) diff --git a/tests/Feature/Http/Livewire/Navbar/SearchTest.php b/tests/Feature/Http/Livewire/Navbar/SearchTest.php index c698a28fb..0c3fd7a55 100644 --- a/tests/Feature/Http/Livewire/Navbar/SearchTest.php +++ b/tests/Feature/Http/Livewire/Navbar/SearchTest.php @@ -34,27 +34,6 @@ ->assertDontSee($otherWallet->address); }); -it('should search for a wallet username over a block generator', function () { - $wallet = Wallet::factory()->create([ - 'attributes' => [ - 'validator' => [ - 'username' => 'pieface', - ], - ], - ]); - $block = Block::factory()->create([ - 'generator_address' => $wallet->address, - ]); - - Transaction::factory() - ->transfer() - ->create(['block_id' => $block->id]); - - Livewire::test(Search::class) - ->set('query', $wallet->address) - ->assertSee($wallet->address); -}); - it('should search for a transaction', function () { Transaction::factory() ->transfer() diff --git a/tests/Feature/Http/Livewire/SearchModalTest.php b/tests/Feature/Http/Livewire/SearchModalTest.php index 22ff381d3..7f7a86ddb 100644 --- a/tests/Feature/Http/Livewire/SearchModalTest.php +++ b/tests/Feature/Http/Livewire/SearchModalTest.php @@ -22,25 +22,6 @@ ->assertDontSee($otherWallet->address); }); -it('should search for a wallet username over a block generator', function () { - $wallet = Wallet::factory()->create([ - 'attributes' => [ - 'validator' => [ - 'username' => 'pieface', - ], - ], - ]); - $block = Block::factory()->create([ - 'generator_address' => $wallet->address, - ]); - Transaction::factory()->create(['block_id' => $block->id]); - - Livewire::test(SearchModal::class) - ->dispatch('openSearchModal') - ->set('query', $wallet->address) - ->assertSee($wallet->address); -}); - it('should search for a transaction', function () { Transaction::factory()->create(); $block = Block::factory()->create(); diff --git a/tests/Feature/Http/Livewire/Stats/CurrentAverageFeeTest.php b/tests/Feature/Http/Livewire/Stats/CurrentAverageFeeTest.php index c0a91565e..eeb13717e 100644 --- a/tests/Feature/Http/Livewire/Stats/CurrentAverageFeeTest.php +++ b/tests/Feature/Http/Livewire/Stats/CurrentAverageFeeTest.php @@ -2,11 +2,9 @@ declare(strict_types=1); -use App\Enums\TransactionTypeEnum; use App\Http\Livewire\Stats\CurrentAverageFee; use App\Models\Transaction; use Carbon\Carbon; -use Illuminate\Database\Eloquent\Factories\Sequence; use Illuminate\Support\Facades\Artisan; use Livewire\Livewire; @@ -15,25 +13,7 @@ }); it('should render the component', function () { - Transaction::factory(5) - ->state(new Sequence( - ['fee' => 1 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 25 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 50 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 75 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 100 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - )) - ->create(); - - Transaction::factory(5) - ->state(new Sequence( - ['fee' => 2 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 24 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 50 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 71 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 99 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - )) - ->create(); + Transaction::factory(5)->create(); Artisan::call('explorer:cache-fees'); @@ -46,36 +26,3 @@ ->assertSee(trans('pages.statistics.information-cards.max-fee')) ->assertSee('100 DARK'); }); - -it('should filter by transfer', function () { - Transaction::factory(5) - ->state(new Sequence( - ['fee' => 1 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 25 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 50 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 75 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - ['fee' => 100 * 1e18, 'type' => TransactionTypeEnum::TRANSFER], - )) - ->create(); - - Transaction::factory(5) - ->state(new Sequence( - ['fee' => 2 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 24 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 50 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 71 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - ['fee' => 99 * 1e18, 'type' => TransactionTypeEnum::MULTI_SIGNATURE], - )) - ->create(); - - Artisan::call('explorer:cache-fees'); - - Livewire::test(CurrentAverageFee::class) - ->set('transactionType', 'multiSignature') - ->assertSee(trans('pages.statistics.information-cards.current-average-fee', ['type' => 'Multisignature'])) - ->assertSee('49.2 DARK') - ->assertSee(trans('pages.statistics.information-cards.min-fee')) - ->assertSee('2 DARK') - ->assertSee(trans('pages.statistics.information-cards.max-fee')) - ->assertSee('99 DARK'); -}); diff --git a/tests/Feature/Http/Livewire/Transaction/RecipientListTest.php b/tests/Feature/Http/Livewire/Transaction/RecipientListTest.php deleted file mode 100644 index 1c12f012a..000000000 --- a/tests/Feature/Http/Livewire/Transaction/RecipientListTest.php +++ /dev/null @@ -1,75 +0,0 @@ -create(); - $recipient2 = Wallet::factory()->create(); - $recipient3 = Wallet::factory()->create(); - - $transaction = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $recipient1->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient2->address, - 'amount' => 2 * 1e18, - ], - [ - 'recipientId' => $recipient3->address, - 'amount' => 3 * 1e18, - ], - ], - ], - ]); - - Livewire::test(RecipientList::class, ['transactionId' => $transaction->id]) - ->call('setIsReady') - ->assertSeeInOrder([ - $recipient3->address, - $recipient2->address, - $recipient1->address, - ]); -}); - -it('should defer loading', function () { - $recipient1 = Wallet::factory()->create(); - $recipient2 = Wallet::factory()->create(); - $recipient3 = Wallet::factory()->create(); - - $transaction = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $recipient1->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient2->address, - 'amount' => 2 * 1e18, - ], - [ - 'recipientId' => $recipient3->address, - 'amount' => 3 * 1e18, - ], - ], - ], - ]); - - Livewire::test(RecipientList::class, ['transactionId' => $transaction->id]) - ->assertDontSee($recipient3->address) - ->assertDontSee($recipient2->address) - ->assertDontSee($recipient1->address) - ->call('setIsReady') - ->assertSee($recipient3->address) - ->assertSee($recipient2->address) - ->assertSee($recipient1->address); -}); diff --git a/tests/Feature/Http/Livewire/TransactionTableTest.php b/tests/Feature/Http/Livewire/TransactionTableTest.php index fd632e381..d626419b2 100644 --- a/tests/Feature/Http/Livewire/TransactionTableTest.php +++ b/tests/Feature/Http/Livewire/TransactionTableTest.php @@ -73,27 +73,24 @@ Livewire::test(TransactionTable::class) ->call('setIsReady') ->assertSet('filter', [ - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]) ->assertSet('selectAllFilters', true) ->set('filter.transfers', true) ->assertSet('selectAllFilters', true) ->set('selectAllFilters', false) ->assertSet('filter', [ - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'transfers' => false, + 'votes' => false, + 'others' => false, ]) ->set('selectAllFilters', true) ->assertSet('filter', [ - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]); }); @@ -101,10 +98,9 @@ Livewire::test(TransactionTable::class) ->call('setIsReady') ->assertSet('filter', [ - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]) ->assertSet('selectAllFilters', true) ->set('filter.transfers', false) @@ -128,10 +124,9 @@ Livewire::test(TransactionTable::class) ->call('setIsReady') ->set('filter', [ - 'transfers' => true, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'transfers' => true, + 'votes' => false, + 'others' => false, ]) ->assertSee($transfer->id) ->assertDontSee($vote->id); @@ -152,53 +147,27 @@ Livewire::test(TransactionTable::class) ->call('setIsReady') ->set('filter', [ - 'transfers' => false, - 'votes' => true, - 'multipayments' => false, - 'others' => false, + 'transfers' => false, + 'votes' => true, + 'others' => false, ]) ->assertSee($vote->id) ->assertDontSee($transfer->id); }); -it('should filter by multipayment transactions', function () { - $transfer = Transaction::factory()->transfer()->create(); - - $multipayment = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [], - ], - ]); - - Livewire::test(TransactionTable::class) - ->call('setIsReady') - ->set('filter', [ - 'transfers' => false, - 'votes' => false, - 'multipayments' => true, - 'others' => false, - ]) - ->assertSee($multipayment->id) - ->assertDontSee($transfer->id); -}); - it('should filter by other transactions', function () { $transfer = Transaction::factory()->transfer()->create(); $validatorRegistration = Transaction::factory()->validatorRegistration()->create(); - $usernameRegistration = Transaction::factory()->usernameRegistration()->create(); - Livewire::test(TransactionTable::class) ->call('setIsReady') ->set('filter', [ - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => true, + 'transfers' => false, + 'votes' => false, + 'others' => true, ]) ->assertSee($validatorRegistration->id) - ->assertSee($usernameRegistration->id) ->assertDontSee($transfer->id); }); @@ -207,19 +176,15 @@ $validatorRegistration = Transaction::factory()->validatorRegistration()->create(); - $usernameRegistration = Transaction::factory()->usernameRegistration()->create(); - Livewire::test(TransactionTable::class) ->call('setIsReady') ->set('filter', [ - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'transfers' => false, + 'votes' => false, + 'others' => false, ]) ->assertDontSee($transfer->id) ->assertDontSee($validatorRegistration->id) - ->assertDontSee($usernameRegistration->id) ->assertSee(trans('tables.transactions.no_results.no_filters')); }); @@ -227,16 +192,14 @@ $instance = Livewire::test(TransactionTable::class) ->call('setIsReady') ->set('filter', [ - 'transfers' => false, - 'votes' => true, - 'multipayments' => false, - 'others' => true, + 'transfers' => false, + 'votes' => true, + 'others' => true, ]) ->instance(); expect($instance->transfers)->toBeFalse(); expect($instance->votes)->toBeTrue(); - expect($instance->multipayments)->toBeFalse(); expect($instance->others)->toBeTrue(); }); @@ -244,21 +207,18 @@ $instance = Livewire::test(TransactionTable::class) ->call('setIsReady') ->set('filter', [ - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'transfers' => false, + 'votes' => false, + 'others' => false, ]) ->instance(); - $instance->transfers = true; - $instance->votes = true; - $instance->multipayments = true; - $instance->others = true; + $instance->transfers = true; + $instance->votes = true; + $instance->others = true; expect($instance->transfers)->toBeTrue(); expect($instance->votes)->toBeTrue(); - expect($instance->multipayments)->toBeTrue(); expect($instance->others)->toBeTrue(); }); diff --git a/tests/Feature/Http/Livewire/Validators/MonitorTest.php b/tests/Feature/Http/Livewire/Validators/MonitorTest.php index 565fddca0..c25ce2717 100644 --- a/tests/Feature/Http/Livewire/Validators/MonitorTest.php +++ b/tests/Feature/Http/Livewire/Validators/MonitorTest.php @@ -219,7 +219,7 @@ function forgeBlock(string $address, int $height): void ->call('setIsReady') ->call('pollValidators') ->assertSeeInOrder([ - $validator->username(), + $validator->walletName(), 'Validator last forged 207 blocks ago (~ 28 min)', ]); }); @@ -257,7 +257,7 @@ function forgeBlock(string $address, int $height): void ->call('setIsReady') ->call('pollValidators') ->assertSeeInOrder([ - $validator->username(), + $validator->walletName(), 'Validator last forged 207 blocks ago (~ 1h 28 min)', ]); }); @@ -295,7 +295,7 @@ function forgeBlock(string $address, int $height): void ->call('setIsReady') ->call('pollValidators') ->assertSeeInOrder([ - $validator->username(), + $validator->walletName(), 'Validator last forged 207 blocks ago (more than a day)', ]); }); @@ -331,7 +331,7 @@ function forgeBlock(string $address, int $height): void ->call('setIsReady') ->dispatch('echo:blocks,NewBlock') ->assertSeeInOrder([ - $validator->username(), + $validator->walletName(), 'Validator last forged 199 blocks ago (more than a day)', ]); }); diff --git a/tests/Feature/Http/Livewire/WalletTablesTest.php b/tests/Feature/Http/Livewire/WalletTablesTest.php index 7f4d088c8..7c4d225d1 100644 --- a/tests/Feature/Http/Livewire/WalletTablesTest.php +++ b/tests/Feature/Http/Livewire/WalletTablesTest.php @@ -51,14 +51,13 @@ ->assertSet('tabQueryData', [ 'transactions' => [ - 'paginators' => ['page' => 1], - 'perPage' => WalletTransactionTable::defaultPerPage(), - 'outgoing' => true, - 'incoming' => true, - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'paginators' => ['page' => 1], + 'perPage' => WalletTransactionTable::defaultPerPage(), + 'outgoing' => true, + 'incoming' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ], 'blocks' => [ @@ -193,14 +192,13 @@ expect($instance->tabQueryData)->toBe([ 'transactions' => [ - 'perPage' => WalletTransactionTable::defaultPerPage(), - 'outgoing' => true, - 'incoming' => true, - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, - 'paginators' => ['page' => 1], + 'perPage' => WalletTransactionTable::defaultPerPage(), + 'outgoing' => true, + 'incoming' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, + 'paginators' => ['page' => 1], ], 'blocks' => [ diff --git a/tests/Feature/Http/Livewire/WalletTransactionTableTest.php b/tests/Feature/Http/Livewire/WalletTransactionTableTest.php index a9e65621f..7e5d1f7c0 100644 --- a/tests/Feature/Http/Livewire/WalletTransactionTableTest.php +++ b/tests/Feature/Http/Livewire/WalletTransactionTableTest.php @@ -98,147 +98,6 @@ ]); }); -it('should show sent multipayment', function () { - $recipient1 = Wallet::factory()->create(); - $recipient2 = Wallet::factory()->create(); - $recipient3 = Wallet::factory()->create(); - - $sent = Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $this->subject->public_key, - 'recipient_id' => $this->subject->address, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $recipient1->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient2->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient3->address, - 'amount' => 1 * 1e18, - ], - ], - ], - ]); - - $component = Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) - ->call('setIsReady'); - - $transaction = ViewModelFactory::make($sent); - - $component->assertSee($transaction->id()); - $component->assertSee($transaction->timestamp()); - $component->assertDontSee(sprintf( - '%s…%s', - substr($this->subject->address, 0, 5), - substr($this->subject->address, -5) - )); - $component->assertSeeInOrder(['Multiple', '(3)']); - $component->assertSeeInOrder([ - '-', - $transaction->amount(), - $transaction->fee(), - ]); -}); - -it('should show received multipayment', function () { - $sender = Wallet::factory()->create(); - $recipient2 = Wallet::factory()->create(); - $recipient3 = Wallet::factory()->create(); - - $received = Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $sender->public_key, - 'recipient_id' => $sender->address, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $this->subject->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient2->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient3->address, - 'amount' => 1 * 1e18, - ], - ], - ], - ]); - - $component = Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) - ->call('setIsReady'); - - $transaction = ViewModelFactory::make($received); - - $component->assertSee($transaction->id()); - $component->assertSee($transaction->timestamp()); - $component->assertSee(sprintf( - '%s…%s', - substr($sender->address, 0, 5), - substr($sender->address, -5) - )); - $component->assertDontSee('Multiple'); - $component->assertSeeInOrder([ - '-', - $transaction->amount(), - $transaction->fee(), - ]); -}); - -it('should show multipayment without amount sent to self', function () { - $recipient1 = Wallet::factory()->create(); - $recipient2 = Wallet::factory()->create(); - - $sent = Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $this->subject->public_key, - 'recipient_id' => $this->subject->address, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $recipient1->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient2->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $this->subject->address, - 'amount' => 1 * 1e18, - ], - ], - ], - ]); - - $component = Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) - ->call('setIsReady'); - - $transaction = ViewModelFactory::make($sent); - - $component->assertSee($transaction->id()); - $component->assertSee($transaction->timestamp()); - $component->assertDontSee(sprintf( - '%s…%s', - substr($this->subject->address, 0, 5), - substr($this->subject->address, -5) - )); - $component->assertSeeInOrder(['Multiple', '(3)']); - $component->assertSeeInOrder([ - 'Excluding 1 DARK sent to self', - '-', - $transaction->amountExcludingItself(), - $transaction->fee(), - ]); -}); - it('should show transfer without amount sent to self', function () { $sent = Transaction::factory()->transfer()->create([ 'sender_public_key' => $this->subject->public_key, @@ -268,33 +127,30 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->assertSet('filter', [ - 'outgoing' => true, - 'incoming' => true, - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'outgoing' => true, + 'incoming' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]) ->assertSet('selectAllFilters', true) ->set('filter.outgoing', true) ->assertSet('selectAllFilters', true) ->set('selectAllFilters', false) ->assertSet('filter', [ - 'outgoing' => false, - 'incoming' => false, - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'outgoing' => false, + 'incoming' => false, + 'transfers' => false, + 'votes' => false, + 'others' => false, ]) ->set('selectAllFilters', true) ->assertSet('filter', [ - 'outgoing' => true, - 'incoming' => true, - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'outgoing' => true, + 'incoming' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]); }); @@ -302,12 +158,11 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->assertSet('filter', [ - 'outgoing' => true, - 'incoming' => true, - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'outgoing' => true, + 'incoming' => true, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]) ->assertSet('selectAllFilters', true) ->set('filter.outgoing', false) @@ -328,12 +183,11 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => true, - 'incoming' => false, - 'transfers' => true, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'outgoing' => true, + 'incoming' => false, + 'transfers' => true, + 'votes' => false, + 'others' => false, ]) ->assertSee($sent->id) ->assertDontSee($received->id); @@ -351,56 +205,11 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => false, - 'incoming' => true, - 'transfers' => true, - 'votes' => false, - 'multipayments' => false, - 'others' => false, - ]) - ->assertSee($received->id) - ->assertDontSee($sent->id); -}); - -it('should show multipayments when filtered by incoming transactions', function () { - $sent = Transaction::factory()->transfer()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - - $multiPaymentSender = Wallet::factory()->create(); - $recipient2 = Wallet::factory()->create(); - $recipient3 = Wallet::factory()->create(); - $received = Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $multiPaymentSender->public_key, - 'recipient_id' => $multiPaymentSender->address, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $this->subject->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient2->address, - 'amount' => 1 * 1e18, - ], - [ - 'recipientId' => $recipient3->address, - 'amount' => 1 * 1e18, - ], - ], - ], - ]); - - Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) - ->call('setIsReady') - ->set('filter', [ - 'outgoing' => false, - 'incoming' => true, - 'transfers' => true, - 'votes' => false, - 'multipayments' => true, - 'others' => false, + 'outgoing' => false, + 'incoming' => true, + 'transfers' => true, + 'votes' => false, + 'others' => false, ]) ->assertSee($received->id) ->assertDontSee($sent->id); @@ -418,12 +227,11 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => true, - 'incoming' => true, - 'transfers' => true, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'outgoing' => true, + 'incoming' => true, + 'transfers' => true, + 'votes' => false, + 'others' => false, ]) ->assertSee($sent->id) ->assertSee($received->id); @@ -444,12 +252,11 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => true, - 'incoming' => false, - 'transfers' => true, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'outgoing' => true, + 'incoming' => false, + 'transfers' => true, + 'votes' => false, + 'others' => false, ]) ->assertSee($transfer->id) ->assertDontSee($vote->id); @@ -470,40 +277,16 @@ Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => true, - 'incoming' => false, - 'transfers' => false, - 'votes' => true, - 'multipayments' => false, - 'others' => false, + 'outgoing' => true, + 'incoming' => false, + 'transfers' => false, + 'votes' => true, + 'others' => false, ]) ->assertSee($vote->id) ->assertDontSee($transfer->id); }); -it('should filter by multipayment transactions', function () { - $transfer = Transaction::factory()->transfer()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - - $multipayment = Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - - Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) - ->call('setIsReady') - ->set('filter', [ - 'outgoing' => true, - 'incoming' => false, - 'transfers' => false, - 'votes' => false, - 'multipayments' => true, - 'others' => false, - ]) - ->assertSee($multipayment->id) - ->assertDontSee($transfer->id); -}); - it('should filter by other transactions', function () { $transfer = Transaction::factory()->transfer()->create([ 'sender_public_key' => $this->subject->public_key, @@ -513,22 +296,16 @@ 'sender_public_key' => $this->subject->public_key, ]); - $usernameRegistration = Transaction::factory()->usernameRegistration()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => true, - 'incoming' => false, - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => true, + 'outgoing' => true, + 'incoming' => false, + 'transfers' => false, + 'votes' => false, + 'others' => true, ]) ->assertSee($validatorRegistration->id) - ->assertSee($usernameRegistration->id) ->assertDontSee($transfer->id); }); @@ -541,23 +318,17 @@ 'sender_public_key' => $this->subject->public_key, ]); - $usernameRegistration = Transaction::factory()->usernameRegistration()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => false, - 'incoming' => false, - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'outgoing' => false, + 'incoming' => false, + 'transfers' => false, + 'votes' => false, + 'others' => false, ]) ->assertDontSee($transfer->id) ->assertDontSee($validatorRegistration->id) - ->assertDontSee($usernameRegistration->id) ->assertSee(trans('tables.transactions.no_results.no_filters')); }); @@ -570,23 +341,17 @@ 'sender_public_key' => $this->subject->public_key, ]); - $usernameRegistration = Transaction::factory()->usernameRegistration()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => false, - 'incoming' => false, - 'transfers' => true, - 'votes' => true, - 'multipayments' => true, - 'others' => true, + 'outgoing' => false, + 'incoming' => false, + 'transfers' => true, + 'votes' => true, + 'others' => true, ]) ->assertDontSee($transfer->id) ->assertDontSee($validatorRegistration->id) - ->assertDontSee($usernameRegistration->id) ->assertSee(trans('tables.transactions.no_results.no_addressing_filters')); }); @@ -599,23 +364,17 @@ 'sender_public_key' => $this->subject->public_key, ]); - $usernameRegistration = Transaction::factory()->usernameRegistration()->create([ - 'sender_public_key' => $this->subject->public_key, - ]); - Livewire::test(WalletTransactionTable::class, [new WalletViewModel($this->subject)]) ->call('setIsReady') ->set('filter', [ - 'outgoing' => true, - 'incoming' => true, - 'transfers' => false, - 'votes' => false, - 'multipayments' => false, - 'others' => false, + 'outgoing' => true, + 'incoming' => true, + 'transfers' => false, + 'votes' => false, + 'others' => false, ]) ->assertDontSee($transfer->id) ->assertDontSee($validatorRegistration->id) - ->assertDontSee($usernameRegistration->id) ->assertSee(trans('tables.transactions.no_results.no_results')); }); diff --git a/tests/Unit/Console/Commands/CacheKnownWalletsTest.php b/tests/Unit/Console/Commands/CacheKnownWalletsTest.php new file mode 100644 index 000000000..0aebad3e2 --- /dev/null +++ b/tests/Unit/Console/Commands/CacheKnownWalletsTest.php @@ -0,0 +1,31 @@ + 'team', + 'name' => 'Hot Wallet', + 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', + ], + ], 200)); + + $knownWallet = Wallet::factory()->create([ + 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', + ]); + + (new CacheKnownWallets())->handle(); + + expect(Cache::tags('wallet')->get(md5("name_by_address/$knownWallet->address")))->toBe('Hot Wallet'); +}); diff --git a/tests/Unit/Console/Commands/CacheMultiSignatureAddressesTest.php b/tests/Unit/Console/Commands/CacheMultiSignatureAddressesTest.php deleted file mode 100644 index 2cb262310..000000000 --- a/tests/Unit/Console/Commands/CacheMultiSignatureAddressesTest.php +++ /dev/null @@ -1,20 +0,0 @@ -create([ - 'attributes' => ['multiSignature' => []], - ]); - - (new CacheMultiSignatureAddresses())->handle(); - - Queue::assertPushed(CacheMultiSignatureAddress::class, 10); -}); diff --git a/tests/Unit/Console/Commands/CacheUsernamesTest.php b/tests/Unit/Console/Commands/CacheUsernamesTest.php deleted file mode 100644 index 3f50db2cf..000000000 --- a/tests/Unit/Console/Commands/CacheUsernamesTest.php +++ /dev/null @@ -1,98 +0,0 @@ -create([ - 'attributes->username' => 'testuser', - ]); - - expect(Cache::tags('wallet')->has(md5("username_by_address/$wallet->address")))->toBeFalse(); - expect(Cache::tags('wallet')->has(md5("username_by_public_key/$wallet->public_key")))->toBeFalse(); - - (new CacheUsernames())->handle(); - - expect(Cache::tags('wallet')->has(md5("username_by_address/$wallet->address")))->toBeTrue(); - expect(Cache::tags('wallet')->has(md5("username_by_public_key/$wallet->public_key")))->toBeTrue(); - - expect(Cache::tags('wallet')->get(md5("username_by_address/$wallet->address")))->toBeString(); - expect(Cache::tags('wallet')->get(md5("username_by_public_key/$wallet->public_key")))->toBeString(); -}); - -it('should cache the known wallet name if defined', function () { - $knownWalletsUrl = 'https://knownwallets.com/known-wallets.json'; - - Config::set('arkscan.networks.development.knownWallets', $knownWalletsUrl); - - Http::fake(Http::response([ - [ - 'type' => 'team', - 'name' => 'Hot Wallet', - 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', - ], - ], 200)); - - $knownWallet = Wallet::factory()->create([ - 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', - ]); - - $regularWallet = Wallet::factory()->create([ - 'attributes->username' => 'regular', - ]); - - (new CacheUsernames())->handle(); - - expect(Cache::tags('wallet')->get(md5("username_by_address/$knownWallet->address")))->toBe('Hot Wallet'); - expect(Cache::tags('wallet')->get(md5("username_by_address/$regularWallet->address")))->toBe('regular'); -}); - -it('should cache the known wallet name if doesnt have validator name', function () { - $knownWalletsUrl = 'https://knownwallets.com/known-wallets.json'; - - Config::set('arkscan.networks.development.knownWallets', $knownWalletsUrl); - - Http::fake(Http::response([ - [ - 'type' => 'team', - 'name' => 'Hot Wallet', - 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', - ], - ], 200)); - - $wallet = Wallet::factory()->create([ - 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', - 'attributes->username' => null, - ]); - - (new CacheUsernames())->handle(); - - expect(Cache::tags('wallet')->get(md5("username_by_address/$wallet->address")))->toBe('Hot Wallet'); -}); - -it('should forget wallets with resigned usernames', function () { - $cache = new WalletCache(); - $wallet = Wallet::factory()->create([ - 'address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', - 'attributes->username' => 'joeblogs', - ]); - - (new CacheUsernames())->handle(); - - expect($cache->getUsernameByAddress($wallet->address))->toBe('joeblogs'); - - Transaction::factory()->usernameResignation()->create([ - 'sender_public_key' => $wallet->public_key, - ]); - - (new CacheUsernames())->handle(); - - expect($cache->getUsernameByAddress($wallet->address))->toBeNull(); -}); diff --git a/tests/Unit/DTO/MemoryWalletTest.php b/tests/Unit/DTO/MemoryWalletTest.php index 8e89b80dd..a4855f5a7 100644 --- a/tests/Unit/DTO/MemoryWalletTest.php +++ b/tests/Unit/DTO/MemoryWalletTest.php @@ -10,7 +10,7 @@ expect($subject->address())->toBe('0x6E4C6817a95263B758bbC52e87Ce8e759eD0B084'); expect($subject->publicKey())->toBeNull(); - expect($subject->username())->toBeNull(); + expect($subject->walletName())->toBeNull(); expect($subject->isValidator())->toBeFalse(); }); @@ -19,18 +19,18 @@ expect($subject->address())->toBe('0x6E4C6817a95263B758bbC52e87Ce8e759eD0B084'); expect($subject->publicKey())->toBe('03d3fdad9c5b25bf8880e6b519eb3611a5c0b31adebc8455f0e096175b28321aff'); - expect($subject->username())->toBeNull(); + expect($subject->walletName())->toBeNull(); expect($subject->isValidator())->toBeFalse(); }); it('should be a validator', function () { (new WalletCache())->setValidatorPublicKeyByAddress('0x6E4C6817a95263B758bbC52e87Ce8e759eD0B084', '03d3fdad9c5b25bf8880e6b519eb3611a5c0b31adebc8455f0e096175b28321aff'); - (new WalletCache())->setUsernameByAddress('0x6E4C6817a95263B758bbC52e87Ce8e759eD0B084', 'username'); + (new WalletCache())->setWalletNameByAddress('0x6E4C6817a95263B758bbC52e87Ce8e759eD0B084', 'username'); $subject = MemoryWallet::fromPublicKey('03d3fdad9c5b25bf8880e6b519eb3611a5c0b31adebc8455f0e096175b28321aff'); expect($subject->address())->toBe('0x6E4C6817a95263B758bbC52e87Ce8e759eD0B084'); expect($subject->publicKey())->toBe('03d3fdad9c5b25bf8880e6b519eb3611a5c0b31adebc8455f0e096175b28321aff'); - expect($subject->username())->toBe('username'); + expect($subject->walletName())->toBe('username'); expect($subject->isValidator())->toBeTrue(); }); diff --git a/tests/Unit/DTO/PaymentTest.php b/tests/Unit/DTO/PaymentTest.php index 4d84a04d4..eee169a48 100644 --- a/tests/Unit/DTO/PaymentTest.php +++ b/tests/Unit/DTO/PaymentTest.php @@ -17,6 +17,5 @@ expect($subject->amount())->toBe(1.0); expect($subject->amountFiat())->toBe(NumberFormatter::currency(0, 'USD')); expect($subject->address())->toBe($wallet->address); - expect($subject->username())->toBe($wallet->attributes['username']); expect($subject->recipient())->toBeInstanceOf(Payment::class); }); diff --git a/tests/Unit/Jobs/CacheMultiSignatureAddressTest.php b/tests/Unit/Jobs/CacheMultiSignatureAddressTest.php deleted file mode 100644 index 74b242b2f..000000000 --- a/tests/Unit/Jobs/CacheMultiSignatureAddressTest.php +++ /dev/null @@ -1,33 +0,0 @@ -create([ - 'attributes' => [ - 'multiSignature' => [ - 'min' => $min, - 'publicKeys' => $publicKeys, - ], - ], - ]); - - expect(Cache::tags('wallet')->has(md5("multi_signature/$min/".serialize($publicKeys))))->toBeFalse(); - - (new CacheMultiSignatureAddress($wallet->toArray()))->handle(); - - expect(Cache::tags('wallet')->has(md5("multi_signature/$min/".serialize($publicKeys))))->toBeTrue(); -}); diff --git a/tests/Unit/Models/Scopes/MultiPaymentScopeTest.php b/tests/Unit/Models/Scopes/MultiPaymentScopeTest.php deleted file mode 100644 index 3531184e2..000000000 --- a/tests/Unit/Models/Scopes/MultiPaymentScopeTest.php +++ /dev/null @@ -1,23 +0,0 @@ -subject = new MultiPaymentScope(); -}); - -it('should be an instance of a scope', function () { - expect($this->subject)->toBeInstanceOf(Scope::class); -}); - -it('should be added as a global scope', function () { - expect(Transaction::hasGlobalScope(get_class($this->subject)))->toBeFalse(); - - Transaction::addGlobalScope($this->subject); - - expect(Transaction::hasGlobalScope(get_class($this->subject)))->toBeTrue(); -}); diff --git a/tests/Unit/Models/Scopes/MultiSignatureScopeTest.php b/tests/Unit/Models/Scopes/MultiSignatureScopeTest.php deleted file mode 100644 index f1666335a..000000000 --- a/tests/Unit/Models/Scopes/MultiSignatureScopeTest.php +++ /dev/null @@ -1,23 +0,0 @@ -subject = new MultiSignatureScope(); -}); - -it('should be an instance of a scope', function () { - expect($this->subject)->toBeInstanceOf(Scope::class); -}); - -it('should be added as a global scope', function () { - expect(Transaction::hasGlobalScope(get_class($this->subject)))->toBeFalse(); - - Transaction::addGlobalScope($this->subject); - - expect(Transaction::hasGlobalScope(get_class($this->subject)))->toBeTrue(); -}); diff --git a/tests/Unit/Repositories/WalletRepositoryTest.php b/tests/Unit/Repositories/WalletRepositoryTest.php index 60b252a00..05aa902f8 100644 --- a/tests/Unit/Repositories/WalletRepositoryTest.php +++ b/tests/Unit/Repositories/WalletRepositoryTest.php @@ -22,10 +22,6 @@ expect($this->subject->allWithPublicKey())->toBeInstanceOf(Builder::class); }); -it('should create a query for all wallets with a multi signature', function () { - expect($this->subject->allWithMultiSignature())->toBeInstanceOf(Builder::class); -}); - it('should find a wallet by address', function () { $wallet = Wallet::factory()->create(); diff --git a/tests/Unit/Repositories/WalletRepositoryWithCacheTest.php b/tests/Unit/Repositories/WalletRepositoryWithCacheTest.php index 18a700f67..a57d64638 100644 --- a/tests/Unit/Repositories/WalletRepositoryWithCacheTest.php +++ b/tests/Unit/Repositories/WalletRepositoryWithCacheTest.php @@ -24,10 +24,6 @@ expect($this->subject->allWithPublicKey())->toBeInstanceOf(Builder::class); }); -it('should create a query for all wallets with a multi signature', function () { - expect($this->subject->allWithMultiSignature())->toBeInstanceOf(Builder::class); -}); - it('should find a wallet by address', function () { $wallet = Wallet::factory()->create(); diff --git a/tests/Unit/Services/Addresses/Aggregates/LatestWalletAggregateTest.php b/tests/Unit/Services/Addresses/Aggregates/LatestWalletAggregateTest.php index 058350625..06e51362a 100644 --- a/tests/Unit/Services/Addresses/Aggregates/LatestWalletAggregateTest.php +++ b/tests/Unit/Services/Addresses/Aggregates/LatestWalletAggregateTest.php @@ -180,320 +180,3 @@ 'value' => '01 Jan 2021', ]); }); - -it('should refresh the latest wallet - A > multipayment B', function () { - $this->travelTo('2021-01-01 11:24:44'); - - $cache = new StatisticsCache(); - $aggregate = new LatestWalletAggregate(); - - expect($cache->getNewestAddress())->toBeNull(); - - $walletA = Wallet::factory()->create(['address' => 'wallet-a']); - $walletB = Wallet::factory()->create(['address' => 'wallet-b']); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => 0, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletA->address); - - $genesisTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 13:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 13:24:45'); - - Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => $genesisTimestamp, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $walletB->address, - 'amount' => 1 * 1e8, - ], - ], - ], - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletB->address); - - expect($cache->getNewestAddress())->toBe([ - 'address' => $walletB->address, - 'timestamp' => $genesisTimestamp, - 'value' => '01 Jan 2021', - ]); -}); - -it('should refresh the latest wallet - A > multipayment B or multipayment C', function () { - $this->travelTo('2021-01-01 11:24:44'); - - $cache = new StatisticsCache(); - $aggregate = new LatestWalletAggregate(); - - expect($cache->getNewestAddress())->toBeNull(); - - $walletA = Wallet::factory()->create(['address' => 'wallet-a']); - $walletB = Wallet::factory()->create(['address' => 'wallet-b']); - $walletC = Wallet::factory()->create(['address' => 'wallet-c']); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => 0, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletA->address); - - $genesisTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 13:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 13:24:45'); - - Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => $genesisTimestamp, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $walletB->address, - 'amount' => 1 * 1e8, - ], - [ - 'recipientId' => $walletC->address, - 'amount' => 1 * 1e8, - ], - ], - ], - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect(in_array($result->address, [$walletB->address, $walletC->address], true))->toBeTrue(); - - $newestAddress = $cache->getNewestAddress(); - expect(in_array($newestAddress['address'], [$walletB->address, $walletC->address], true))->toBeTrue(); - expect($newestAddress['timestamp'])->toBe($genesisTimestamp); - expect($newestAddress['value'])->toBe('01 Jan 2021'); -}); - -it('should refresh the latest wallet - multipayment over standard', function () { - $this->travelTo('2021-01-01 11:24:44'); - - $cache = new StatisticsCache(); - $aggregate = new LatestWalletAggregate(); - - expect($cache->getNewestAddress())->toBeNull(); - - $walletA = Wallet::factory()->create(['address' => 'wallet-a']); - $walletB = Wallet::factory()->create(['address' => 'wallet-b']); - $walletC = Wallet::factory()->create(['address' => 'wallet-c']); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => 0, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletA->address); - - $genesisTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 13:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 13:24:45'); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletC->address, - 'timestamp' => $genesisTimestamp, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletC->address); - - $multipaymentTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 14:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 14:24:45'); - - Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => $multipaymentTimestamp, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $walletB->address, - 'amount' => 1 * 1e8, - ], - ], - ], - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletB->address); - - expect($cache->getNewestAddress())->toBe([ - 'address' => $walletB->address, - 'timestamp' => $multipaymentTimestamp, - 'value' => '01 Jan 2021', - ]); -}); - -it('should refresh the latest wallet - standard over multipayment', function () { - $this->travelTo('2021-01-01 11:24:44'); - - $cache = new StatisticsCache(); - $aggregate = new LatestWalletAggregate(); - - expect($cache->getNewestAddress())->toBeNull(); - - $walletA = Wallet::factory()->create(['address' => 'wallet-a']); - $walletB = Wallet::factory()->create(['address' => 'wallet-b']); - $walletC = Wallet::factory()->create(['address' => 'wallet-c']); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => 0, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletA->address); - - $genesisTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 13:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 13:24:45'); - - Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => $genesisTimestamp, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $walletB->address, - 'amount' => 1 * 1e8, - ], - ], - ], - ]); - - $standardTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 14:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 14:24:45'); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletC->address, - 'timestamp' => $standardTimestamp, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletC->address); - - expect($cache->getNewestAddress())->toBe([ - 'address' => $walletC->address, - 'timestamp' => $standardTimestamp, - 'value' => '01 Jan 2021', - ]); -}); - -it('should not take an old wallet with its first multipayment as the newest', function () { - $this->travelTo('2021-01-01 11:24:44'); - - $cache = new StatisticsCache(); - $aggregate = new LatestWalletAggregate(); - - expect($cache->getNewestAddress())->toBeNull(); - - $walletA = Wallet::factory()->create(['address' => 'wallet-a']); - $walletB = Wallet::factory()->create(['address' => 'wallet-b']); - $walletC = Wallet::factory()->create(['address' => 'wallet-c']); - $walletD = Wallet::factory()->create(['address' => 'wallet-d']); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => 0, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletA->address); - - $genesisTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 13:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 13:24:45'); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletC->address, - 'timestamp' => $genesisTimestamp, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletC->address); - - expect($cache->getNewestAddress())->toBe([ - 'address' => $walletC->address, - 'timestamp' => $genesisTimestamp, - 'value' => '01 Jan 2021', - ]); - - $nextTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 13:25:44')->unix())->unix(); - $this->travelTo('2021-01-01 13:25:45'); - - Transaction::factory()->transfer()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletB->address, - 'timestamp' => $nextTimestamp, - ]); - - $result = $aggregate->aggregate(); - expect($result)->not->toBeNull(); - expect($result->address)->toBe($walletB->address); - - expect($cache->getNewestAddress())->toBe([ - 'address' => $walletB->address, - 'timestamp' => $nextTimestamp, - 'value' => '01 Jan 2021', - ]); - - $multipaymentTimestamp = Timestamp::fromUnix(Carbon::parse('2021-01-01 14:24:44')->unix())->unix(); - $this->travelTo('2021-01-01 14:24:45'); - - Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $walletA->public_key, - 'recipient_id' => $walletA->address, - 'timestamp' => $multipaymentTimestamp, - - 'asset' => [ - 'payments' => [ - [ - 'recipientId' => $walletC->address, - 'amount' => 1 * 1e8, - ], - ], - ], - ]); - - $result = $aggregate->aggregate(); - // expect($result)->toBeNull(); - - expect($cache->getNewestAddress())->toBe([ - 'address' => $walletB->address, - 'timestamp' => $nextTimestamp, - 'value' => '01 Jan 2021', - ]); -}); diff --git a/tests/Unit/Services/Cache/WalletCacheTest.php b/tests/Unit/Services/Cache/WalletCacheTest.php index ee200a23f..cc294e424 100644 --- a/tests/Unit/Services/Cache/WalletCacheTest.php +++ b/tests/Unit/Services/Cache/WalletCacheTest.php @@ -55,22 +55,6 @@ expect($this->subject->getVote('address'))->toBeInstanceOf(Wallet::class); }); -it('should get and set the multi signature address', function () { - expect($this->subject->getMultiSignatureAddress(3, [1, 2, 3]))->toBeNull(); - - $this->subject->setMultiSignatureAddress(3, [1, 2, 3], fn () => '123'); - - expect($this->subject->getMultiSignatureAddress(3, [1, 2, 3]))->toBeString(); -}); - -it('should get and set the username by address', function () { - expect($this->subject->getUsernameByAddress('address'))->toBeNull(); - - $this->subject->setUsernameByAddress('address', 'username'); - - expect($this->subject->getUsernameByAddress('address'))->toBeString(); -}); - it('should get and set the missed blocks by address', function () { expect($this->subject->getMissedBlocks('address'))->toBe(0); diff --git a/tests/Unit/Services/FormsTest.php b/tests/Unit/Services/FormsTest.php index 4a8003ccc..18a38cc51 100644 --- a/tests/Unit/Services/FormsTest.php +++ b/tests/Unit/Services/FormsTest.php @@ -11,9 +11,5 @@ 'validatorRegistration', 'validatorResignation', 'vote', - 'multiSignature', - 'multiPayment', - 'usernameRegistration', - 'usernameResignation', ]); }); diff --git a/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php b/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php index 0998e7fcf..6d90b8f7f 100644 --- a/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php +++ b/tests/Unit/Services/Transactions/Aggregates/HistoricalAggregateFactoryTest.php @@ -10,7 +10,6 @@ use App\Services\Transactions\Aggregates\Historical\WeekAggregate; use App\Services\Transactions\Aggregates\Historical\YearAggregate; use App\Services\Transactions\Aggregates\HistoricalAggregateFactory; -use App\Services\Transactions\Aggregates\Type\MultipaymentAggregate; use App\Services\Transactions\Aggregates\Type\TransferAggregate; use App\Services\Transactions\Aggregates\Type\UnvoteAggregate; use App\Services\Transactions\Aggregates\Type\ValidatorRegistrationAggregate; @@ -36,7 +35,6 @@ expect(HistoricalAggregateFactory::type($type))->toBeInstanceOf($class); })->with([ [StatsTransactionType::TRANSFER, TransferAggregate::class], - [StatsTransactionType::MULTIPAYMENT, MultipaymentAggregate::class], [StatsTransactionType::VOTE, VoteAggregate::class], [StatsTransactionType::UNVOTE, UnvoteAggregate::class], [StatsTransactionType::VALIDATOR_REGISTRATION, ValidatorRegistrationAggregate::class], diff --git a/tests/Unit/Services/Transactions/Aggregates/LargestTransactionAggregateTest.php b/tests/Unit/Services/Transactions/Aggregates/LargestTransactionAggregateTest.php index dc9593f3e..c07745346 100644 --- a/tests/Unit/Services/Transactions/Aggregates/LargestTransactionAggregateTest.php +++ b/tests/Unit/Services/Transactions/Aggregates/LargestTransactionAggregateTest.php @@ -22,23 +22,6 @@ expect((new LargestTransactionAggregate())->aggregate()->id)->toBe($transaction->id); }); -it('should get largest transaction including multipayments', function () { - Transaction::factory()->transfer()->create([ - 'amount' => 2000 * 1e18, - 'fee' => 10 * 1e18, - ]); - Transaction::factory()->transfer()->create([ - 'amount' => 6000 * 1e18, - 'fee' => 10 * 1e18, - ]); - $transaction = Transaction::factory()->multipayment()->create([ - 'amount' => ((300 * 1e18) * 4) + (5000 * 1e18), - 'fee' => 10 * 1e18, - ]); - - expect((new LargestTransactionAggregate())->aggregate()->id)->toBe($transaction->id); -}); - it('should return null if no records', function () { expect((new LargestTransactionAggregate())->aggregate())->toBeNull(); }); diff --git a/tests/Unit/Services/Transactions/Aggregates/Type/MultipaymentAggregateTest.php b/tests/Unit/Services/Transactions/Aggregates/Type/MultipaymentAggregateTest.php deleted file mode 100644 index 24b47c639..000000000 --- a/tests/Unit/Services/Transactions/Aggregates/Type/MultipaymentAggregateTest.php +++ /dev/null @@ -1,16 +0,0 @@ -aggregate())->toBe(0); - - Transaction::factory(10) - ->multipayment() - ->create(); - - expect((new MultipaymentAggregate())->aggregate())->toBe(10); -}); diff --git a/tests/Unit/Services/Transactions/TransactionTypeTest.php b/tests/Unit/Services/Transactions/TransactionTypeTest.php deleted file mode 100644 index 75ddf9a05..000000000 --- a/tests/Unit/Services/Transactions/TransactionTypeTest.php +++ /dev/null @@ -1,78 +0,0 @@ -{$type}()->create(); - $transactionType = new TransactionType($transaction); - - expect($transactionType->{'is'.ucfirst($type)}())->toBeTrue(); - expect($transactionType->name())->toBe($expected); -})->with([ - [ - 'transfer', - 'transfer', - ], - [ - 'validatorRegistration', - 'validator-registration', - ], - [ - 'vote', - 'vote', - ], - [ - 'unvote', - 'unvote', - ], - [ - 'multiSignature', - 'multi-signature', - ], - [ - 'validatorResignation', - 'validator-resignation', - ], - [ - 'multiPayment', - 'multi-payment', - ], - [ - 'usernameRegistration', - 'username-registration', - ], - [ - 'usernameResignation', - 'username-resignation', - ], -]); - -it('should determine is unknown type', function () { - $transaction = Transaction::factory()->create([ - 'type' => 1234, - 'asset' => [], - ]); - $transactionType = new TransactionType($transaction); - - expect($transactionType->isUnknown())->toBeTrue(); - expect($transactionType->name())->toBe('unknown'); -}); - -it('should play through every scenario of an unknown type', function (string $type) { - $transaction = Transaction::factory()->{$type}()->create(); - - expect((new TransactionType($transaction))->isUnknown())->toBeFalse(); -})->with([ - ['transfer'], - ['validatorRegistration'], - ['vote'], - ['unvote'], - ['multiSignature'], - ['validatorResignation'], - ['multiPayment'], - ['usernameRegistration'], - ['usernameResignation'], -]); diff --git a/tests/Unit/ViewModels/BlockViewModelTest.php b/tests/Unit/ViewModels/BlockViewModelTest.php index dcd35c58c..e7faebd7a 100644 --- a/tests/Unit/ViewModels/BlockViewModelTest.php +++ b/tests/Unit/ViewModels/BlockViewModelTest.php @@ -144,20 +144,20 @@ expect($this->subject->validator())->toBeInstanceOf(MemoryWallet::class); }); -it('should get the validator username', function () { - expect($this->subject->username())->toBeString(); - expect($this->subject->username())->toBe('Genesis'); +it('should get the validator wallet name', function () { + expect($this->subject->walletName())->toBeString(); + expect($this->subject->walletName())->toBe('Genesis'); }); -it('should fail to get the validator username', function () { +it('should fail to get the validator wallet name', function () { $this->subject = new BlockViewModel(Block::factory()->create([ 'generator_address' => Wallet::factory()->create([ 'attributes' => [], ])->address, ])); - expect($this->subject->username())->toBeString(); - expect($this->subject->username())->toBe('Genesis'); + expect($this->subject->walletName())->toBeString(); + expect($this->subject->walletName())->toBe('Genesis'); }); it('should get the previous block url', function () { diff --git a/tests/Unit/ViewModels/ForgingStatsViewModelTest.php b/tests/Unit/ViewModels/ForgingStatsViewModelTest.php index ea2873c73..0021a5fbb 100644 --- a/tests/Unit/ViewModels/ForgingStatsViewModelTest.php +++ b/tests/Unit/ViewModels/ForgingStatsViewModelTest.php @@ -62,8 +62,8 @@ 'public_key' => $wallet->public_key, ])); - expect($this->subject->username())->toBeString(); - expect($this->subject->username())->toBe('joe.blogs'); + expect($this->subject->walletName())->toBeString(); + expect($this->subject->walletName())->toBe('joe.blogs'); }); it('should handle no validator username', function () { @@ -73,5 +73,5 @@ 'public_key' => $wallet->public_key, ])); - expect($this->subject->username())->toBeNull(); + expect($this->subject->walletName())->toBeNull(); }); diff --git a/tests/Unit/ViewModels/TransactionViewModelTest.php b/tests/Unit/ViewModels/TransactionViewModelTest.php index ab6700334..884a9aa9f 100644 --- a/tests/Unit/ViewModels/TransactionViewModelTest.php +++ b/tests/Unit/ViewModels/TransactionViewModelTest.php @@ -2,21 +2,16 @@ declare(strict_types=1); -use App\DTO\Payment; use App\Facades\Settings; use App\Models\Block; use App\Models\Receipt; use App\Models\Transaction; use App\Models\Wallet; -use App\Services\Blockchain\NetworkFactory; use App\Services\Cache\CryptoDataCache; use App\Services\Cache\NetworkCache; use App\ViewModels\TransactionViewModel; use App\ViewModels\WalletViewModel; -use ArkEcosystem\Crypto\Configuration\Network as NetworkConfiguration; -use ArkEcosystem\Crypto\Identities\Address; use Carbon\Carbon; -use Illuminate\Support\Facades\Config; use function Spatie\Snapshots\assertMatchesSnapshot; beforeEach(function () { @@ -63,50 +58,6 @@ expect($transaction->isSentToSelf('recipient'))->toBeFalse(); }); -it('should determine if multipayment transaction is sent to self when sender is part of recipients', function () { - $transaction = new TransactionViewModel(Transaction::factory() - ->multiPayment() - ->create([ - 'sender_public_key' => $this->sender->public_key, - 'recipient_id' => $this->sender->address, - 'asset' => [ - 'payments' => [ - ['recipientId' => $this->sender->address], - ['recipientId' => 'recipient'], - ['recipientId' => 'recipient-2'], - ], - ], - ])); - - expect($transaction->isSentToSelf($this->sender->address))->toBeFalse(); - expect($transaction->isSentToSelf('recipient-3'))->toBeFalse(); -}); - -it('should determine if multipayment transaction is not sent to self', function () { - $transaction = new TransactionViewModel(Transaction::factory() - ->multiPayment() - ->create([ - 'sender_public_key' => $this->sender->public_key, - 'recipient_id' => $this->sender->address, - 'asset' => [ - 'payments' => [ - ['recipientId' => 'recipient'], - ['recipientId' => 'recipient-2'], - ], - ], - ])); - - expect($transaction->isSentToSelf($this->sender->address))->toBeFalse(); -}); - -it('should not be sent to self if not multipayment or transfer', function () { - $transaction = new TransactionViewModel(Transaction::factory() - ->vote() - ->create()); - - expect($transaction->isSentToSelf($this->sender->address))->toBeFalse(); -}); - it('should get the timestamp', function () { expect($this->subject->timestamp())->toBeString(); expect($this->subject->timestamp())->toBe('19 Oct 2020 04:54:16'); @@ -139,7 +90,7 @@ assertMatchesSnapshot($this->subject->amount()); }); -it('should get the amount received for non-multipayment', function () { +it('should get the amount received for transfer transactions', function () { expect($this->subject->amountReceived('recipient'))->toBeFloat(); assertMatchesSnapshot($this->subject->amountReceived('recipient')); @@ -151,296 +102,6 @@ assertMatchesSnapshot($this->subject->amountWithFee()); }); -it('should get the amount for multi payments', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'E', - ], - ], - ], - ])); - - expect($this->subject->amount())->toBeFloat(); - - assertMatchesSnapshot($this->subject->amount()); -}); - -it('should get the amount for multi payments excluding payment to the same address', function () { - $sender = Wallet::factory()->create(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $sender->public_key, - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => $sender->address, - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 60 * 1e18, - 'recipientId' => 'E', - ], - ], - ], - ])); - - expect($this->subject->amountExcludingItself())->toEqual(160); -}); - -it('should get the amount in fiat for multi payments excluding payment to the same address', function () { - $sender = Wallet::factory()->create(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $sender->public_key, - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => $sender->address, - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 60 * 1e18, - 'recipientId' => 'E', - ], - ], - ], - ])); - - (new CryptoDataCache())->setPrices('USD.week', collect([ - Carbon::parse($this->subject->timestamp())->format('Y-m-d') => 0.2907, - ])); - - assertMatchesSnapshot($this->subject->amountFiatExcludingItself()); -}); - -it('should get the amount for itself on multi payments', function () { - $sender = Wallet::factory()->create(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'sender_public_key' => $sender->public_key, - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => $sender->address, - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 60 * 1e18, - 'recipientId' => 'E', - ], - ], - ], - ])); - - expect($this->subject->amountForItself())->toEqual(50); -}); - -it('should get the specific multi payment amount for a wallet recipient', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'E', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'B', - ], - ], - ], - ])); - - expect($this->subject->amountReceived('B'))->toBeFloat(); - - assertMatchesSnapshot($this->subject->amountReceived('B')); -}); - -it('should get multi payment amount with fee', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'E', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'B', - ], - ], - ], - ])); - - expect($this->subject->amountWithFee())->toBeFloat(); - - assertMatchesSnapshot($this->subject->amountWithFee()); -}); - -it('should get the amount as fiat', function () { - $transaction = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'E', - ], - ], - ], - ]); - - $this->subject = new TransactionViewModel($transaction); - - (new CryptoDataCache())->setPrices('USD.week', collect([ - Carbon::parse($this->subject->timestamp())->format('Y-m-d') => 0.2907, - ])); - - assertMatchesSnapshot($this->subject->amountFiat()); -}); - -it('should get the specific multi payment fiat amount for a wallet recipient', function () { - $transaction = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => 'A', - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => 'B', - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => 'C', - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => 'D', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'E', - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => 'B', - ], - ], - ], - ]); - - $this->subject = new TransactionViewModel($transaction); - - (new CryptoDataCache())->setPrices('USD.week', collect([ - Carbon::parse($this->subject->timestamp())->format('Y-m-d') => 0.2907, - ])); - - assertMatchesSnapshot($this->subject->amountReceivedFiat('B')); -}); - -it('should handle 256 recipients in a multipayment', function () { - $addresses = collect(array_fill(0, 256, null))->keys(); - - $addresses->each(fn ($address) => Wallet::factory()->create(['address' => 'address-'.$address])); - - $this->subject = new TransactionViewModel( - Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => $addresses - ->map(fn ($value) => ([ - 'amount' => (256 - $value) * 1e18, - 'recipientId' => 'address-'.$value, - ])) - ->toArray(), - ], - ]) - ); - - $payments = $this->subject->payments(true); - - expect($payments)->toHaveCount(256); - expect($payments[0]->address())->toBe('address-0'); - expect($payments[255]->address())->toBe('address-255'); -}); - it('should get the total as fiat', function () { (new CryptoDataCache())->setPrices('USD.week', collect([ Carbon::parse($this->subject->timestamp())->format('Y-m-d') => 0.2907, @@ -495,11 +156,7 @@ ['validatorRegistration'], ['vote'], ['unvote'], - ['multiSignature'], ['validatorResignation'], - ['multiPayment'], - ['usernameRegistration'], - ['usernameResignation'], ]); it('should determine if the transaction is self-receiving', function (string $type) { @@ -520,8 +177,6 @@ ['vote'], ['unvote'], ['validatorResignation'], - ['usernameRegistration'], - ['usernameResignation'], ]); it('should fallback to the sender if no recipient exists', function () { @@ -580,495 +235,6 @@ expect($this->subject->nonce())->toBeInt(); }); -it('should get the multi signature address', function () { - expect($this->subject->multiSignatureAddress())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiSignature() - ->create(['asset' => null])); - - expect($this->subject->multiSignatureAddress())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignature' => [ - 'min' => 3, - 'publicKeys' => [ - '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureAddress())->toBeString(); -}); - -it('should derive the correct multisignature address', function () { - expect($this->subject->multiSignatureAddress())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiSignature() - ->create(['asset' => null])); - - expect($this->subject->multiSignatureAddress())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignature' => [ - 'min' => 3, - 'publicKeys' => [ - '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureAddress())->toBe('0x8246206ef20b95D0a3C16704Ee971a605cb7E33E'); - - Config::set('arkscan.network', 'production'); - - $network = NetworkFactory::make(config('arkscan.network')); - NetworkConfiguration::set($network->config()); - - expect($this->subject->multiSignatureAddress())->toBe('0x8246206ef20b95D0a3C16704Ee971a605cb7E33E'); - - Config::set('arkscan.network', 'development'); -}); - -it('should get the multi signature minimum', function () { - expect($this->subject->multiSignatureMinimum())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiSignature() - ->create(['asset' => null])); - - expect($this->subject->multiSignatureMinimum())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignature' => [ - 'min' => 3, - 'publicKeys' => [ - '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureMinimum())->toBeInt(); - expect($this->subject->multiSignatureMinimum())->toBe(3); -}); - -it('should get the multi signature participant count', function () { - expect($this->subject->multiSignatureParticipantCount())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiSignature() - ->create(['asset' => null])); - - expect($this->subject->multiSignatureParticipantCount())->toBeNull(); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignature' => [ - 'min' => 3, - 'publicKeys' => [ - '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureParticipantCount())->toBeInt(); - expect($this->subject->multiSignatureParticipantCount())->toBe(5); -}); - -it('should get the payments', function () { - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiPayment() - ->create(['asset' => null])); - - expect($this->subject->payments())->toBeEmpty(); - - $A = Wallet::factory()->create(); - $B = Wallet::factory()->create(); - $C = Wallet::factory()->create(); - $D = Wallet::factory()->create(); - $E = Wallet::factory()->create(); - - $model = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => $A->address, - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => $B->address, - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => $C->address, - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => $D->address, - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => $E->address, - ], - ], - ], - ]); - - $this->subject = new TransactionViewModel($model); - - $payments = $this->subject->payments(); - expect($payments[0])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 10 * 1e18, - 'recipientId' => $A->address, - ])); - - expect($payments[1])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 20 * 1e18, - 'recipientId' => $B->address, - ])); - - expect($payments[2])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 30 * 1e18, - 'recipientId' => $C->address, - ])); - - expect($payments[3])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 40 * 1e18, - 'recipientId' => $D->address, - ])); - - expect($payments[4])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 50 * 1e18, - 'recipientId' => $E->address, - ])); -}); - -it('should get the payments in descending order', function () { - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiPayment() - ->create(['asset' => null])); - - expect($this->subject->payments())->toBeEmpty(); - - $A = Wallet::factory()->create(); - $B = Wallet::factory()->create(); - $C = Wallet::factory()->create(); - $D = Wallet::factory()->create(); - $E = Wallet::factory()->create(); - - $model = Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - [ - 'amount' => 10 * 1e18, - 'recipientId' => $A->address, - ], [ - 'amount' => 20 * 1e18, - 'recipientId' => $B->address, - ], [ - 'amount' => 30 * 1e18, - 'recipientId' => $C->address, - ], [ - 'amount' => 40 * 1e18, - 'recipientId' => $D->address, - ], [ - 'amount' => 50 * 1e18, - 'recipientId' => $E->address, - ], - ], - ], - ]); - - $this->subject = new TransactionViewModel($model); - - $payments = array_values($this->subject->payments(true)); - expect($payments[0])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 50 * 1e18, - 'recipientId' => $E->address, - ])); - - expect($payments[1])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 40 * 1e18, - 'recipientId' => $D->address, - ])); - - expect($payments[2])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 30 * 1e18, - 'recipientId' => $C->address, - ])); - - expect($payments[3])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 20 * 1e18, - 'recipientId' => $B->address, - ])); - - expect($payments[4])->toEqual(new Payment((int) $model->timestamp, [ - 'amount' => 10 * 1e18, - 'recipientId' => $A->address, - ])); -}); - -it('should fail to get the payments if the transaction is not a multi payment', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->transfer()->create()); - - expect($this->subject->payments())->toBeEmpty(); -}); - -it('should get the recipients count', function () { - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiPayment() - ->create(['asset' => null])); - - expect($this->subject->recipientsCount())->toBe(0); - - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiPayment() - ->create(['asset' => ['payments' => []]])); - - expect($this->subject->recipientsCount())->toBe(0); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiPayment()->create([ - 'asset' => [ - 'payments' => [ - ['amount' => 10, 'recipientId' => 'ABC'], - ['amount' => 10, 'recipientId' => 'ABC'], - ['amount' => 10, 'recipientId' => 'ABC'], - ['amount' => 10, 'recipientId' => 'ABC'], - ['amount' => 10, 'recipientId' => 'ABC'], - ], - ], - ])); - - expect($this->subject->recipientsCount())->toBe(5); -}); - -it('should fail to get the recipients count if the transaction is not a multi payment', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->transfer()->create()); - - expect($this->subject->recipientsCount())->toBe(0); -}); - -it('should get the participants', function () { - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiSignature() - ->create(['asset' => null])); - - expect($this->subject->participants())->toHaveCount(0); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignature' => [ - 'min' => 3, - 'publicKeys' => [ - '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - Wallet::factory()->create([ - 'address' => Address::fromPublicKey('02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56'), - 'public_key' => '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - ]); - - Wallet::factory()->create([ - 'address' => Address::fromPublicKey('02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b'), - 'public_key' => '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - ]); - - Wallet::factory()->create([ - 'address' => Address::fromPublicKey('03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0'), - 'public_key' => '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - ]); - - Wallet::factory()->create([ - 'address' => Address::fromPublicKey('020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3'), - 'public_key' => '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - ]); - - Wallet::factory()->create([ - 'address' => Address::fromPublicKey('03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219'), - 'public_key' => '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ]); - - expect($this->subject->participants())->toHaveCount(5); -}); - -it('should fail to get the participants if the transaction is not a multi signature registrations', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->transfer()->create()); - - expect($this->subject->participants())->toBeEmpty(); -}); - -it('should get the multi signature wallet', function () { - $this->subject = new TransactionViewModel(Transaction::factory() - ->multiSignature() - ->create(['asset' => null])); - - expect($this->subject->participants())->toHaveCount(0); - - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignature' => [ - 'min' => 3, - 'publicKeys' => [ - '02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - Wallet::factory()->create(['address' => '0x8246206ef20b95D0a3C16704Ee971a605cb7E33E']); - - $result = $this->subject->multiSignatureWallet(); - - expect($result)->toBeInstanceOf(WalletViewModel::class); - expect($result->address())->toBe('0x8246206ef20b95D0a3C16704Ee971a605cb7E33E'); -}); - -it('should fail to get the multi signature wallet if the transaction is not a multi signature registrations', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->transfer()->create()); - - expect($this->subject->multiSignatureWallet())->toBeEmpty(); -}); - -it('should determine if the transaction type is unknown', function () { - $subject = new TransactionViewModel(Transaction::factory()->create([ - 'type' => 123, - 'type_group' => 456, - ])); - - expect($subject->isUnknown())->toBeTrue(); -}); - -it('should get the username if the transaction is not a validator registration', function () { - $subject = new TransactionViewModel(Transaction::factory() - ->validatorRegistration() - ->create([ - 'asset' => [ - 'username' => 'john', - ], - ])); - - expect($subject->username())->toBe('john'); -}); - -it('should return null for username if not specified', function () { - $subject = new TransactionViewModel(Transaction::factory()->transfer()->create()); - - expect($subject->username())->toBeNull(); -}); - -it('should get the address of legacy multi signature transactions', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'sender_public_key' => $this->sender->public_key, - 'asset' => [ - 'multiSignatureLegacy' => [ - 'min' => 3, - 'lifetime' => 24, - 'keysgroup' => [ - '+02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '+02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '+03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '+020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '+03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureAddress())->toBe($this->sender->address); -}); - -it('should get the participant count for legacy multi signature transactions', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignatureLegacy' => [ - 'min' => 3, - 'lifetime' => 24, - 'keysgroup' => [ - '+02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '+02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '+03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '+020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '+03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureParticipantCount())->toBe(5); -}); - -it('should get the participants for legacy multi signature transactions', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignatureLegacy' => [ - 'min' => 3, - 'lifetime' => 24, - 'keysgroup' => [ - '+02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '+02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '+03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '+020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '+03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->participants())->toHaveCount(5); -}); - -it('should get the minimum for legacy multi signature transactions', function () { - $this->subject = new TransactionViewModel(Transaction::factory()->multiSignature()->create([ - 'asset' => [ - 'multiSignatureLegacy' => [ - 'min' => 3, - 'lifetime' => 24, - 'keysgroup' => [ - '+02fb3def2593a00c5b84620addf28ff21bac452bd71a37d4d8e24f301683a81b56', - '+02bc9f661fcc8abca65fe9aff4614036867b7fdcc5730085ccc5cb854664d0194b', - '+03c44c6b6cc9893ae21ca606712fd0f6f03c41ce81c4f6ce5a640f4b0b82ec1ce0', - '+020300039e973baf5e46b945777cfae330d6392cdb039b1cebc5c3382d421166c3', - '+03b050073621b9b5caec9461d44d6bcf21a858c47dd88230ce723e25c1bc75c219', - ], - ], - ], - ])); - - expect($this->subject->multiSignatureMinimum())->toBe(3); -}); - describe('HasPayload trait', function () { it('should determine if a transaction has a payload', function () { $transaction = new TransactionViewModel(Transaction::factory()->create([ diff --git a/tests/Unit/ViewModels/WalletViewModelTest.php b/tests/Unit/ViewModels/WalletViewModelTest.php index f04b6a976..3fd5da7c2 100644 --- a/tests/Unit/ViewModels/WalletViewModelTest.php +++ b/tests/Unit/ViewModels/WalletViewModelTest.php @@ -165,27 +165,6 @@ ->create(['address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B'])); expect($subject->isKnown())->toBeTrue(); - expect($subject->hasMultiSignature())->toBeFalse(); - expect($subject->hasSecondSignature())->toBeFalse(); - expect($subject->isOwnedByExchange())->toBeFalse(); - expect($subject->hasSpecialType())->toBeTrue(); - - $subject = new WalletViewModel(Wallet::factory() - ->activeValidator() - ->create(['address' => 'unknown'])); - - expect($subject->hasSpecialType())->toBeFalse(); -}); - -it('should determine if the wallet has a special type if multisignature', function () { - fakeKnownWallets(); - - $subject = new WalletViewModel(Wallet::factory() - ->multiSignature() - ->create(['address' => '0x946BF38f53aE753371BDC9583e68865643876320'])); - - expect($subject->isKnown())->toBeFalse(); - expect($subject->hasMultiSignature())->toBeTrue(); expect($subject->isOwnedByExchange())->toBeFalse(); expect($subject->hasSpecialType())->toBeTrue(); @@ -202,7 +181,6 @@ $subject = new WalletViewModel(Wallet::factory()->create(['address' => '0x946BF38f53aE753371BDC9583e68865643876320'])); expect($subject->isKnown())->toBeFalse(); - expect($subject->hasSecondSignature())->toBeTrue(); expect($subject->isOwnedByExchange())->toBeFalse(); expect($subject->hasSpecialType())->toBeTrue(); @@ -615,7 +593,7 @@ ], ])); - expect($this->subject->usernameIfNotKnown())->toBe('ACF Hot Wallet'); + expect($this->subject->walletName())->toBe('ACF Hot Wallet'); }); it('should get username if wallet not know', function () { @@ -629,37 +607,7 @@ ], ])); - expect($this->subject->usernameIfNotKnown())->toBe('john'); -}); - -it('should get the username if the wallet is a validator', function () { - fakeKnownWallets(); - - $this->subject = new WalletViewModel(Wallet::factory()->create([ - 'attributes' => [ - 'username' => 'John', - ], - ])); - - expect($this->subject->username())->toBe('John'); -}); - -it('should determine if the wallet has a second signature', function () { - expect($this->subject->hasSecondSignature())->toBeBool(); -}); - -it('should determine if the wallet has a multi signature', function () { - expect($this->subject->hasMultiSignature())->toBeBool(); -}); - -it('should get the validator user name', function () { - $this->subject = new WalletViewModel(Wallet::factory()->create([ - 'attributes' => [ - 'username' => 'john', - ], - ])); - - expect($this->subject->username())->toBe('john'); + expect($this->subject->walletName())->toBe('john'); }); it('should get the vote url with validator', function () { @@ -717,17 +665,6 @@ expect($this->subject->isActive())->toBeFalse(); }); -it('should get validator name for wallet name', function () { - $this->subject = new WalletViewModel(Wallet::factory()->create([ - 'attributes' => [ - 'username' => 'John', - 'validatorRank' => 50, - ], - ])); - - expect($this->subject->usernameBeforeKnown())->toBe('John'); -}); - it('should get known wallet name for wallet name', function () { $wallet = Wallet::factory()->create([ 'attributes' => [], @@ -745,30 +682,7 @@ $this->subject = new WalletViewModel($wallet); - expect($this->subject->usernameBeforeKnown())->toBe('Test Wallet'); -}); - -it('should get validator name before known wallet name for a wallet', function () { - $wallet = Wallet::factory()->create([ - 'attributes' => [ - 'username' => 'John', - 'validatorRank' => 50, - ], - ]); - - Http::fake([ - 'githubusercontent.com/*' => [ - [ - 'type' => 'exchange', - 'name' => 'Test Wallet', - 'address' => $wallet->address, - ], - ], - ]); - - $this->subject = new WalletViewModel($wallet); - - expect($this->subject->usernameBeforeKnown())->toBe('John'); + expect($this->subject->walletName())->toBe('Test Wallet'); }); it('should get no name if a standard wallet', function () { @@ -778,7 +692,7 @@ 'attributes' => [], ])); - expect($this->subject->usernameBeforeKnown())->toBeNull(); + expect($this->subject->walletName())->toBeNull(); }); it('should get forged block count for validator', function () { diff --git a/tests/fixtures/fees.json b/tests/fixtures/fees.json index 4646403d1..e6820192a 100644 --- a/tests/fixtures/fees.json +++ b/tests/fixtures/fees.json @@ -20,35 +20,11 @@ "min": "85641326", "sum": "1923024659" }, - "multiSignature": { - "avg": "1225000000", - "max": "2000000000", - "min": "500000000", - "sum": "24500000000" - }, - "multiPayment": { - "avg": "10387534", - "max": "17750683", - "min": "10000000", - "sum": "207750683" - }, "validatorResignation": { "avg": "2389750000", "max": "2500000000", "min": "500000000", "sum": "47795000000" - }, - "usernameRegistration": { - "avg": "2500000000", - "max": "2500000000", - "min": "2500000000", - "sum": "50000000000" - }, - "usernameResignation": { - "avg": "2389750000", - "max": "2500000000", - "min": "500000000", - "sum": "47795000000" } } }