-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
651 additions
and
300 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
pub mod protocol; | ||
pub mod reqrep; |
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,85 @@ | ||
use std::fmt::Display; | ||
|
||
use libp2p::request_response::ProtocolName; | ||
const PROTOCOL_PREFIX: &str = "/account_abstraction/erc4337/req"; | ||
|
||
#[derive(Clone, Debug, Copy)] | ||
pub enum Protocol { | ||
Status, | ||
Goodbye, | ||
Ping, | ||
MetaData, | ||
PooledUserOpHashes, | ||
PooledUserOpsByHash, | ||
} | ||
|
||
impl Display for Protocol { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let result = match self { | ||
Protocol::Status => "status", | ||
Protocol::Goodbye => "goodbye", | ||
Protocol::Ping => "ping", | ||
Protocol::MetaData => "metadata", | ||
Protocol::PooledUserOpHashes => "pooled_user_ops_hashes", | ||
Protocol::PooledUserOpsByHash => "pooled_user_ops_by_hash", | ||
}; | ||
f.write_str(result) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ProtocolId { | ||
/// The RPC message type/name. | ||
pub message_name: Protocol, | ||
|
||
/// The version of the RPC. | ||
pub version: Version, | ||
|
||
/// The encoding of the RPC. | ||
pub encoding: Encoding, | ||
|
||
protocol_id: String, | ||
} | ||
|
||
impl ProtocolId { | ||
fn new(message_name: Protocol, version: Version, encoding: Encoding) -> Self { | ||
let protocol_id = format!( | ||
"{}/{}/{}/{}", | ||
PROTOCOL_PREFIX, message_name, version, encoding | ||
); | ||
Self { | ||
message_name, | ||
version, | ||
encoding, | ||
protocol_id, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Version { | ||
V1, | ||
} | ||
|
||
impl Display for Version { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str("1") | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Encoding { | ||
SSZSnappy, | ||
} | ||
|
||
impl Display for Encoding { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str("ssz_snappy") | ||
} | ||
} | ||
|
||
impl ProtocolName for ProtocolId { | ||
fn protocol_name(&self) -> &[u8] { | ||
self.protocol_id.as_bytes() | ||
} | ||
} |
Oops, something went wrong.