Hey I’m having issues with storing into my databas...
# help
a
Hey I’m having issues with storing into my database using knex using async and await.
t
tell us more!
a
I am trying to store data in my database but I need it to be done after a few other work has been done but the function always stops when it is time to store the data in the database
It doesn’t even go to the next lines after that
t
can I see the code?
a
So in the second picture, the code stops where there’s await save_new_tx and doesn’t continue execution
I can’t figure out why
t
Is storage(...).insert the part that's inserting to the db? If this returns a promise it needs to be awaited
a
Yes it does and we’ve awaited that as well
It still stops to continue execution as soon as there’s an await
t
keep the await in there, how far in the execution of
save_new_tx
does it go to
does it print COIN
a
Yea it prints coin
But nothing after
t
ok can you create a basic function that does nothing but insert some data into knex and see if you can get that working?
a
Kk will do
t
I think I understand the issue here. This isn't the root issue but you have the return response(...) in the wrong place, it needs to be outside the function
I have a feeling the await on
send_signed_transaction
is returning as soon as it fires all the
once
callbacks - it doesn't await the callbacks
you can try this
Copy code
await new Promise(resolve => {
   send_signed_transaction(...).once(async () => {
      // do awaited work
      resolve()
  })
})
return response(200)
a
That worked
Thanks 🔥
t
Not to be nosy but shouldn't the signed transaction be sent directly from the frontend which then sends you the transaction ID for your records
i
haha - no cause we unpack the signed Tx and have some logic there :)