generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract events * Use a macro to add From traits * Expose TestEvent
- Loading branch information
Showing
21 changed files
with
649 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use alloy::primitives::U256; | ||
use alloy_primitives::ruint::ParseError; | ||
use core::fmt; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct E3id(pub String); | ||
impl fmt::Display for E3id { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str(&self.0) | ||
} | ||
} | ||
|
||
impl E3id { | ||
pub fn new(id: impl Into<String>) -> Self { | ||
Self(id.into()) | ||
} | ||
} | ||
|
||
impl From<u32> for E3id { | ||
fn from(value: u32) -> Self { | ||
E3id::new(value.to_string()) | ||
} | ||
} | ||
|
||
impl From<String> for E3id { | ||
fn from(value: String) -> Self { | ||
E3id::new(value) | ||
} | ||
} | ||
|
||
impl From<&str> for E3id { | ||
fn from(value: &str) -> Self { | ||
E3id::new(value) | ||
} | ||
} | ||
|
||
impl TryFrom<E3id> for U256 { | ||
type Error = ParseError; | ||
fn try_from(value: E3id) -> Result<Self, Self::Error> { | ||
U256::from_str_radix(&value.0, 10) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/ciphernode/events/src/enclave_event/ciphernode_added.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct CiphernodeAdded { | ||
pub address: String, | ||
pub index: usize, | ||
pub num_nodes: usize, | ||
} | ||
|
||
impl Display for CiphernodeAdded { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"address: {}, index: {}, num_nodes: {}", | ||
self.address, self.index, self.num_nodes | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/ciphernode/events/src/enclave_event/ciphernode_removed.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct CiphernodeRemoved { | ||
pub address: String, | ||
pub index: usize, | ||
pub num_nodes: usize, | ||
} | ||
|
||
impl Display for CiphernodeRemoved { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"address: {}, index: {}, num_nodes: {}", | ||
self.address, self.index, self.num_nodes | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/ciphernode/events/src/enclave_event/ciphernode_selected.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::E3id; | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct CiphernodeSelected { | ||
pub e3_id: E3id, | ||
pub threshold_m: usize, | ||
} | ||
|
||
impl Display for CiphernodeSelected { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"e3_id: {}, threshold_m: {}", | ||
self.e3_id, self.threshold_m, | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/ciphernode/events/src/enclave_event/ciphertext_output_published.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::E3id; | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct CiphertextOutputPublished { | ||
pub e3_id: E3id, | ||
pub ciphertext_output: Vec<u8>, | ||
} | ||
|
||
impl Display for CiphertextOutputPublished { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "e3_id: {}", self.e3_id,) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/ciphernode/events/src/enclave_event/decryptionshare_created.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::E3id; | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "anyhow::Result<()>")] | ||
pub struct DecryptionshareCreated { | ||
pub decryption_share: Vec<u8>, | ||
pub e3_id: E3id, | ||
pub node: String, | ||
} | ||
|
||
impl Display for DecryptionshareCreated { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "e3_id: {}, node: {}", self.e3_id, self.node,) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct Die; | ||
impl Display for Die { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "Die",) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/ciphernode/events/src/enclave_event/e3_request_complete.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::E3id; | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
/// E3RequestComplete event is a local only event | ||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct E3RequestComplete { | ||
pub e3_id: E3id, | ||
} | ||
|
||
impl Display for E3RequestComplete { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "e3_id: {}", self.e3_id) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/ciphernode/events/src/enclave_event/e3_requested.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::{E3id, Seed}; | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct E3Requested { | ||
pub e3_id: E3id, | ||
pub threshold_m: usize, | ||
pub seed: Seed, | ||
pub params: Vec<u8>, | ||
pub src_chain_id: u64, | ||
} | ||
|
||
impl Display for E3Requested { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"e3_id: {}, threshold_m: {}, src_chain_id: {}, seed: {}, params: <omitted>", | ||
self.e3_id, self.threshold_m, self.src_chain_id, self.seed | ||
) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/ciphernode/events/src/enclave_event/enclave_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::{self, Display}; | ||
|
||
pub trait FromError { | ||
type Error; | ||
fn from_error(err_type: EnclaveErrorType, error: Self::Error) -> Self; | ||
} | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "()")] | ||
pub struct EnclaveError { | ||
pub err_type: EnclaveErrorType, | ||
pub message: String, | ||
} | ||
|
||
impl Display for EnclaveError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{:?}", self) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub enum EnclaveErrorType { | ||
Evm, | ||
KeyGeneration, | ||
PublickeyAggregation, | ||
IO, | ||
PlaintextAggregation, | ||
Decryption, | ||
Sortition, | ||
Data, | ||
} | ||
|
||
impl EnclaveError { | ||
pub fn new(err_type: EnclaveErrorType, message: &str) -> Self { | ||
Self { | ||
err_type, | ||
message: message.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl FromError for EnclaveError { | ||
type Error = anyhow::Error; | ||
fn from_error(err_type: EnclaveErrorType, error: Self::Error) -> Self { | ||
Self { | ||
err_type, | ||
message: error.to_string(), | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/ciphernode/events/src/enclave_event/keyshare_created.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::E3id; | ||
use actix::Message; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
use std::fmt::Display; | ||
|
||
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[rtype(result = "anyhow::Result<()>")] | ||
pub struct KeyshareCreated { | ||
pub pubkey: Vec<u8>, | ||
pub e3_id: E3id, | ||
pub node: String, | ||
} | ||
|
||
impl Display for KeyshareCreated { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "e3_id: {}, node: {}", self.e3_id, self.node,) | ||
} | ||
} |
Oops, something went wrong.