dcrd/internal
Dave Collins 59e1d24513
blockchain: Make zero val threshold tuple invalid.
This makes the zero value for a threshold state tuple act as the invalid
state and choice instead of using magic sentinel values.

In practice, callers should be checking the error of any methods before
using any other returned values, however, the code typically tries to
adopt a defense in depth model where it makes sure unusable/invalid
values are also returned in error cases to help make it obvious when a
caller incorrectly uses the returned value without checking the error.

It accomplishes this by reording the threshold states so that the
invalid state is 0 and converting the choice field to a pointer to the
relevant choice as opposed to a choice index.  That way the zero value
for the overall type is the invalid state and nil the choice, exactly as
expected.

In addition to being more ergonomic and inline with typical Go code, it
has a few additional benefits:

* Makes the type harder to misuse
* Simplifies identification of a specific resulting choice for votes
  that have multiple affirmative choices since the choice can be checked
  by its ID instead of a tightly coupled array index
* Provides an easy method to distinguish between a vote that failed due
  to a majority vote and one that failed due to expiring before a
  majority result was achieved
2023-03-13 21:43:40 -05:00
..
blockchain blockchain: Make zero val threshold tuple invalid. 2023-03-13 21:43:40 -05:00
fees multi: Go 1.19 doc comment formatting. 2022-07-30 04:08:58 -05:00
integration/rpctests rpctests: Build constraint for util too. 2022-12-05 13:37:38 -06:00
limits main: Remove old style build constraints. 2022-12-05 09:04:01 -06:00
mempool multi: Use atomic types in unexported modules. 2023-02-13 10:02:56 -06:00
mining multi: Use atomic types in unexported modules. 2023-02-13 10:02:56 -06:00
netsync netsync: Re-request data sooner after peer disconnect. 2023-03-08 09:07:32 -06:00
progresslog multi: Go 1.19 doc comment formatting. 2022-07-30 04:08:58 -05:00
rpcserver blockchain: Make zero val threshold tuple invalid. 2023-03-13 21:43:40 -05:00
staging multi: Go 1.19 doc comment formatting. 2022-07-30 04:08:58 -05:00
version main: Remove old style build constraints. 2022-12-05 09:04:01 -06:00