Skip to content

Commit

Permalink
refactor: remove obsolete transactions (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries authored Jul 30, 2024
1 parent e7e5dd4 commit 0d7e9c0
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 608 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

21 changes: 5 additions & 16 deletions src/Configuration/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ArkEcosystem\Crypto\Enums\Fees;
use ArkEcosystem\Crypto\Enums\Types;
use PHPUnit\Util\Type;

/**
* This is the fee configuration class.
Expand All @@ -24,23 +25,11 @@
class Fee
{
/**
* The default transaction fees.
* Custom transaction fees.
*
* @var array
*/
private static $fees = [
Types::TRANSFER => Fees::TRANSFER,
Types::SECOND_SIGNATURE_REGISTRATION => Fees::SECOND_SIGNATURE_REGISTRATION,
Types::VALIDATOR_REGISTRATION => Fees::VALIDATOR_REGISTRATION,
Types::VOTE => Fees::VOTE,
Types::MULTI_SIGNATURE_REGISTRATION => Fees::MULTI_SIGNATURE_REGISTRATION,
Types::IPFS => Fees::IPFS,
Types::MULTI_PAYMENT => Fees::MULTI_PAYMENT,
Types::VALIDATOR_RESIGNATION => Fees::VALIDATOR_RESIGNATION,
Types::USERNAME_REGISTRATION => Fees::USERNAME_REGISTRATION,
Types::USERNAME_RESIGNATION => Fees::USERNAME_RESIGNATION,
Types::HTLC_REFUND => Fees::HTLC_REFUND,
];
private static $customFees = [];

/**
* Get the transaction fee for the given type.
Expand All @@ -49,7 +38,7 @@ class Fee
*/
public static function get(int $type): string
{
return static::$fees[$type];
return isset(static::$customFees[$type]) ? static::$customFees[$type] : Types::fromValue($type)->defaultFee();
}

/**
Expand All @@ -60,6 +49,6 @@ public static function get(int $type): string
*/
public static function set(int $type, string $fee): void
{
static::$fees[$type] = $fee;
static::$customFees[$type] = $fee;
}
}
6 changes: 0 additions & 6 deletions src/Enums/Fees.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,17 @@ class Fees
{
public const TRANSFER = '10000000';

public const SECOND_SIGNATURE_REGISTRATION = '500000000';

public const VALIDATOR_REGISTRATION = '2500000000';

public const VOTE = '100000000';

public const MULTI_SIGNATURE_REGISTRATION = '500000000';

public const IPFS = '500000000';

public const MULTI_PAYMENT = '10000000';

public const VALIDATOR_RESIGNATION = '2500000000';

public const USERNAME_REGISTRATION = '2500000000';

public const USERNAME_RESIGNATION = '2500000000';

public const HTLC_REFUND = '0';
}
76 changes: 56 additions & 20 deletions src/Enums/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,68 @@

namespace ArkEcosystem\Crypto\Enums;

use ArkEcosystem\Crypto\Transactions\Types\MultiPayment;
use ArkEcosystem\Crypto\Transactions\Types\MultiSignatureRegistration;
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
use ArkEcosystem\Crypto\Transactions\Types\UsernameRegistration;
use ArkEcosystem\Crypto\Transactions\Types\UsernameResignation;
use ArkEcosystem\Crypto\Transactions\Types\ValidatorRegistration;
use ArkEcosystem\Crypto\Transactions\Types\ValidatorResignation;
use ArkEcosystem\Crypto\Transactions\Types\Vote;
use ReflectionEnum;

/**
* This is the transaction types class.
*
* @author Brian Faust <[email protected]>
* This is the transaction types enum.
*/
class Types
enum Types: int
{
public const TRANSFER = 0;

public const SECOND_SIGNATURE_REGISTRATION = 1;

public const VALIDATOR_REGISTRATION = 2;

public const VOTE = 3;

public const MULTI_SIGNATURE_REGISTRATION = 4;

public const IPFS = 5;
case TRANSFER = 0;
case VALIDATOR_REGISTRATION = 2;
case VOTE = 3;
case MULTI_SIGNATURE_REGISTRATION = 4;
case MULTI_PAYMENT = 6;
case VALIDATOR_RESIGNATION = 7;
case USERNAME_REGISTRATION = 8;
case USERNAME_RESIGNATION = 9;

public const MULTI_PAYMENT = 6;
public function transactionClass(): string
{
return match ($this) {
Types::TRANSFER => Transfer::class,
Types::VALIDATOR_REGISTRATION => ValidatorRegistration::class,
Types::VOTE => Vote::class,
Types::MULTI_SIGNATURE_REGISTRATION => MultiSignatureRegistration::class,
Types::MULTI_PAYMENT => MultiPayment::class,
Types::VALIDATOR_RESIGNATION => ValidatorResignation::class,
Types::USERNAME_REGISTRATION => UsernameRegistration::class,
Types::USERNAME_RESIGNATION => UsernameResignation::class,
};
}

public const VALIDATOR_RESIGNATION = 7;
public function defaultFee(): string
{
return match ($this) {
Types::TRANSFER => Fees::TRANSFER,
Types::VALIDATOR_REGISTRATION => Fees::VALIDATOR_REGISTRATION,
Types::VOTE => Fees::VOTE,
Types::MULTI_SIGNATURE_REGISTRATION => Fees::MULTI_SIGNATURE_REGISTRATION,
Types::MULTI_PAYMENT => Fees::MULTI_PAYMENT,
Types::VALIDATOR_RESIGNATION => Fees::VALIDATOR_RESIGNATION,
Types::USERNAME_REGISTRATION => Fees::USERNAME_REGISTRATION,
Types::USERNAME_RESIGNATION => Fees::USERNAME_RESIGNATION,
};
}

public const USERNAME_REGISTRATION = 8;
public static function fromValue(int $value): ?self
{
$enum = new ReflectionEnum(self::class);

public const USERNAME_RESIGNATION = 9;
foreach ($enum->getCases() as $case) {
if ($case->getValue()->value === $value) {
return $case->getValue();
}
}

public const HTLC_REFUND = 10;
throw new \InvalidArgumentException("Invalid value: {$value}");
}
}
49 changes: 0 additions & 49 deletions src/Transactions/Builder/HtlcClaimBuilder.php

This file was deleted.

73 changes: 0 additions & 73 deletions src/Transactions/Builder/HtlcLockBuilder.php

This file was deleted.

48 changes: 0 additions & 48 deletions src/Transactions/Builder/HtlcRefundBuilder.php

This file was deleted.

48 changes: 0 additions & 48 deletions src/Transactions/Builder/IPFSBuilder.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Transactions/Builder/MultiPaymentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function vendorField(string $vendorField): self
*/
protected function getType(): int
{
return \ArkEcosystem\Crypto\Enums\Types::MULTI_PAYMENT;
return \ArkEcosystem\Crypto\Enums\Types::MULTI_PAYMENT->value;
}

protected function getTypeGroup(): int
Expand Down
Loading

0 comments on commit 0d7e9c0

Please sign in to comment.