Rm Error and Prd AnkFlag, Add Cipher, add error field for each message

This commit is contained in:
Sosthene 2024-05-27 11:49:53 +02:00
parent c5ff2e2edb
commit 72089b8545

View File

@ -139,8 +139,7 @@ impl Envelope {
pub enum AnkFlag { pub enum AnkFlag {
NewTx, NewTx,
Faucet, Faucet,
Prd, Cipher,
Error,
Unknown, Unknown,
} }
@ -149,8 +148,7 @@ impl From<&str> for AnkFlag {
match value { match value {
"NewTx" => Self::NewTx, "NewTx" => Self::NewTx,
"Faucet" => Self::Faucet, "Faucet" => Self::Faucet,
"Prd" => Self::Prd, "Cipher" => Self::Cipher,
"Error" => Self::Error,
_ => Self::Unknown, _ => Self::Unknown,
} }
} }
@ -167,19 +165,17 @@ impl AnkFlag {
match byte { match byte {
0 => Self::NewTx, 0 => Self::NewTx,
1 => Self::Faucet, 1 => Self::Faucet,
2 => Self::Prd, 2 => Self::Cipher,
9 => Self::Error,
_ => Self::Unknown, _ => Self::Unknown,
} }
} }
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
match self { match self {
Self::NewTx => "new_tx", Self::NewTx => "NewTx",
Self::Faucet => "faucet", Self::Faucet => "Faucet",
Self::Prd => "prd", Self::Cipher => "Cipher",
Self::Error => "error", Self::Unknown => "Unknown",
Self::Unknown => "unknown",
} }
} }
} }
@ -189,13 +185,14 @@ impl AnkFlag {
pub struct FaucetMessage { pub struct FaucetMessage {
pub sp_address: String, pub sp_address: String,
pub commitment: String, pub commitment: String,
pub error: Option<AnkError>,
} }
impl FaucetMessage { impl FaucetMessage {
pub fn new(sp_address: String) -> Self { pub fn new(sp_address: String) -> Self {
let mut buf = [0u8;64]; let mut buf = [0u8;64];
thread_rng().fill_bytes(&mut buf); thread_rng().fill_bytes(&mut buf);
Self { sp_address, commitment: buf.to_lower_hex_string() } Self { sp_address, commitment: buf.to_lower_hex_string(), error: None }
} }
} }
@ -204,6 +201,7 @@ impl FaucetMessage {
pub struct NewTxMessage { pub struct NewTxMessage {
pub transaction: String, pub transaction: String,
pub tweak_data: Option<String>, pub tweak_data: Option<String>,
pub error: Option<AnkError>,
} }
impl NewTxMessage { impl NewTxMessage {
@ -211,22 +209,25 @@ impl NewTxMessage {
Self { Self {
transaction, transaction,
tweak_data, tweak_data,
error: None,
} }
} }
} }
#[derive(Debug, Serialize, Deserialize, Tsify)] #[derive(Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)] #[tsify(into_wasm_abi, from_wasm_abi)]
pub struct UnknownMessage { pub struct CipherMessage {
pub sender: String, pub sender: String,
pub message: String, pub message: String,
pub error: Option<AnkError>,
} }
impl UnknownMessage { impl CipherMessage {
pub fn new(sender: String, message: String) -> Self { pub fn new(sender: String, message: String) -> Self {
Self { Self {
sender, sender,
message, message,
error: None,
} }
} }
} }