Просмотр исходного кода

[contract/dao] impl daobulla try into for shareaddrs

ertosns 2 лет назад
Родитель
Сommit
567b334b95
1 измененных файлов с 12 добавлено и 0 удалено
  1. 12 0
      src/contract/dao/src/model.rs

+ 12 - 0
src/contract/dao/src/model.rs

@@ -28,6 +28,7 @@ use darkfi_serial::{SerialDecodable, SerialEncodable};
 #[cfg(feature = "client")]
 use darkfi_serial::async_trait;
 
+use darkfi_sdk::crypto::{ShareAddress, ShareAddressType};
 /// A `DaoBulla` represented in the state
 #[derive(Debug, Copy, Clone, Eq, PartialEq, SerialEncodable, SerialDecodable)]
 pub struct DaoBulla(pallas::Base);
@@ -65,6 +66,17 @@ darkfi_sdk::fp_from_bs58!(DaoBulla);
 darkfi_sdk::fp_to_bs58!(DaoBulla);
 darkfi_sdk::ty_from_fp!(DaoBulla);
 
+impl TryInto<DaoBulla> for ShareAddress {
+    type Error = String;
+    fn try_into(self) -> Result<DaoBulla, Self::Error> {
+        if self.prefix != ShareAddressType::DaoBulla {
+            return Err("wrong prefix".to_string())
+        }
+        let sk: Result<DaoBulla, ContractError> = DaoBulla::from_bytes(self.raw);
+        Ok(sk.unwrap())
+    }
+}
+
 /// A `DaoProposalBulla` represented in the state
 #[derive(Debug, Copy, Clone, Eq, PartialEq, SerialEncodable, SerialDecodable)]
 pub struct DaoProposalBulla(pallas::Base);