lib.rs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2025 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::{error::ContractError, pasta::pallas};
  19. use darkfi_serial::{SerialDecodable, SerialEncodable};
  20. #[cfg(feature = "client")]
  21. use darkfi_serial::async_trait;
  22. /// Functions available in the contract
  23. #[repr(u8)]
  24. pub enum ContractFunction {
  25. Register = 0x00,
  26. Deregister = 0x01,
  27. }
  28. impl TryFrom<u8> for ContractFunction {
  29. type Error = ContractError;
  30. fn try_from(b: u8) -> Result<Self, Self::Error> {
  31. match b {
  32. 0x00 => Ok(Self::Register),
  33. 0x01 => Ok(Self::Deregister),
  34. _ => Err(ContractError::InvalidFunction),
  35. }
  36. }
  37. }
  38. /// Function parameters
  39. #[derive(Debug, Clone, Copy, SerialEncodable, SerialDecodable)]
  40. pub struct HelloParams {
  41. /// X coordinate of the public key
  42. pub x: pallas::Base,
  43. /// Y coordinate of the public key
  44. pub y: pallas::Base,
  45. }
  46. #[cfg(not(feature = "no-entrypoint"))]
  47. /// WASM entrypoint functions
  48. pub mod entrypoint;
  49. /// This is a sled tree that will be created
  50. pub const HELLO_CONTRACT_MEMBER_TREE: &str = "members";
  51. /// zkas circuit namespace
  52. pub const HELLO_CONTRACT_ZKAS_SECRETCOMMIT_NS: &str = "SecretCommitment";