Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: update transaction type handling #1000

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fef8fe1
fix: handle missing state record
alexbarnsley Nov 12, 2024
57716a2
use zero static helper method
alexbarnsley Nov 12, 2024
aff68e1
rename class names
alexbarnsley Nov 13, 2024
798366c
update handling of payload
alexbarnsley Nov 13, 2024
07776c4
update langs
alexbarnsley Nov 13, 2024
c25bc15
update method used for checking if transaction is evm - check if it h…
alexbarnsley Nov 13, 2024
1bff804
force no vote/unvote return value
alexbarnsley Nov 13, 2024
b687b36
comment out voted validator
alexbarnsley Nov 13, 2024
34c302e
payload signature enum
alexbarnsley Nov 13, 2024
200d686
style: resolve style guide violations
alexbarnsley Nov 13, 2024
b67f253
remove vote combination/swap functionality
alexbarnsley Nov 13, 2024
da4a083
Merge branch 'refactor/update-transaction-type-handling' of github.co…
alexbarnsley Nov 13, 2024
eeee5e2
remove legacy & subcategory handling
alexbarnsley Nov 13, 2024
7f5a0ed
output method has & update transaction page headings
alexbarnsley Nov 13, 2024
4f051a1
get voted validator from payload
alexbarnsley Nov 13, 2024
b169885
add vote address tooltip wrapping
alexbarnsley Nov 13, 2024
312f2c4
chore: stanley
alexbarnsley Nov 14, 2024
b5765fa
remove vendorfield
alexbarnsley Nov 14, 2024
dddd3e7
style: resolve style guide violations
alexbarnsley Nov 14, 2024
4df8682
Merge branch 'mainsail-develop' into refactor/update-transaction-type…
alexbarnsley Nov 14, 2024
d654a94
transaction method test
alexbarnsley Nov 14, 2024
3f906c7
style: resolve style guide violations
alexbarnsley Nov 14, 2024
3402997
refactor: remove unused transaction types (#1001)
alexbarnsley Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/Console/Commands/CacheAnnualStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ private function cacheAllYears(StatisticsCache $cache): void
->orderBy('year')
->get();

// TODO: handle multipayment transactions

$blocksData = DB::connection('explorer')
->query()
->select([
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions app/Console/Commands/CacheDevelopmentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,51 @@
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
{
$cache = app(WalletCache::class);

$knownWallets = collect(Network::knownWallets());

Wallets::allWithUsername()
->orWhereIn('address', $knownWallets->pluck('address'))
Wallet::whereIn('address', $knownWallets->pluck('address'))
->select([
'address',
'public_key',
'attributes',
])
->get()
->each(function (Model $wallet) use ($cache, $knownWallets) : 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
}
}
37 changes: 0 additions & 37 deletions app/Console/Commands/CacheMultiSignatureAddresses.php

This file was deleted.

31 changes: 0 additions & 31 deletions app/Console/Commands/CacheValidatorStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 2 additions & 5 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 0 additions & 4 deletions app/Console/Playbooks/TransactionPlaybook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions app/Contracts/WalletRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions app/DTO/MemoryWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions app/DTO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@

namespace App\DTO;

use App\Facades\Wallets;
use App\Services\ExchangeRate;
use Illuminate\Support\Arr;

final class Payment
{
private float $amount;

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
Expand All @@ -38,11 +33,6 @@ public function address(): string
return $this->address;
}

public function username(): ?string
{
return $this->username;
}

public function recipient(): self
{
return $this;
Expand Down
18 changes: 18 additions & 0 deletions app/Enums/PayloadSignature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum PayloadSignature: string
{
case TRANSFER = 'a9059cbb';

case VALIDATOR_REGISTRATION = '602a9eee';

case VOTE = '6dd7d8ea';

case UNVOTE = '3174b689';

case VALIDATOR_RESIGNATION = 'b85f5da2';
}
6 changes: 0 additions & 6 deletions app/Enums/StatsTransactionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ enum StatsTransactionType
{
public const TRANSFER = 'transfer';

public const MULTIPAYMENT = 'multipayment';

public const VOTE = 'vote';

public const UNVOTE = 'unvote';

public const SWITCH_VOTE = 'switch_vote';

public const VALIDATOR_REGISTRATION = 'validator_registration';

public const VALIDATOR_RESIGNATION = 'validator_resignation';
Expand All @@ -26,10 +22,8 @@ public static function all(): Collection
{
return new Collection([
self::TRANSFER,
self::MULTIPAYMENT,
self::VOTE,
self::UNVOTE,
self::SWITCH_VOTE,
self::VALIDATOR_REGISTRATION,
self::VALIDATOR_RESIGNATION,
]);
Expand Down
24 changes: 0 additions & 24 deletions app/Enums/TransactionTypeEnum.php

This file was deleted.

3 changes: 0 additions & 3 deletions app/Facades/Wallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static Builder allWithUsername()
* @method static Builder allWithValidatorPublicKey()
* @method static Builder allWithVote()
* @method static Builder allWithPublicKey()
* @method static Builder allWithMultiSignature()
* @method static Wallet findByAddress(string $address)
* @method static Wallet findByPublicKey(string $publicKey)
* @method static Collection findByPublicKeys(array $publicKey)
* @method static Wallet findByUsername(string $username)
* @method static Wallet findByIdentifier(string $identifier)
*/
final class Wallets extends Facade
Expand Down
6 changes: 0 additions & 6 deletions app/Http/Livewire/Modals/ExportBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ final class ExportBlocks extends Component

public string $publicKey;

public ?string $username = null;

public bool $hasForgedBlocks = false;

public function mount(WalletViewModel $wallet): void
Expand All @@ -28,10 +26,6 @@ public function mount(WalletViewModel $wallet): void
$publicKey = $wallet->publicKey();

$this->publicKey = $publicKey;

if ($wallet->hasUsername()) {
$this->username = $wallet->username();
}
}

public function render(): View
Expand Down
Loading
Loading