Make all wallet queries into stored procedures

This supersedes #47