From 97caa0347684f79832dd4651949f1038f16f3ea0 Mon Sep 17 00:00:00 2001 From: irriden Date: Fri, 18 Aug 2023 23:53:37 +0000 Subject: [PATCH 1/3] glyph: create signer types --- glyph/src/types.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/glyph/src/types.rs b/glyph/src/types.rs index 0b4a2ec..63f8dc0 100644 --- a/glyph/src/types.rs +++ b/glyph/src/types.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use anyhow::{anyhow, Result}; use serde::{Deserialize, Serialize}; use std::str::FromStr; @@ -104,3 +104,25 @@ pub struct WifiParams { pub ssid: String, pub password: String, } + +#[derive(Serialize, Deserialize, Debug, Clone, Copy)] +pub enum SignerType { + ReceiveOnly, + ReceiveSend, +} + +impl SignerType { + pub fn to_byte(&self) -> u8 { + match self { + SignerType::ReceiveOnly => 0x5a, + SignerType::ReceiveSend => 0x8c, + } + } + pub fn from_byte(b: u8) -> Result { + match b { + 0x5a => Ok(SignerType::ReceiveOnly), + 0x8c => Ok(SignerType::ReceiveSend), + _ => Err(anyhow!("SignerType byte incorrect: {:x}", b)), + } + } +} From 3733003485f98941d514833202e98579e55355b9 Mon Sep 17 00:00:00 2001 From: irriden Date: Sat, 19 Aug 2023 00:05:35 +0000 Subject: [PATCH 2/3] glyph: add default for signertypes --- glyph/src/types.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/glyph/src/types.rs b/glyph/src/types.rs index 63f8dc0..0785600 100644 --- a/glyph/src/types.rs +++ b/glyph/src/types.rs @@ -1,5 +1,6 @@ use anyhow::{anyhow, Result}; use serde::{Deserialize, Serialize}; +use std::default::Default; use std::str::FromStr; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] @@ -126,3 +127,9 @@ impl SignerType { } } } + +impl Default for SignerType { + fn default() -> Self { + SignerType::ReceiveSend + } +} From 64d5c8aa166c4ff46b0817bc4011f39a3c949de7 Mon Sep 17 00:00:00 2001 From: irriden Date: Sat, 19 Aug 2023 17:59:54 +0000 Subject: [PATCH 3/3] glyph: add partialeq for signertype --- glyph/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glyph/src/types.rs b/glyph/src/types.rs index 0785600..2370176 100644 --- a/glyph/src/types.rs +++ b/glyph/src/types.rs @@ -106,7 +106,7 @@ pub struct WifiParams { pub password: String, } -#[derive(Serialize, Deserialize, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] pub enum SignerType { ReceiveOnly, ReceiveSend,