How to use send-tokens from another nodejs script
MareoRaft opened this issue · 6 comments
Hello! I'm basically writing a GUI for send-tokens. Since my program is also in nodejs, I would like to use one of your internal functions directly instead of making a command line call.
I think I just need to call the run
function, but I'm wondering if your code needs to be further abstracted out a bit so that this run
function is more user-facing. Instead of taking in program
and args
, perhaps we can make a function that takes in a single plain-old object of user inputs.
I would be more than happy to attempt making the changes myself, but since you understand your code better than I do, it would be good if you were somehow involved. Thanks in advance, and let me know if you'd like to do it yourself or let me have a go at it!
I've been reading through your code more. It looks really solid. I think I may be good using the run
function as-is, but please let me know if there's anything I should be careful about.
run()
from send-tokens.js really just sets up logging, does some light input sanitation/normalization then calls on sendTokens()
from lib.js. In fact, if you just require()
the package as a normal library, you'll get lib.js. This was the intended library usage.
That said, I can't think of any gotchas with breaking out run()
from send-tokens.js for use in your own app. You'll probably want to remove the logging stuff since you'll have a UI.
I will document library usage with sendTokens()
soon, but you can probably suss out how it works from run()
.
Does this help?
The input sanitation is nice, and it would be preferable for my GUI to behave exactly the same as the command line usage. So I would prefer to import the run
function and use it directly. Would you be willing to add that function to module.exports
so that I can import it?
So just throwing some ideas out there:
For logging, it should probably be fine to leave it in there since users won't see the console anyway. If for some reason it causes an error, we could add a log=true
parameter to run
. If somebody passes log=false
into run
, then the logging lines wouldn't execute. But hopefully that won't be necessary.
Does it make sense to remove the process.exit(0)
line from the run
function? I'm not sure if it's even necessary to have that line, since process.exit(0)
happens on line 33 anyway.
To be clear, I prefer importing your run
function because (1) it reduces redundancy and (2) it guarantees that the behavior of the GUI will be the same as the behavior of the command line interface, which is good for users. But if you are opposed to it, I can copy and paste some code from send-tokens.js
and modify to my specific needs. Thanks and have a great day!
OK, I pulled run()
out to be the new sendTokens()
library function. Documentation is on the front page. It is exactly the programmatic version of the command line.
Let me know if this meets your requirements.
Oh man, this looks really amazing. Thanks a billion, I'll let you know if I run into anything.