Managing Rules & Attributes in Ledger

Attributes and rules play a crucial role in the operational phase by governing, enhancing, and contextualizing the actions performed, such as creating instructions, executing movements, and generating postings. Here's how they connect:


Role of Attributes in Ledger

Attributes are metadata attached to ledger elements (accounts, wallets, instructions, movements) to provide context or enforce specific behaviors. They ensure that operations are tailored to meet system and business-specific requirements.

How Attributes Connect to Ledger Operations:

  • Enhancing Instructions:

    • Attributes like purpose, transaction_type, or customer_id can be attached to instructions.

    • Example:

      {
        "instruction_id": "12345",
        "attributes": {
          "transaction_type": "refund",
          "customer_id": "C001"
        }
      }
    • This ensures that the instruction carries relevant metadata for auditing or downstream processing.

  • Context for Movements:

    • Movements inherit attributes from instructions or have their own (e.g., allow_partial, priority).

    • Example:

      {
        "movement_id": "m001",
        "attributes": {
          "priority": "high",
          "allow_partial": true
        }
      }

      This can be used to prioritize specific movements during processing.

  • Categorizing Accounts and Wallets:

    • Attributes help classify accounts and wallets to enforce rules during operations.

    • Example: An attribute account_type=corporate ensures only corporate funds are used for specific instructions.

Why Attributes Are Important:

  • They allow customization of operations without changing core logic.

  • They provide granularity for business-specific scenarios, like tagging high-value transactions.


Rules in Ledger

Rules define the operational constraints and validations that ensure transactions comply with business policies, regulatory requirements, and system integrity.

How Rules Connect to Operations:

  • Instruction Validation:

    • Rules can validate attributes on instructions or enforce specific actions.

    • Example: A rule ensures that refunds (transaction_type=refund) do not exceed the original transaction amount.

  • Movement Constraints:

    • Rules determine whether a movement can proceed based on conditions like:

      • Sufficient funds in the debit wallet.

      • Matching currencies between debit and credit wallets.

      • Consolidated balance evaluations (e.g., check_gcb_multi).

    • Example Rule:

      {
        "name": "check_gcb_multi",
        "parameters": {
          "datasheet": "/datasheet/exchange_rates",
          "tolerance": 5
        }
      }
  • Posting and Balance Restrictions:

    • Rules can enforce restrictions on how postings affect wallet balances.

    • Example:

      • A rule disallows negative balances on customer wallets (disallow_negative_customer_balance).

  • Automation Triggers:

    • Rules trigger specific automated actions based on operational conditions.

    • Example:

      • If an account balance falls below a threshold, a rule triggers a notification or a fund transfer.

Why Rules Are Important:

  • Validation: They ensure that every operation complies with predefined constraints.

  • Control: They prevent invalid operations, like unauthorized transfers or insufficient funds.

  • Automation: They streamline complex workflows by enforcing predefined responses to specific conditions.


By working together, attributes and rules create a framework where operations are dynamic, governed, and tailored to the specific needs of the ledger's use cases.

Last updated