210 Commits

Author SHA1 Message Date
jholdstock
96b99f35d7 webapi: Add expired/missed to /vspinfo. 2023-09-04 16:51:09 +01:00
jholdstock
54e243526e multi: Display expired/missed tickets on webpage.
Revoked ticket count is replaced by separate counts for expired/missed
tickets.

/vspinfo API response remains unchanged.
2023-09-04 16:47:00 +01:00
jholdstock
fc1f7f2955 webapi: Fix revoked % calculation. 2023-09-04 16:47:00 +01:00
jholdstock
1dbcb785df webapi: Display testnet as a banner.
A banner notice is now displayed when a VSP is running on testnet
rather than including it in the row of statistics.
2023-09-04 16:47:00 +01:00
jholdstock
0a38bd8152 multi: Replace interface{} with 'any' alias 2023-08-18 14:32:17 +01:00
jholdstock
820f130f59 webapi: Add test for securecookie error.
A simple test to ensure an error string returned by the securecookie lib
does not change when we upgrade to newer versions. Important because
vspd checks for this error using string comparison.
2023-08-18 14:31:26 +01:00
Jamie Holdstock
d8bcc9292f rpc: Ignore another "duplicate tx" error.
sendrawtransaction is expected to fail if the transaction already exists in the mempool or a mined block. dcrd returns two different errors which can indicate this situation. Handling for one of them already existed, and this commit adds handling for the other.
2023-07-04 11:27:57 +01:00
jholdstock
a88c261cb1 webapi: Display decoded fee tx, not just raw bytes
When searching for a ticket in the admin interface, use GetRawTransaction RPC to get the decoded transaction and display it as formatted JSON.
2023-06-27 14:52:24 +01:00
jholdstock
4dc2cc4d8d webapi: Use raw whitespace to format JSON.
No need to manually construct HTML in this formatting func, it can simply deal with whitespace and then use <pre> tags to display.

Add some tests to validate behaviour.
2023-06-27 14:52:24 +01:00
jholdstock
78cf99bc2c webapi: Use input type "search" for ticket hash.
The "search" input type is functionally the same as "text" but has a nice extra property - most browsers will render it with a "Clear" button to wipe the current input.

Also disable spellchecking on this input.
2023-06-27 14:52:24 +01:00
Jamie Holdstock
f46ffcb60d
docs: Review and polish existing docs. (#390)
Also includes a couple of updates to comments in webapi code.
2023-06-13 13:22:57 -05:00
jholdstock
9863636978 webapi: Update to gin 1.9.1. 2023-06-13 08:48:56 +01:00
jholdstock
7cb4681639 main: Use latest dcrd deps. 2023-06-11 11:42:53 +01:00
Jamie Holdstock
203bf7d2e6
build: Update linter to 1.53.2 (#384)
* build: Update linter to 1.53.2

* database: Rename helpers.go to encoding.go

* database: Ignore json.Marshal errors.
2023-06-05 09:39:01 -05:00
Jamie Holdstock
08ea48f7a3
Update decred dependencies. (#378)
* webapi: Use types 2.0.0

* v3tool: Use types 2.0.0

* Update decred dependencies.
2023-04-12 08:16:29 -05:00
Jamie Holdstock
6b99c5d2b5
webapi: Use types 2.0.0 (#376)
* webapi: Use types 2.0.0

* v3tool: Use types 2.0.0
2023-04-12 08:12:53 -05:00
jholdstock
62803147f0 webapi: Rate limit for admin login requests.
Only allow 3 requests per second. Return "429 Too Many Requests" when this rate is exceeded.
2023-03-15 10:45:54 +00:00
Jamie Holdstock
d00ba70f94
vspd: Fix invalid default config log level. (#371)
* vspd: Fix invalid default config log level.

slog.LevelDebug.String() returns "DBG" which is not valid per the config validation rules specified below. Hard-code "debug" instead.

* Update year.
2023-02-24 09:55:25 -05:00
Jamie Holdstock
7718476caf
webapi: Move VSP closed check to middleware.
Checking this in middleware not only removes duplicated code from each of the handlers, but also makes things more efficient. Previously, dcrd/dcrwallet/database clients were initialized (and could possibly cause errors) **before** checking if the VSP is closed. Now the check happens before those other things.

Also bundled with some improvements to setaltsignaddr_test.go which I implemented along the way.
2023-02-17 20:44:13 +00:00
Jamie Holdstock
6d872db60e
Rename APIError to ErrorResponse. (#360)
Last commit before tagging v1.0.0 of the types module. The name ErrorResponse is consistent with all other response types.
2022-11-22 17:09:06 +08:00
Jamie Holdstock
ed1fac1a2a
Add types module for API requests/responses/errors. (#356)
* Remove helper func getCommitmentAddress.

This function is only used in one place so removing it does not introduce any duplication. Removing the func also removes the need for errors.Is comparison, which will be very useful in upcoming changes.

* Rename apiError to ErrorCode.

* Don't use inline type for API errors.

* Export webapi errors.

* Export webapi request/responses.

* Add types module for API requests/responses/errors
2022-11-18 15:06:47 -05:00
jholdstock
32790984fe Make database backups optional.
Periodic database backups are no longer started automatically in database.Open(), and the backup written by database.Close() can now be disabled.

Only vspd itself requires backups, they are not useful for test code or future upcoming tools such as vote-validator.
2022-09-29 14:54:40 +01:00
jholdstock
e23e3729e8 Helper func for stdout logger.
Also reuse the logger in database tests, dont create a new one each time.
2022-06-29 08:31:44 +01:00
jholdstock
65fab01225 Remove remaining global loggers.
This removes all of the global loggers from the project and replaces them with loggers which are instantiated in vspd.go and passed down as params.

To support this, the background package was removed. It only contained one file so it was a bit pointless anyway. It only existed so background tasks could have their own named logger.
2022-06-29 08:31:44 +01:00
jholdstock
ebcfe0e5e9 Remove global logger from webapi. 2022-06-23 09:11:28 +01:00
jholdstock
01b0df2d7a Remove global loggers from components.
- Web API Cache
- Recovery Middleware
- Database upgrades
- Address Generator
2022-06-13 14:50:16 +01:00
jholdstock
75026f5e91 Clean up use of shutdown context.
- Rename all instances to "shutdownCtx" to be really explicit. This context is special in that it can be closed at any time without warning, so it should be obvious to the reader.
- Don't use shutdownCtx in RPC clients. Clients should not stop working immediately when shutdown is signalled, they need to keep working while the process is shutting down.
2022-05-19 07:59:44 +01:00
Jamie Holdstock
d8dd02433c Move CanTicketVote out of dcrd RPC client.
`CanTicketVote` doesn't really fit into the RPC client code as it is more of a business logic function. Moving it into the webapi package is more appropriate.
2022-05-06 11:14:22 +01:00
jholdstock
49f68fd5ec Rename test.
I assume "hist at max" is leftover from when it was possible to set more than one alt sign address.
2022-05-06 11:14:22 +01:00
jholdstock
5aa8f9faaf Create testNode up-front.
Theres no need to declare separate  vars for the testNode and then create it later, it can just be created up-front.
2022-05-06 11:14:22 +01:00
jholdstock
6057c2b273 Run webapi tests as sub-tests.
Running as sub-tests has the benefit of automatically logging the test name, no need to include it in failure messages manually. It even works if the test panics.
2022-05-06 11:14:22 +01:00
jholdstock
b32bb56032 Remove hash param from CanTicketVote.
CanTicketVote already has the full rawTx, so it doesn't need the hash passed in separately.
2022-05-06 11:14:22 +01:00
Jamie Holdstock
78bb28056c
Remove global cache variable. (#341)
* Remove global cache variable.

Rather than maintaining cached data in a global variable, instantiate a cache struct and keep it in the `Server` struct.

* Store net params in RPC clients.

This means net params only need to be supplied once at startup, and also removes a global instance of net params in `background.go`.
2022-03-30 11:00:42 -05:00
jholdstock
c91ec5c697 Use time.After instead of tickers. 2022-03-28 16:37:25 +01:00
jholdstock
3b1812e98f Minor cleanups for new helpers.
- Ensure errors are properly wrapped with `%w`
- Error strings should not starts with caps.
- Add missing params to "Bad signature" error log
2022-03-28 16:37:25 +01:00
jholdstock
37d51df546 Remove global vars from webapi package. 2022-03-28 08:54:09 +01:00
Ukane philemon
4d4f9c8ca0
add new helper functions 2022-03-28 08:26:08 +01:00
jholdstock
9fa1012f3d Add some new linters. 2022-03-21 14:49:40 +00:00
Ukane philemon
3bb2f65151
add votingwalletsonline and totalvotingwallets to /vspinfo 2022-03-17 10:40:47 +00:00
Ukane philemon
655e5756af
Using error.Is and error.As
* This allow using error.Is and error.As within vsp.
* Add test cases for apiError type.
2022-03-15 10:20:07 +00:00
Jamie Holdstock
da1cb8f916
Enable treasury vote choices. (#319)
This allows both tspend and treasury policies to be set by clients on a per-ticket basis. Preferences can be set when initially registering a ticket with `/payfee`, and can be later updated using `/setvotechoices`.

Any requests which alter treasury/tspend policy will be stored in the database using the existing accountability system.

**Note:** This does not include consistency checking, it will need to be added later when dcrwallet has an RPC to retrieve policies in batches.
2022-02-04 14:14:49 -05:00
Jamie Holdstock
dcbf8a2c18
Ensure previous vote choices are remembered. (#323) 2022-02-02 10:04:53 -05:00
Jamie Holdstock
040ed56f11
Use DCP-0010 status to calculate fees.
vspd will now call dcrd RPC `getblockchaininfo` to determine if DCP-0010 is active, and take that information into consideration when calculating ticket registration fee.
2022-01-20 08:54:52 +00:00
Ukane philemon
74aa7bcd13
Added alternate signing address to /ticketstatus response (#314) 2022-01-17 10:50:46 +00:00
ukane-philemon
0b78c9c2da Show altsignaddress req/res in admin UI 2022-01-13 12:40:16 +00:00
jholdstock
ab5aa4dd6d Clarify "setaltsig" terminology.
Stardardize "alt sig"/"alt signature"/"alt signing address" terminology to "alternate signing address".
2021-11-16 14:49:13 +00:00
jholdstock
b1a68a94fe Use constants for web context keys. 2021-11-16 14:33:39 +00:00
jholdstock
6acc5be10c Add dcrd to VSP status.
This renames "Voting wallet status" to "VSP status" and it now includes the status of the local dcrd instance. This change impacts both the /admin page of the UI, and the response of the /admin/status API endpoint.
2021-11-16 14:33:39 +00:00
jholdstock
d337e0a321 Delay dcrd client error handling.
Errors generated during dcrd client creation were previously handled in middleware, and request handling was terminated immediately.

Now the error handling is delayed by adding the error details to the request context. This enables downstream handlers to decide what to do with the error.
2021-11-16 14:33:39 +00:00
jholdstock
6260e4ee5b Add alternate sign address to ticket search result 2021-11-14 11:00:39 +00:00