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

🗞️ Export Safe-compatible JSON from lz:oapp:wire and lz:ownable:transfer-ownership #576

Open
janjakubnanista opened this issue Apr 18, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@janjakubnanista
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Some of the Safe UIs are not compatible with the current way of signing safe transactions. The aforementioned tasks should support a JSON-compatible output generation so that the user can export the transactions and upload them manually to the Safe UI

Describe the solution you'd like
Add a CLI flag to the tasks that will make them either:

  • Export a JSON file to filesystem
  • Print out the JSON file to the console
@janjakubnanista janjakubnanista added enhancement New feature or request help wanted Extra attention is needed labels Apr 18, 2024
@janjakubnanista janjakubnanista changed the title 🗞️ Export Safe-compatible JSON from lz:oapp:wire and la:ownable:transfer-ownership 🗞️ Export Safe-compatible JSON from lz:oapp:wire and lz:ownable:transfer-ownership Jun 5, 2024
@mubarakade
Copy link

To address the problem of Safe UIs not being compatible with the current way of signing safe transactions, we can add a new CLI flag to your task scripts that will enable JSON-compatible output generation. This solution will involve two main functionalities: exporting the JSON file to the filesystem and printing the JSON file to the console. Below are the steps to implement this solution

Steps to Implement the Solution

  1. Modify the Task Scripts: Update the task scripts to include a CLI flag (--output-json) that triggers JSON output generation.

  2. Export to Filesystem: Implement functionality to export the JSON output to a file in the filesystem.

  3. Print to Console: Implement functionality to print the JSON output directly to the console.

  4. Update Documentation: Ensure that the CLI usage documentation is updated to reflect the new flag and its usage.

Example Implementation

Here’s a sample implementation in Python, assuming you have a task script that processes transactions:

Step 1: Modify the Task Script

import argparse
import json
import sys

def process_transaction(transaction_data):
    # Placeholder for transaction processing logic
    processed_data = {"status": "success", "data": transaction_data}
    return processed_data

def main():
    parser = argparse.ArgumentParser(description="Process transactions for Safe UI.")
    parser.add_argument("--input", type=str, required=True, help="Input file containing transaction data.")
    parser.add_argument("--output-json", type=str, help="Output JSON file path. If not provided, JSON will be printed to console.")
    args = parser.parse_args()

    # Read transaction data from input file
    with open(args.input, 'r') as file:
        transaction_data = json.load(file)

    # Process the transaction
    result = process_transaction(transaction_data)

    # Convert the result to JSON
    result_json = json.dumps(result, indent=4)

    if args.output_json:
        # Export JSON to file
        with open(args.output_json, 'w') as output_file:
            output_file.write(result_json)
        print(f"JSON output saved to {args.output_json}")
    else:
        # Print JSON to console
        print(result_json)

if __name__ == "__main__":
    main()

Step 2: Export to Filesystem

In the main function above, if the --output-json flag is provided with a file path, the JSON result will be written to the specified file. If the flag is not provided, the JSON result will be printed to the console.

Step 3: Print to Console

The print(result_json) statement ensures that the JSON output is printed to the console when the --output-json flag is not provided.

Step 4: Update Documentation

Update the script's documentation and usage instructions:

Usage: script_name.py --input <input_file> [--output-json <output_file>]

Options:
  --input       Input file containing transaction data.
  --output-json Output JSON file path. If not provided, JSON will be printed to console.

Examples:
  python script_name.py --input transactions.json --output-json output.json
  python script_name.py --input transactions.json

Benefits of This Approach

  1. Flexibility: Users can choose to either save the output to a file or print it directly to the console.
  2. Compatibility: The JSON output ensures compatibility with Safe UIs, allowing users to manually upload the transaction data if needed.
  3. Ease of Use: Adding a simple CLI flag makes it easy for users to generate the necessary JSON output without modifying the script.

This solution provides a straightforward way to handle the compatibility issue with Safe UIs and offers flexibility in how users can export and manage their transaction data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants