Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add non-zero variant of NeptuneCoins #180

Open
dan-da opened this issue Aug 28, 2024 · 1 comment
Open

add non-zero variant of NeptuneCoins #180

dan-da opened this issue Aug 28, 2024 · 1 comment

Comments

@dan-da
Copy link
Collaborator

dan-da commented Aug 28, 2024

Presently zero is representable in NeptuneCoins, eg with NeptuneCoins::new(0) or NeptuneCoins::zero(). Some things like balances do need to represent zero, so that is good.

However other areas of the code expect non-zero values. For example when sending a transaction with native coins, each address should have a corresponding non-zero amount.

To that end, I'm thinking that we should add a NeptuneCoinsNonZero type that methods could use to be correct-by-construction. The type system (compiler) would guarantee non-zero values, so no need to validate. This is in-line with the parse, don't validate philosophy, which has two core ideas:

  1. Use a data structure that makes illegal states unrepresentable
  2. Push the burden of proof upward as far as possible, but no further.

Both types would share most code and be easily convertible, eg via impl From<NeptuneCoins> for NeptuneCoinsZero and impl TryFrom<NeptuneCoinsZero> for NeptuneCoins.

I plan to impl this in a PR I'm presently working on. This issue is mainly for discussion and documentation purposes.

@dan-da
Copy link
Collaborator Author

dan-da commented Aug 29, 2024

I just realized that NeptuneCoins is signed also. So I think what is really needed for the address/amount send use-case is NeptuneCoinsUnsignedNonZero.

Further consideration/review should be given to when/if it makes sense to have negative amounts in neptune-core. I don't immediately see a need for that, but I could very well be missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant