Creates a service for CringeCash™, the hit mobile experience coming to FRIENDBOTS NEAR YOU!
First, I reworked booting up / initial config a bit. Now, there's a boot module that allows us to configure boot-related tasks. These are run as the very first part of the main function. For CringeCash™, that ensures the sqlite database is set up. That's all it does for now but you could move initialization of dependencies and other boot-related things into there. That can help avoid the problem of cyclical dependency resolution in JS (module A imports B which needs C which has to initialize D which isn't ready by the time A needs it, and has no way to tell A it's not ready yet).
The CringeCashService itself is pretty simple right now - it allows retrieval of a user's balance (which signs them up automatically with a balance of 0) and transactions to be applied to a given user's balance. CringeCash™ is currently in integers, because aint nobody wanna mess with floats in JS, heck that noise. There are basic sanity checks on transaction amounts - a user cannot make a transaction that would put them in the negative, for example, and any float value passed in will be promptly floored into the integer below it.
Finally, I added a sqlite wrapper library that wraps it in the promise API. That makes it a bit nicer to work with than it was previously, and removes the need for us to manually wrap those functions ourselves.
Creates a service for CringeCash™, the hit mobile experience coming to FRIENDBOTS NEAR YOU!
First, I reworked booting up / initial config a bit. Now, there's a
boot
module that allows us to configure boot-related tasks. These are run as the very first part of themain
function. For CringeCash™, that ensures the sqlite database is set up. That's all it does for now but you could move initialization of dependencies and other boot-related things into there. That can help avoid the problem of cyclical dependency resolution in JS (module A imports B which needs C which has to initialize D which isn't ready by the time A needs it, and has no way to tell A it's not ready yet).The CringeCashService itself is pretty simple right now - it allows retrieval of a user's balance (which signs them up automatically with a balance of 0) and transactions to be applied to a given user's balance. CringeCash™ is currently in integers, because aint nobody wanna mess with floats in JS, heck that noise. There are basic sanity checks on transaction amounts - a user cannot make a transaction that would put them in the negative, for example, and any float value passed in will be promptly floored into the integer below it.
Finally, I added a sqlite wrapper library that wraps it in the promise API. That makes it a bit nicer to work with than it was previously, and removes the need for us to manually wrap those functions ourselves.