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

Include API responses in submit_tx method #185

Closed
bhatt-deep opened this issue Mar 22, 2023 · 2 comments
Closed

Include API responses in submit_tx method #185

bhatt-deep opened this issue Mar 22, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@bhatt-deep
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Yes, When a transaction is submitted, If there's an error in any part of it, the response from APIs will be helpful in decoding and re-submitting.

Describe the solution you'd like
Modify the submit_tx method to capture the API response and include it in the return value. Here's an example of how this could be done:

from blockfrost import ApiError

def submit_tx(self, cbor: Union[bytes, str]) -> dict:
    if isinstance(cbor, str):
        cbor = bytes.fromhex(cbor)
    with tempfile.NamedTemporaryFile(delete=False) as f:
        f.write(cbor)
    try:
        response: dict = self.api.tx_submit(f.name)
    except ApiError as e:
        os.remove(f.name)
        raise ValueError(f"Failed to submit transaction. Error code: {e.status_code}. Error message: {e.message}")
    os.remove(f.name)
    return {
        'response': response,
    }

Describe alternatives you've considered
None

Additional context
None

@cffls
Copy link
Collaborator

cffls commented Mar 23, 2023

Thank you for the suggestion. This sounds a good idea. Would you mind creating a PR for it?

@bhatt-deep
Copy link
Contributor Author

yeah, sure will give it a try.

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

No branches or pull requests

2 participants