Note: this is a squashing of two commits from core#21391 and core#21767. The second commit fixes an issue introduced by the first, when the node context does not have a chainmanager.
rest: Use existing NodeContext
https://github.com/bitcoin/bitcoin/pull/21391/commits/d7824acdb9b18fe8f151771a83ccae1681f16c66
rest: Add GetChainman function and use it
This is not the cleanest change but:
- It fixes the erroneous use of RPC's Ensure*() in rest.cpp, which cause crashes in REST contexts.
RPC code wraps all calls in a try/except, REST code does not. Ensure*(), being part of RPC, expects that its throw's will get caught by a try/except. But if you use Ensure*() in REST code, since it doesn't have a try/except wrap, a crash will happen.
- It is consistent with other functions like GetMemPool.
Someone can probably make this a bit prettier.
https://github.com/bitcoin/bitcoin/pull/21767/commits/9ecade14252ad1972f668d2d2e4ef44fdfcb944a
This is a backport of core#21391 [7/14]
Depends on D11584