Move global wallet variables to WalletContext struct
This is a backport of [[https://github.com/bitcoin/bitcoin/pull/19101 | [[https://github.com/bitcoin/bitcoin/pull/19101 | core#19101]]]] and [[https://github.com/bitcoin/bitcoin/pull/22992 | [[https://github.com/bitcoin/bitcoin/pull/22992 | core#22992]]]]