Skip to content

feat: add capability to specify account metadata outside ns #835

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

Merged
merged 1 commit into from
Mar 28, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Mar 28, 2025

Fixes LX-25

@gfyrag gfyrag requested a review from a team as a code owner March 28, 2025 17:05
Copy link

coderabbitai bot commented Mar 28, 2025

Walkthrough

The pull request introduces a new optional JSON structure, accountMetadata, across multiple API endpoints and documentation. This structure—featuring properties with an embedded admin flag—is incorporated into API examples and client models. In parallel, all transaction creation methods are refactored: conversion methods are renamed from ToRunScript to ToCore, and method signatures and tests across various packages are updated to use a new CreateTransaction type (which now includes account metadata). These changes ensure that account metadata is processed uniformly within both the API layer and the ledger controllers.

Changes

File(s) Change Summary
docs/api/README.md, pkg/client/docs/models/components/v2posttransaction.md, pkg/client/docs/sdks/v2/README.md, pkg/client/models/components/v2posttransaction.go Added new optional accountMetadata JSON structure with properties (property1 and property2 containing "admin": "true"); updated documentation examples and added an accessor method.
internal/api/bulking/{bulker.go, bulker_test.go, elements.go, mocks_ledger_controller_test.go} Updated transaction request conversion from ToRunScript to ToCore; changed the CreateTransaction parameter type from RunScript to CreateTransaction; added AccountMetadata field to TransactionRequest.
internal/api/v1/{controllers_transactions_create.go, controllers_transactions_create_test.go, mocks_ledger_controller_test.go} Refactored API v1 endpoints to use the new CreateTransaction struct, updating parameter types and test assertions accordingly.
internal/api/v2/{controllers_bulk_test.go, controllers_transactions_create.go, controllers_transactions_create_test.go, mocks_ledger_controller_test.go} Standardized transaction creation to use CreateTransaction; restructured the input format and updated tests to reflect these changes.
internal/controller/{ledger/controller.go, controller_default.go, controller_default_test.go, controller_generated_test.go, controller_with_events.go, controller_with_too_many_client_handling.go, controller_with_too_many_client_handling_test.go, controller_with_traces.go}, internal/controller/system/state_tracker.go Modified Controller interfaces and implementations to use a new CreateTransaction type (embedding RunScript and including AccountMetadata); updated method signatures and corresponding tests.
test/e2e/api_transactions_create_test.go Added an end-to-end test context to validate that account metadata is correctly set and retrieved after transaction creation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant TxRequest
    participant Controller
    participant Ledger

    Client->>API: POST Transaction Request (with accountMetadata)
    API->>TxRequest: Parse payload & invoke ToCore (build CreateTransaction)
    TxRequest->>Controller: Pass CreateTransaction parameters
    Controller->>Ledger: Call CreateTransaction with parameters
    Ledger-->>Controller: Return Log & CreatedTransaction
    Controller-->>API: Send success response
    API-->>Client: Return HTTP Response
Loading

Assessment against linked issues

Objective Addressed Explanation
Ability to allow accounts overdrafts (LX-25) No modifications related to overdraft functionality.
Ability to set accounts metadata (LX-25) New accountMetadata field introduced and processed.

Possibly related PRs

Suggested labels

build-images

Poem

I hopped through lines of code all day,
Adding metadata in a brand-new way.
With each refactored call and structured type,
My little paws made the API bright.
Account metadata now leads the play,
A rabbit’s joy in every byte—hip, hip, hooray! 🐇

Happy hops to cleaner flows!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.94%. Comparing base (ace5f9a) to head (81b38f4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #835      +/-   ##
==========================================
- Coverage   82.00%   81.94%   -0.06%     
==========================================
  Files         137      137              
  Lines        7512     7532      +20     
==========================================
+ Hits         6160     6172      +12     
- Misses       1036     1042       +6     
- Partials      316      318       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
internal/api/v1/controllers_transactions_create.go (1)

61-144: 💡 Verification agent

🧩 Analysis chain

Verify that account metadata is properly handled

While the code changes look good, I don't see any specific handling for the "account metadata" mentioned in the PR objective. The PR summary mentions adding this capability, but it's not immediately clear from this file how account metadata is processed.


🏁 Script executed:

#!/bin/bash
# Check the definition of CreateTransaction struct to verify account metadata handling
rg -A 10 "type CreateTransaction struct" --type go

# Look for any AccountMetadata references in the codebase
rg "AccountMetadata" --type go

Length of output: 33818


Action required: Propagate Account Metadata in Transaction Creation

The endpoint in internal/api/v1/controllers_transactions_create.go isn’t mapping any account metadata from the incoming request—even though the ledgercontroller.CreateTransaction struct (defined in internal/controller/ledger/controller.go) includes an AccountMetadata field. This omission means that, despite the PR’s objective to add account metadata capability, the feature isn’t being exercised here.

  • In both branches (postings and script), the command is constructed only with a RunScript value.
  • If the request is meant to include account metadata (e.g. as a separate field like payload.AccountMetadata), it should be assigned to the AccountMetadata field when calling l.CreateTransaction.

Please confirm how the payload should supply account metadata and update the mapping accordingly.

🧹 Nitpick comments (3)
internal/controller/ledger/controller_default_test.go (1)

106-106: Potential inconsistency with metadata handling

While the CreateTransaction test on line 55 now uses an empty map for account metadata, the RevertTransaction test on line 106 still uses nil for the metadata parameter in CommitTransaction. For consistency, consider updating this to also use an empty map.

- CommitTransaction(gomock.Any(), gomock.Any(), nil).
+ CommitTransaction(gomock.Any(), gomock.Any(), map[string]metadata.Metadata{}).
docs/api/README.md (2)

497-509: Add “accountMetadata” to Bulk Request JSON Example
A new JSON field, accountMetadata, has been added immediately after the metadata field in the bulk request example. It defines two properties (property1 and property2), each with an embedded admin key. This is clear and consistent with the intended update. However, consider adding a brief explanatory note in the surrounding documentation (or in a dedicated parameters table) to clarify that this field is optional and describe its expected usage.


1293-1321: Include “accountMetadata” in Transaction Creation JSON Example
In the transaction creation example, the update introduces a new accountMetadata field (following the same structure as in the bulk request) in addition to the existing metadata field. The nested structure—with property1 and property2 each holding an admin flag—is clear and consistent. For clarity, it might be helpful to add a brief description in the accompanying documentation regarding the purpose of accountMetadata and how it differs (or complements) the standard metadata.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ace5f9a and 81b38f4.

⛔ Files ignored due to path filters (3)
  • openapi.yaml is excluded by !**/*.yaml
  • openapi/v2.yaml is excluded by !**/*.yaml
  • pkg/client/.speakeasy/gen.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (26)
  • docs/api/README.md (7 hunks)
  • internal/api/bulking/bulker.go (1 hunks)
  • internal/api/bulking/bulker_test.go (1 hunks)
  • internal/api/bulking/elements.go (2 hunks)
  • internal/api/bulking/mocks_ledger_controller_test.go (1 hunks)
  • internal/api/common/mocks_ledger_controller_test.go (1 hunks)
  • internal/api/v1/controllers_transactions_create.go (2 hunks)
  • internal/api/v1/controllers_transactions_create_test.go (1 hunks)
  • internal/api/v1/mocks_ledger_controller_test.go (1 hunks)
  • internal/api/v2/controllers_bulk_test.go (2 hunks)
  • internal/api/v2/controllers_transactions_create.go (1 hunks)
  • internal/api/v2/controllers_transactions_create_test.go (1 hunks)
  • internal/api/v2/mocks_ledger_controller_test.go (1 hunks)
  • internal/controller/ledger/controller.go (2 hunks)
  • internal/controller/ledger/controller_default.go (4 hunks)
  • internal/controller/ledger/controller_default_test.go (2 hunks)
  • internal/controller/ledger/controller_generated_test.go (1 hunks)
  • internal/controller/ledger/controller_with_events.go (1 hunks)
  • internal/controller/ledger/controller_with_too_many_client_handling.go (1 hunks)
  • internal/controller/ledger/controller_with_too_many_client_handling_test.go (2 hunks)
  • internal/controller/ledger/controller_with_traces.go (1 hunks)
  • internal/controller/system/state_tracker.go (1 hunks)
  • pkg/client/docs/models/components/v2posttransaction.md (1 hunks)
  • pkg/client/docs/sdks/v2/README.md (1 hunks)
  • pkg/client/models/components/v2posttransaction.go (2 hunks)
  • test/e2e/api_transactions_create_test.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (12)
internal/controller/ledger/controller_with_too_many_client_handling.go (2)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (83-86)
internal/storage/ledger/logs.go (1)
  • Log (20-26)
internal/api/v2/controllers_transactions_create_test.go (4)
internal/controller/ledger/controller.go (2)
  • CreateTransaction (83-86)
  • RunScript (79-79)
pkg/testserver/api.go (1)
  • CreateTransaction (37-45)
internal/controller/ledger/parameters.go (1)
  • Parameters (3-7)
internal/machine/vm/run.go (1)
  • RunScript (14-19)
internal/controller/ledger/controller.go (4)
internal/controller/ledger/parameters.go (1)
  • Parameters (3-7)
internal/log.go (3)
  • Log (84-96)
  • CreatedTransaction (193-196)
  • AccountMetadata (191-191)
internal/storage/ledger/logs.go (1)
  • Log (20-26)
internal/machine/vm/run.go (1)
  • RunScript (14-19)
internal/api/v1/controllers_transactions_create_test.go (3)
internal/controller/ledger/controller.go (2)
  • CreateTransaction (83-86)
  • RunScript (79-79)
internal/controller/ledger/parameters.go (1)
  • Parameters (3-7)
internal/machine/vm/run.go (1)
  • RunScript (14-19)
internal/controller/system/state_tracker.go (1)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (83-86)
internal/controller/ledger/controller_generated_test.go (2)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (83-86)
internal/storage/ledger/logs.go (1)
  • Log (20-26)
internal/controller/ledger/controller_default_test.go (4)
internal/controller/ledger/controller.go (2)
  • CreateTransaction (83-86)
  • RunScript (79-79)
pkg/testserver/api.go (1)
  • CreateTransaction (37-45)
internal/controller/ledger/parameters.go (1)
  • Parameters (3-7)
internal/machine/vm/run.go (1)
  • RunScript (14-19)
internal/controller/ledger/controller_with_too_many_client_handling_test.go (1)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (83-86)
internal/api/v2/mocks_ledger_controller_test.go (5)
internal/api/common/mocks_ledger_controller_test.go (1)
  • LedgerController (24-28)
internal/api/v1/mocks_ledger_controller_test.go (1)
  • LedgerController (24-28)
internal/api/bulking/mocks_ledger_controller_test.go (1)
  • LedgerController (24-28)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (83-86)
internal/storage/ledger/logs.go (1)
  • Log (20-26)
internal/api/bulking/bulker_test.go (1)
internal/controller/ledger/controller.go (2)
  • CreateTransaction (83-86)
  • RunScript (79-79)
internal/api/bulking/elements.go (2)
internal/controller/ledger/controller.go (3)
  • CreateTransaction (83-86)
  • RunScript (79-79)
  • Script (80-80)
internal/api/v1/controllers_transactions_create.go (1)
  • Script (19-22)
internal/api/bulking/mocks_ledger_controller_test.go (5)
internal/api/common/mocks_ledger_controller_test.go (1)
  • LedgerController (24-28)
internal/api/v1/mocks_ledger_controller_test.go (1)
  • LedgerController (24-28)
internal/api/v2/mocks_ledger_controller_test.go (1)
  • LedgerController (24-28)
internal/controller/ledger/controller.go (1)
  • CreateTransaction (83-86)
internal/storage/ledger/logs.go (1)
  • Log (20-26)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (42)
internal/controller/ledger/controller_with_too_many_client_handling_test.go (2)

26-26: Parameter type updated to reflect new CreateTransaction type

The parameter type has been changed from Parameters[RunScript] to Parameters[CreateTransaction], which is consistent with the introduction of the new CreateTransaction struct that includes support for account metadata outside of namespaces.


60-60: Parameter type updated to reflect new CreateTransaction type

Similar to line 26, this change updates the parameter type from Parameters[RunScript] to Parameters[CreateTransaction] to be consistent with the new parameter structure in the controller interface.

internal/api/bulking/mocks_ledger_controller_test.go (1)

108-108: Mock method signature updated to use CreateTransaction parameter type

The signature of the CreateTransaction mock method has been updated to use ledger0.Parameters[ledger0.CreateTransaction] instead of ledger0.Parameters[ledger0.RunScript]. This change is necessary to align the mock implementation with the actual interface that now uses the enhanced CreateTransaction type which supports account metadata.

pkg/client/docs/models/components/v2posttransaction.md (1)

12-13: Added AccountMetadata field for specifying metadata outside namespace

The documentation has been enhanced with a new optional AccountMetadata field of type map[string]map[string]*string* to support the capability of specifying account metadata outside of the namespace. This field allows associating metadata with specific accounts directly during transaction creation, which addresses the PR objective (LX-25).

pkg/client/models/components/v2posttransaction.go (2)

35-35: Added AccountMetadata field to V2PostTransaction struct

A new field AccountMetadata of type map[string]map[string]string has been added to the V2PostTransaction struct. This implementation allows clients to provide account-specific metadata during transaction creation, which is consistent with the documentation changes and the PR objective.


84-89: Added accessor method for the new AccountMetadata field

The GetAccountMetadata() method provides a null-safe way to access the new AccountMetadata field, consistent with the pattern used for other fields in the struct. This ensures API consumers can safely interact with the new field even when the object is nil.

pkg/client/docs/sdks/v2/README.md (1)

1031-1038: New account metadata field looks good.

This addition implements a new field AccountMetadata which enables the specification of metadata for accounts outside the namespace (addressing LX-25). The structure is well-formed, with account keys mapping to metadata key-value pairs.

internal/controller/ledger/controller.go (2)

46-46: Good signature update to support new functionality.

The method signature has been correctly updated to accept Parameters[CreateTransaction] instead of the previous Parameters[RunScript], which aligns with the PR objective to support account metadata outside namespace.


83-86: Well-structured new type definition.

The new CreateTransaction type appropriately embeds RunScript to maintain backward compatibility while adding the AccountMetadata field to support the new functionality. The use of the existing metadata.Metadata type ensures consistency with the rest of the codebase.

internal/controller/ledger/controller_with_events.go (1)

41-41: Method signature correctly updated.

The CreateTransaction method signature has been properly updated to use Parameters[CreateTransaction] instead of the previous Parameters[RunScript], ensuring consistent implementation of the interface across the codebase.

internal/controller/ledger/controller_with_traces.go (1)

352-352: Method signature correctly updated for tracing.

The CreateTransaction method signature in ControllerWithTraces has been properly updated to use Parameters[CreateTransaction], maintaining consistency with the interface definition and other implementations.

internal/api/v2/controllers_transactions_create_test.go (1)

404-408: Test updated to correctly use the CreateTransaction struct

The change appropriately updates the test to use the new CreateTransaction struct which wraps the existing RunScript structure, aligning with the PR's goal of supporting account metadata specification outside the namespace.

internal/controller/ledger/controller_with_too_many_client_handling.go (1)

43-43: Method signature updated to support account metadata

The method signature has been properly updated to use Parameters[CreateTransaction] instead of Parameters[RunScript], maintaining consistency with the interface changes across the codebase. This change enables the handling of account metadata during transaction creation while preserving the retry logic for handling "too many clients" errors.

internal/controller/system/state_tracker.go (1)

49-49: Method signature updated for account metadata support

The signature change correctly updates the parameter type to use ledgercontroller.Parameters[ledgercontroller.CreateTransaction], aligning with the broader refactoring in the codebase. The state tracking logic remains unchanged, ensuring proper state management while supporting the new account metadata feature.

test/e2e/api_transactions_create_test.go (1)

120-163: Well-structured test for the new account metadata feature

The new test case properly validates that account metadata can be specified outside of the namespace. The test creates a transaction with postings and adds metadata to two accounts ("world" and "alice"), then verifies that the metadata is correctly associated with each account after the transaction is created.

This test effectively covers the core functionality introduced in this PR and ensures that the account metadata is properly persisted in the database.

internal/api/v1/controllers_transactions_create_test.go (1)

230-234: Update to CreateTransaction parameters reflects new account metadata capability

The parameter type for CreateTransaction has been changed from Parameters[RunScript] to Parameters[CreateTransaction] to accommodate the new account metadata functionality. This change aligns with the PR objective to enable specifying account metadata outside the namespace.

internal/api/bulking/bulker_test.go (1)

59-65: LGTM: Transaction creation parameters updated correctly

The test correctly updates the parameters passed to the CreateTransaction method, wrapping the RunScript in a CreateTransaction struct to support the new account metadata functionality.

internal/controller/ledger/controller_generated_test.go (1)

107-107: Parameter type change in mock implementation

The mock correctly reflects the updated parameter type for the CreateTransaction method, changing from Parameters[RunScript] to Parameters[CreateTransaction] to support the new account metadata functionality.

internal/api/bulking/bulker.go (2)

129-129: Method rename from ToRunScript to ToCore

The method call has been updated from ToRunScript(false) to ToCore(false) to better represent its purpose of converting to a core transaction structure rather than just a run script.


134-138: CreateTransaction parameter type updated for account metadata support

The parameter type has been changed from Parameters[RunScript] to Parameters[CreateTransaction] to accommodate the new account metadata capability, aligning with the broader API changes.

internal/api/v2/mocks_ledger_controller_test.go (1)

108-108: Updated method signature to support account metadata

The CreateTransaction method signature has been updated to use ledger0.Parameters[ledger0.CreateTransaction] instead of ledger0.Parameters[ledger0.RunScript]. This change correctly aligns with the new feature that allows specifying account metadata outside of the namespace.

internal/api/v1/mocks_ledger_controller_test.go (1)

108-108: Updated method signature to support account metadata

The signature change for CreateTransaction from using ledger0.Parameters[ledger0.RunScript] to ledger0.Parameters[ledger0.CreateTransaction] is consistent with the new feature implementation and matches the changes made in other mock controllers.

internal/api/common/mocks_ledger_controller_test.go (1)

108-108: Updated method signature to support account metadata

The CreateTransaction method signature has been consistently updated across all mock controllers to use the new ledger0.Parameters[ledger0.CreateTransaction] type, which now includes account metadata capabilities.

internal/controller/ledger/controller_default_test.go (2)

55-55: Initialized account metadata map in CommitTransaction call

The test has been updated to pass an empty metadata map (map[string]metadata.Metadata{}) instead of nil, ensuring consistent behavior when account metadata is present but empty.


67-70: Updated test to use new CreateTransaction structure

The test now correctly uses the new Parameters[CreateTransaction] structure with the embedded RunScript field, aligning with the interface changes in the controller. This change supports the new capability to specify account metadata outside the namespace.

internal/api/v1/controllers_transactions_create.go (2)

86-88: Properly adapted the function call to use the new CreateTransaction structure

The code has been updated to use the new ledgercontroller.CreateTransaction structure that wraps the previously used RunScript parameter. This change aligns with the PR objective of adding capability to specify account metadata outside namespace.


117-124: Implementation consistently applies the new structure pattern

This section correctly implements the same pattern as the previous modification, encapsulating the RunScript data within the new CreateTransaction structure. The code maintains proper handling of script, timestamp, reference, and metadata.

internal/api/v2/controllers_transactions_create.go (2)

35-35: Method call renamed from ToRunScript to ToCore

The change from payload.ToRunScript() to payload.ToCore() aligns with the PR objective to enhance account metadata handling. This refactoring suggests a shift from treating the transaction as a script to run, to creating a core transaction representation.


41-41: Variable renamed and type changed

The variable has been renamed from runScript to createTransaction to better reflect its purpose, and the type is now CreateTransaction instead of RunScript. This change maintains consistency with the updated method signature.

internal/api/v2/controllers_bulk_test.go (2)

67-73: Test updated to use the new CreateTransaction structure

The mock expectation has been updated to use ledgercontroller.Parameters[ledgercontroller.CreateTransaction] instead of ledgercontroller.Parameters[ledgercontroller.RunScript]. The transaction data is now correctly wrapped in a CreateTransaction struct, with RunScript as a field.


477-483: Consistent use of new CreateTransaction structure

This change mirrors the earlier update to properly use the new CreateTransaction structure in test expectations, maintaining consistency throughout the test file.

internal/api/bulking/elements.go (4)

102-102: New field added for account metadata

Added a new field AccountMetadata of type map[string]metadata.Metadata to the TransactionRequest struct. This implements the core feature of the PR - allowing account metadata to be specified outside the namespace.


105-105: Method renamed with updated return type

The method has been renamed from ToRunScript to ToCore and its return type changed from *ledgercontroller.RunScript to *ledgercontroller.CreateTransaction. This reflects the shift towards a more general transaction creation approach rather than just script execution.


111-128: Refactored logic to handle both postings and script cases

The implementation now creates a runScript variable that's properly populated based on whether postings exist or script is provided. This maintains the existing logic while adapting to the new structure.


130-133: Return updated to include account metadata

The method now returns a CreateTransaction struct that includes both the RunScript and the new AccountMetadata field. This ensures that account metadata is properly passed through the transaction creation flow.

internal/controller/ledger/controller_default.go (7)

47-47: Updated type parameter for createTransactionLp

The type parameter for createTransactionLp has been changed from RunScript to CreateTransaction, reflecting the updated transaction creation flow.


103-103: Updated log processor initialization

The initialization of createTransactionLp now uses CreateTransaction as its type parameter, consistent with the type change.


287-287: Updated method signature for createTransaction

The method signature now accepts Parameters[CreateTransaction] instead of Parameters[RunScript], reflecting the updated transaction creation flow.


325-338: New logic added to process account metadata

This new implementation properly handles account metadata:

  1. It initializes accountMetadata from the script execution result
  2. Creates an empty map if none exists
  3. Merges in any account metadata provided in the input parameters

This is a key part of implementing the PR's objective to allow specifying account metadata outside the namespace.


345-345: Updated CommitTransaction call to include account metadata

The CommitTransaction call now includes the processed account metadata, ensuring it's properly stored with the transaction.


352-352: Updated return value to include account metadata

The CreatedTransaction return value now includes the account metadata, ensuring it's available to callers.


356-356: Updated method signature for CreateTransaction

The public API method has been updated to use Parameters[CreateTransaction] instead of Parameters[RunScript], maintaining consistency with the internal implementation changes.

@gfyrag gfyrag added this pull request to the merge queue Mar 28, 2025
Copy link
Contributor

@paul-nicolas paul-nicolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont' have all the context, but I see nothing fishy

Merged via the queue into main with commit ed5da10 Mar 28, 2025
10 checks passed
@gfyrag gfyrag deleted the feat/accounts-metadata-at-tx-creation branch March 28, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants