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

Utility function to derive flags from integer #390

Open
LimpidCrypto opened this issue May 17, 2022 · 2 comments
Open

Utility function to derive flags from integer #390

LimpidCrypto opened this issue May 17, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers potential bounty idea

Comments

@LimpidCrypto
Copy link
Contributor

When receiving a transactions data, the Flags field contains all flags set expressed as integer. Example:

{
    "Account": "rMapXdAPsZBScjMKUki7hJBz7aZH51BRqi",
    "Fee": "15",
    "Flags": 2148139008,
    "LastLedgerSequence": 71663679,
    "Memos": [
        {
            "Memo": {
                "MemoData": "4F666665722076696120546F6B656E205472617368657220784170702E",
                "MemoType": "7872706C2E7365727669636573"
            }
        }
    ],
    "Sequence": 63126083,
    "SigningPubKey": "02846E0549D225326F22EB8845B0AB97B4BF95EF5BB698694E3FE97CCCF88E7EAF",
    "TakerGets": {
        "currency": "585250616E646100000000000000000000000000",
        "issuer": "r9uQt7Y34SwSyKqdb5sMmAqk37rh3Y4V7",
        "value": "0.05"
    },
    "TakerPays": "1",
    "TransactionType": "OfferCreate",
    "TxnSignature": "3044022062AE9E76F5E5E76CBBA4397DFE07384A2111B1FED0FD3E1E41EC0DAADAD5D35502203A4C39C431C0E4C67DBC0E231DCB2D73FA8826D553349B708910597AE07F50C0",
    "date": 705918052,
    "hash": "684A057DE7FB687DD8883628D69222A86F72A3DB8F350CDF5681DCB42AED2C1E",
    "inLedger": 71663671,
    "ledger_index": 71663671,
    "meta": ...
}

In this example the Flags set are 2148139008. Since it's not immediately obvious which flags are set for that transaction, there should be a utility function that derives the flag names from this integer. The function should take the transaction type and the flags expressed as integer (in this example 2148139008). For the example it should return something like ['tf_immediate_or_cancel', 'tf_sell', 'tf_fully_canonical_sig'].

@LimpidCrypto LimpidCrypto changed the title Utility function to derive flags Utility function to derive flags from integer May 17, 2022
@intelliot intelliot added enhancement New feature or request good first issue Good for newcomers potential bounty idea labels Dec 13, 2022
@JST5000
Copy link
Contributor

JST5000 commented Jan 5, 2023

This is an example of this done in xrpl.js specifically for AccountRoot flags which may be a helpful reference: https://github.com/XRPLF/xrpl.js/pull/1699/files

(xrpl.org is the best source for what the flags do)

@LimpidCrypto
Copy link
Contributor Author

LimpidCrypto commented Jan 5, 2023

This is an example of this done in xrpl.js specifically for AccountRoot flags which may be a helpful reference: https://github.com/XRPLF/xrpl.js/pull/1699/files

(xrpl.org is the best source for what the flags do)

Yeah, I also already posted an example for python on Discord once:

ACCOUNT_ROOT_LEDGER_FLAGS: Dict[str, int] = {
    "lsfPasswordSpent": 0x00010000,
    "lsfRequireDestTag": 0x00020000,
    "lsfRequireAuth": 0x00040000,
    "lsfRequireAuth": 0x00040000,
    "lsfDisableMaster": 0x00100000,
    "lsfNoFreeze": 0x00200000,
    "lsfGlobalFreeze": 0x00400000,
    "lsfDefaultRipple": 0x00800000,
    "lsfDepositAuth": 0x01000000,
}

def parse_account_root_flags(flags: int) -> List[str]:
    flags_enabled = []
    for flag in ACCOUNT_ROOT_LEDGER_FLAGS:
        check_flag = ACCOUNT_ROOT_LEDGER_FLAGS[flag]
        if check_flag & flags == check_flag:
            flags_enabled.append(flag)
    return flags_enabled

print(parse_account_root_flags(4194304))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers potential bounty idea
Projects
None yet
Development

No branches or pull requests

3 participants