14 Commits

Author SHA1 Message Date
jholdstock
72b0411ee0 webapi: Refine server start/stop logging.
Don't log errors returned by server.Shutdown. They are exceedingly
unlikely, and there is nothing which can be done about them.

Moving the "Listening on..." log closer to where the server is actually
started reduces the chance of confusion. Also, logging the parsed
listener.Addr() string instead of the provided config string provides
extra debugging detail.
2023-09-16 08:29:17 +01:00
jholdstock
61b6460014 webapi: Use existing context for server shutdown.
The server will shutdown cleanly even if the passed context is already
canceled, so there is no need to pass a new context and blindly guess at
how long the server may need to stop.
2023-09-16 07:54:24 +01:00
jholdstock
f881179024 webapi: Make Run func blocking.
This updates the Run func to make it blocking. When the provided context
is canceled the server is cleanly shut down and the func returns.
2023-09-16 07:54:24 +01:00
jholdstock
0742e0ff1a webapi: Split Start func into New and Run funcs.
Separating the single func grants the calling code greater control over
the webapi lifecycle.
2023-09-16 07:54:24 +01:00
jholdstock
a7bb0cd9d7 webapi: Rename server to WebAPI.
Exporting this struct is a step towards breaking up the Start func into
a New func and Run func, enabling calling code to use:

    api := webapi.New()
    api.Run()

WebAPI is a more suitable name than server because it matches the
package name, and also it helps to distinguish WebAPI from the HTTP
server it uses internally (ie. webapi.server rather than server.server).
2023-09-16 07:54:24 +01:00
jholdstock
8a8cbe47b9 webapi: Create server when all components ready.
It's generally good practice to first create everything that can fail
and then create the final instance at once with the results versus doing
it piecemeal.

Piecemeal creation is typically more error prone and, while not a huge
concern here, it also ends up needlessly creating objects that are just
thrown away in the event of a later error.
2023-09-16 07:54:24 +01:00
jholdstock
a9f517f787 multi: Don't use RPC to determine DCP0010 status.
The activation heights are known for mainnet and testnet, so they can be
hard-coded and RPC does not need to be used.
2023-09-14 20:45:24 +01:00
jholdstock
280dc391be webapi: Keep DB and RPC clients inside cache.
Storing references to the database/dcrd/dcrwallet clients inside the
cache struct means they don't need to be passed in every time the cache
is updated.
2023-09-14 20:43:09 +01:00
jholdstock
d1766c362e webapi: Add Listen to webapi Config.
No need for this value to be passed in separately, it can be passed in
the same as every other config value.
2023-09-14 20:42:12 +01:00
jholdstock
a33bcbcbfd multi: Reuse CurrentVoteVersion helper.
Moving CurrentVoteVersion to the config package allows it to be reused
in vote-validator.
2023-09-14 20:39:49 +01:00
jholdstock
d5d1c3239c multi: Move netparams to internal.
A new internal package named config contains all of the hard-coded, network specific values used by vspd.
2023-09-14 20:39:49 +01:00
jholdstock
3967d9e24e webapi: Don't export funcs/vars unnecessarily. 2023-09-13 09:03:05 +01:00
jholdstock
3d4fb6ab99 version: Move package to internal. 2023-09-13 09:03:05 +01:00
jholdstock
7ad309c9aa webapi: Move package to internal. 2023-09-13 09:03:05 +01:00