I am building a system that requires the client to pay for the transaction. Once the user has successfully paid for the transaction, my backend will give the user some Web2 benefits. The main problem that I am facing is, how I can make sure that the user has:
- Signed the expected transaction.
- If the user paid for the correct transaction, the user should be getting the web2 benefits even if the backend server went down at the time of the user signing the transaction later when the server gets back up by clicking on some "Revalidate" button.
I came up with the following flow to make the above work but I am not completely sure if that is the right way to it, or if there is a better way:
- create the transaction in the backend.
- save serializedTransactionAsStringWithoutSignatures in web2 DB.
- send serializedTransactionAsStringWithSignatures to the client.
- the client will receive the encoded transaction, sign it, & and pay for it.
- the signed transaction will again get sent to backend.
- the backend will decode the transaction & remove the signatures and compare it with the transaction (serializedTransactionAsStringWithoutSignatures) saved in web2 DB.
- if both match, the backend will save the transaction signature in web2 DB.
- then the backend will send a request to the blockchain to process the transaction.
- once the blockchain transaction is confirmed, the user will receive some web2 benefits.
I think this flow will be able to handle network failures like let's say the server shuts down between steps 8 & 9, still, the transaction signature is already saved in web2 DB, and we can later use that to verify the transaction once the server comes back up.
Open to better alternatives and suggestions, thanks!