dimanche 22 décembre 2019

How to do this in NODEJS?

This has no code as it is the middle of the night and woke up with a question.

I have a node.js web app and use firebase for auth username (email) and password, there is also a Token which is an in app currency in the database. Lets say User1 has 50tokens in his account , and the tokens are saved in the fire base database, user 2 has 20 tokens in his database.

User 1 decides to send 20 tokens to User 2.

Is it possible to extract the ammount 50 from the database substract 20 and print the new value (20) tokens remaining and add to the User 2 20 tokens so in total he has now 40tokens saved in the database.

I also had the idea of creating a class and make it a wallet and store the tokens in the wallet, I have a rough idea how to do this, but where does the tokens value get stored? How can I establish a connection to add/subtract tokens between users?

If you were to do this? How would you do it?

Ps. Im not asking to write the code for me, I just really cant seem to find a solution in my head and its been bothering me to the point that I cant sleep. I will be trying recommendations from here and keep posting code snippets to see how well it performs and hope helps me and someone else in future.

Ps. Wallets are non crypto, just in app currency token

Aucun commentaire:

Enregistrer un commentaire