state.rs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2022 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use darkfi_sdk::{
  19. crypto::{MerkleNode, Nullifier, PublicKey},
  20. pasta::{group::Group, pallas},
  21. };
  22. use darkfi_serial::{SerialDecodable, SerialEncodable};
  23. #[derive(SerialEncodable, SerialDecodable)]
  24. pub struct DaoBulla(pallas::Base);
  25. impl DaoBulla {
  26. pub fn inner(&self) -> pallas::Base {
  27. self.0
  28. }
  29. }
  30. impl From<pallas::Base> for DaoBulla {
  31. fn from(x: pallas::Base) -> Self {
  32. Self(x)
  33. }
  34. }
  35. #[derive(SerialEncodable, SerialDecodable)]
  36. pub struct ProposalVotes {
  37. // TODO: Might be more logical to have `yes_votes_commit` and `no_votes_commit`
  38. /// Weighted vote commit
  39. pub yes_votes_commit: pallas::Point,
  40. /// All value staked in the vote
  41. pub all_votes_commit: pallas::Point,
  42. /// Vote nullifiers
  43. pub vote_nullifiers: Vec<Nullifier>,
  44. }
  45. impl ProposalVotes {
  46. pub fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
  47. self.vote_nullifiers.iter().any(|n| n == nullifier)
  48. }
  49. }
  50. impl Default for ProposalVotes {
  51. fn default() -> Self {
  52. Self {
  53. yes_votes_commit: pallas::Point::identity(),
  54. all_votes_commit: pallas::Point::identity(),
  55. vote_nullifiers: vec![],
  56. }
  57. }
  58. }
  59. #[derive(SerialEncodable, SerialDecodable)]
  60. pub struct DaoMintParams {
  61. pub dao_bulla: DaoBulla,
  62. }
  63. #[derive(SerialEncodable, SerialDecodable)]
  64. pub struct DaoMintUpdate {
  65. pub dao_bulla: DaoBulla,
  66. }
  67. #[derive(Clone, SerialEncodable, SerialDecodable)]
  68. pub struct ProposeInput {
  69. pub value_commit: pallas::Point,
  70. pub merkle_root: MerkleNode,
  71. pub signature_public: PublicKey,
  72. }
  73. #[derive(SerialEncodable, SerialDecodable)]
  74. pub struct DaoProposeParams {
  75. pub dao_merkle_root: MerkleNode,
  76. pub token_commit: pallas::Base,
  77. pub proposal_bulla: pallas::Base,
  78. pub ciphertext: Vec<u8>,
  79. pub ephem_public: PublicKey,
  80. pub inputs: Vec<ProposeInput>,
  81. }
  82. #[derive(SerialEncodable, SerialDecodable)]
  83. pub struct DaoProposeUpdate {
  84. pub proposal_bulla: pallas::Base,
  85. }
  86. #[derive(SerialEncodable, SerialDecodable)]
  87. pub struct VoteInput {
  88. pub nullifier: Nullifier,
  89. pub vote_commit: pallas::Point,
  90. pub merkle_root: MerkleNode,
  91. pub signature_public: PublicKey,
  92. }
  93. #[derive(SerialEncodable, SerialDecodable)]
  94. pub struct DaoVoteParams {
  95. pub token_commit: pallas::Base,
  96. pub proposal_bulla: pallas::Base,
  97. pub yes_vote_commit: pallas::Point,
  98. pub ciphertext: Vec<u8>,
  99. pub ephem_public: PublicKey,
  100. pub inputs: Vec<VoteInput>,
  101. }
  102. #[derive(SerialEncodable, SerialDecodable)]
  103. pub struct DaoVoteUpdate {
  104. pub proposal_bulla: pallas::Base,
  105. // bad but lets get it just working...
  106. pub proposal_votes: ProposalVotes,
  107. //pub vote_nullifiers: Vec<Nullifier>,
  108. //pub yes_vote_commit: pallas::Point,
  109. //pub all_vote_commit: pallas::Point,
  110. }
  111. #[derive(SerialEncodable, SerialDecodable)]
  112. pub struct DaoExecParams {
  113. pub proposal: pallas::Base,
  114. pub coin_0: pallas::Base,
  115. pub coin_1: pallas::Base,
  116. pub yes_votes_commit: pallas::Point,
  117. pub all_votes_commit: pallas::Point,
  118. pub input_value_commit: pallas::Point,
  119. }
  120. #[derive(SerialEncodable, SerialDecodable)]
  121. pub struct DaoExecUpdate {
  122. pub proposal: pallas::Base,
  123. }