Move code from script to wallet

Continues #4754
If you keep the ifdefs, this include needs to be in #ifdef ENABLE_WALLET.