From 48fc55359eb0b01fa63857484cadf65f0bc1f8d1 Mon Sep 17 00:00:00 2001 From: zgrguric Date: Thu, 17 Aug 2023 19:14:20 +0200 Subject: [PATCH] Flag descriptions --- src/Utilities/Flags.php | 103 +++++++++++++++++++++++++++++++++++++++ tests/Unit/FlagsTest.php | 16 ++++++ 2 files changed, 119 insertions(+) diff --git a/src/Utilities/Flags.php b/src/Utilities/Flags.php index 24fabc2..0b98b47 100644 --- a/src/Utilities/Flags.php +++ b/src/Utilities/Flags.php @@ -95,4 +95,107 @@ public static function hasFlag(int $flags, int $check): bool { return ($flags & $check) ? true : false; } + + public static function description(string $transactiontype, string $flagname, bool $htmlFormat = false): string + { + $path = $transactiontype.'_'.$flagname; + + $html = ''; + + switch($path) { + case '_GLOBAL_tfFullyCanonicalSig': + case 'tfFullyCanonicalSig': + $html = 'DEPRECATED No effect. (If the RequireFullyCanonicalSig amendment is not enabled, this flag enforces a fully-canonical signature.)'; + break; + case 'EnableAmendment_tfGotMajority': + $html = 'The tfGotMajority flag means the amendment has more than 80% support.'; + break; + case 'EnableAmendment_tfLostMajority': + $html = 'The tfLostMajority flag means support for the amendment has decreased to 80% or less.'; + break; + case 'NFTokenCreateOffer_tfSellNFToken': + $html = 'If set, indicates that the offer is a sell offer. Otherwise, it is a buy offer.'; + break; + case 'NFTokenMint_tfBurnable': + $html = 'If set, indicates that the minted token may be burned by the issuer even if the issuer does not currently hold the token. The current holder of the token may always burn it.'; + break; + case 'NFTokenMint_tfOnlyXRP': + $html = 'If set, indicates that the token may only be offered or sold for XRP.'; + break; + case 'NFTokenMint_tfTrustLine': + $html = 'If set, indicates that the issuer wants a trustline to be automatically created.'; + break; + case 'NFTokenMint_tfTransferable': + $html = 'If set, indicates that this NFT can be transferred. This flag has no effect if the token is being transferred from the issuer or to the issuer.'; + break; + case 'OfferCreate_tfPassive': + $html = 'If enabled, the offer does not consume offers that exactly match it, and instead becomes an Offer object in the ledger. It still consumes offers that cross it.'; + break; + case 'OfferCreate_tfImmediateOrCancel': + $html = 'Treat the offer as an Immediate or Cancel order. If enabled, the offer never becomes a ledger object: it only tries to match existing offers in the ledger. If the offer cannot match any offers immediately, it executes successfully without trading any currency. In this case, the transaction has the result code tesSUCCESS, but creates no Offer objects in the ledger.'; + break; + case 'OfferCreate_tfFillOrKill': + $html = 'Treat the offer as a Fill or Kill order . Only try to match existing offers in the ledger, and only do so if the entire TakerPays quantity can be obtained. If the fix1578 amendment is enabled and the offer cannot be executed when placed, the transaction has the result code tecKILLED; otherwise, the transaction uses the result code tesSUCCESS even when it was killed without trading any currency.'; + break; + case 'OfferCreate_tfSell': + $html = 'Exchange the entire TakerGets amount, even if it means obtaining more than the TakerPays amount in exchange.'; + break; + case 'PaymentChannelClaim_tfRenew': + $html = 'Clear the channel\'s Expiration time. (Expiration is different from the channel\'s immutable CancelAfter time.) Only the source address of the payment channel can use this flag.'; + break; + case 'PaymentChannelClaim_tfClose': + $html = 'Request to close the channel. Only the channel source and destination addresses can use this flag. This flag closes the channel immediately if it has no more XRP allocated to it after processing the current claim, or if the destination address uses it. If the source address uses this flag when the channel still holds XRP, this schedules the channel to close after SettleDelay seconds have passed. (Specifically, this sets the Expiration of the channel to the close time of the previous ledger plus the channel\'s SettleDelay time, unless the channel already has an earlier Expiration time.) If the destination address uses this flag when the channel still holds XRP, any XRP that remains after processing the claim is returned to the source address.'; + break; + case 'Payment_tfNoDirectRipple': + $html = 'Do not use the default path; only use paths included in the Paths field. This is intended to force the transaction to take arbitrage opportunities.'; + break; + case 'Payment_tfPartialPayment': + $html = 'If the specified Amount cannot be sent without spending more than SendMax, reduce the received amount instead of failing outright.'; + break; + case 'Payment_tfLimitQuality': + $html = 'Only take paths where all the conversions have an input:output ratio that is equal or better than the ratio of Amount:SendMax.'; + break; + case 'TrustSet_tfSetfAuth': + $html = 'Authorize the other party to hold currency issued by this account. (No effect unless using the asfRequireAuth AccountSet flag.) Cannot be unset.'; + break; + case 'TrustSet_tfSetNoRipple': + $html = 'Enable the No Ripple flag, which blocks rippling between two trust lines of the same currency if this flag is enabled on both.'; + break; + case 'TrustSet_tfClearNoRipple': + $html = 'Disable the No Ripple flag, which blocks rippling between two trust lines of the same currency if this flag is enabled on both.'; + break; + case 'TrustSet_tfSetFreeze': + $html = 'Freeze the trust line.'; + break; + case 'TrustSet_tfClearFreeze': + $html = 'Disable individual Freeze on the specific trust line.'; + break; + case 'AccountSet_tfRequireDestTag': + case 'AccountSet_asfRequireDest': + $html = 'Require a destination tag to send transactions to this account.'; + break; + case 'AccountSet_tfOptionalDestTag': + $html = 'Disable requirement that destination tag is required to send transactions to this account.'; + break; + case 'AccountSet_tfRequireAuth': + case 'AccountSet_asfRequireAuth': + $html = 'Require authorization for users to hold balances issued by this address can only be enabled if the address has no trust lines connected to it.'; + break; + case 'AccountSet_tfOptionalAuth': + $html = 'Disable requirement that authorization for users to hold balances issued by this address can only be enabled if the address has no trust lines connected to it.'; + break; + case 'AccountSet_tfDisallowXRP': + case 'AccountSet_asfDisallowXRP': + $html = 'XRP should not be sent to this account.'; + break; + case 'AccountSet_tfAllowXRP': + $html = 'XRP is allowed to be sent to this account.'; + break; + } + + if(!$htmlFormat) + return \strip_tags($html); + + return $html; + } } \ No newline at end of file diff --git a/tests/Unit/FlagsTest.php b/tests/Unit/FlagsTest.php index 071d20b..3565b86 100644 --- a/tests/Unit/FlagsTest.php +++ b/tests/Unit/FlagsTest.php @@ -20,4 +20,20 @@ public function testExtractCanonicalGlobalFlag() $this->assertEquals(2,count($extracted)); $this->assertEquals(['tfFullyCanonicalSig','tfSell'],$extracted); } + + public function testFlagDescription() + { + $extracted = Flags::description('_GLOBAL','tfFullyCanonicalSig',true); + $html = 'DEPRECATED No effect. (If the RequireFullyCanonicalSig amendment is not enabled, this flag enforces a fully-canonical signature.)'; + + $this->assertEquals($html,$extracted); + } + + public function testFlagDescriptionPlain() + { + $extracted = Flags::description('_GLOBAL','tfFullyCanonicalSig',false); + $html = 'DEPRECATED No effect. (If the RequireFullyCanonicalSig amendment is not enabled, this flag enforces a fully-canonical signature.)'; + + $this->assertEquals($html,$extracted); + } } \ No newline at end of file