I'm working on a site that has wallet-like functionality in ruby/rails. I'm wondering the best way to process withdraws. My first inclination is to do something like this:
def process_withdraw client.wallet_passphrase(ENV['wallet_password'], 10) # unlock the wallet for 10 seconds client.send_to_address(address, amount) # send coins client.wallet_lock # re-lock the wallet end
However, I'm concerned that with many concurrent withdraws I could run into race conditions. For example, if "Process A" unlocks the wallet and sends coins, but then "Process B" jumps in and unlocks the wallet but before it can send coins, "Process A" locks the wallet. So when "Process B" tries to send, the wallet is locked.
Is this a legitimate concern? Do I need to re-lock the wallet or is it safe enough to just wait for the 10 second timeout? Is it worth writing some sort of queue system for my client?
Thanks a lot in advance!