fixed sql errors in getSpentOutputs and getOutputs.
fixed logic error in handle_async_block
fixed trying to access closed socket (Bad File Descriptor exception) by ensuring the socket is open before executing the actual handle_read/write