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