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

Revert transaction #52

Closed
altitude opened this issue Oct 18, 2021 · 3 comments · Fixed by #61
Closed

Revert transaction #52

altitude opened this issue Oct 18, 2021 · 3 comments · Fixed by #61
Assignees
Labels
contrib/tier-3 enhancement New feature or request

Comments

@altitude
Copy link
Member

Summary

We should be able to revert a transaction without having to build the reverse transaction

Proposal

POST /:ledger/transactions/:txid/revert

Expected behaviors

Given the transaction:

{
  "txid": 0,
  "postings": [
    {
      "source": "world",
      "destination": "users:001",
      "amount": 100,
      "asset": "COIN"
    },
    {
      "source": "users:001",
      "destination": "payments:001",
      "amount": 100,
      "asset": "COIN"
    }
  ]
}

The revert endpoint should attempt to commit the exact reverse transaction:

{
  "txid": 1,
  "postings": [
    {
      "source": "payments:001",
      "destination": "users:001",
      "amount": 100,
      "asset": "COIN"
    },
    {
      "source": "users:001",
      "destination": "world",
      "amount": 100,
      "asset": "COIN"
    }
  ]
}
@altitude altitude added enhancement New feature or request RFC contrib/tier-3 labels Oct 18, 2021
@altitude altitude assigned altitude and NumaryBot and unassigned altitude Oct 19, 2021
@altitude altitude added api/http and removed RFC labels Oct 19, 2021
@henry-jackson
Copy link
Contributor

@altitude What do you think about adding a "Reverse" method to the Transaction struct in core/transaction.go. The method would reverse the order of the postings in the Transaction, and switch the source and destination strings on each posting.

Then when the endpoint is hit, we will query for transaction using the ID in the URL, reverse the transaction using that method, and then post the new transaction to the ledger.

@henry-jackson
Copy link
Contributor

henry-jackson commented Oct 20, 2021

Another consideration is that we should mark that a Transaction has been reverted - do you think this is best achieved with the metadata table?

@altitude
Copy link
Member Author

@henry-jackson sounds great to me!

1/ Sharing that vision for core/transaction.go, agreed it's a great place to host the reverse-transaction-building-logic

2/ Awesome idea. Would go along well with the scheme concept we're working on for materialized transactions, where we introduce specific keys and values to use on the metadata table. I think I'd go for two meta fields addition on the reverted transaction upon successful commit of the reverting transaction:

scheme/state with a reverted value
scheme/state/reverted-by with a value of the txid of the reverting transaction

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

Successfully merging a pull request may close this issue.

3 participants