Use SQL SUM instead Python sum() to calculate XCP supply

I need this commit to speed up the login in Counterwallet. If you are ok I make a PR also in master.