Skip to content

Commit 18594b4

Browse files
committed
initial trait
1 parent 8c32a93 commit 18594b4

50 files changed

Lines changed: 4795 additions & 214 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 3280 additions & 192 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
1-
[package]
2-
name = "mercury"
1+
[workspace]
2+
resolver = "2"
3+
4+
members = [
5+
"crates/core",
6+
"crates/chain-traits",
7+
"crates/cosmos",
8+
"crates/relay",
9+
"crates/cli",
10+
]
11+
12+
[workspace.package]
313
version = "0.1.0"
414
edition = "2024"
5-
description = ""
615
license = "MIT"
716
repository = "https://github.com/vaporif/mercury"
8-
readme = "README.md"
917

10-
[lints.clippy]
18+
[workspace.lints.clippy]
1119
all = { level = "warn", priority = -1 }
1220
pedantic = { level = "warn", priority = -1 }
1321
nursery = { level = "warn", priority = -1 }
1422
cargo = { level = "warn", priority = -1 }
1523
multiple_crate_versions = "allow"
1624

17-
[dependencies]
18-
tokio = { version = "1", features = ["rt-multi-thread", "macros", "signal"] }
19-
thiserror = "2"
20-
clap = { version = "4", features = ["derive", "env"] }
25+
[workspace.dependencies]
26+
async-trait = "0.1"
27+
eyre = "0.6"
28+
tracing = "0.1"
29+
tokio = { version = "1", features = ["full"] }
30+
futures = { version = "0.3", default-features = false }
31+
clap = { version = "4", features = ["derive"] }
2132
serde = { version = "1", features = ["derive"] }
2233
serde_json = "1"
23-
tracing = "0.1"
2434
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2535

26-
[dev-dependencies]
36+
mercury-core = { path = "crates/core" }
37+
mercury-chain-traits = { path = "crates/chain-traits" }
38+
mercury-cosmos = { path = "crates/cosmos" }
39+
mercury-relay = { path = "crates/relay" }
40+
mercury-cli = { path = "crates/cli" }
41+
42+
tendermint = { version = "0.40", features = ["secp256k1"] }
43+
tendermint-rpc = { version = "0.40", features = ["http-client"] }
44+
tendermint-proto = "0.40"
45+
tendermint-light-client-verifier = "0.40"
46+
ibc = { version = "0.56", default-features = false, features = ["serde"] }
47+
ibc-proto = { version = "0.51", default-features = false, features = ["serde"] }
48+
ibc-client-tendermint = { version = "0.56", default-features = false }
49+
prost = "0.13"
50+
prost-types = "0.13"
51+
tonic = { version = "0.12", features = ["tls", "tls-roots"] }
52+
secp256k1 = { version = "0.28", features = ["serde"] }
53+
sha2 = "0.10"
54+
bech32 = "0.9"

crates/chain-traits/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "mercury-chain-traits"
3+
version.workspace = true
4+
edition.workspace = true
5+
license.workspace = true
6+
7+
[lints]
8+
workspace = true
9+
10+
[dependencies]
11+
mercury-core = { workspace = true }
12+
async-trait = { workspace = true }

crates/chain-traits/src/events.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use mercury_core::ThreadSafe;
2+
3+
use crate::types::{HasChainTypes, HasPacketTypes};
4+
5+
pub trait CanExtractPacketEvents<Counterparty: HasChainTypes + ?Sized>:
6+
HasPacketTypes<Counterparty>
7+
{
8+
type SendPacketEvent: ThreadSafe;
9+
10+
fn try_extract_send_packet_event(event: &Self::Event) -> Option<Self::SendPacketEvent>;
11+
fn packet_from_send_event(event: &Self::SendPacketEvent) -> &Self::Packet;
12+
}

crates/chain-traits/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub mod types;
2+
pub mod messaging;
3+
pub mod queries;
4+
pub mod packet_queries;
5+
pub mod payload_builders;
6+
pub mod message_builders;
7+
pub mod packet_builders;
8+
pub mod events;
9+
pub mod tx;
10+
pub mod relay;
11+
12+
pub use types::*;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use async_trait::async_trait;
2+
use mercury_core::error::Result;
3+
4+
use crate::payload_builders::{CanBuildCreateClientPayload, CanBuildUpdateClientPayload};
5+
use crate::types::{HasChainTypes, HasIbcTypes, HasMessageTypes};
6+
7+
#[async_trait]
8+
pub trait CanBuildCreateClientMessage<Counterparty>: HasMessageTypes
9+
where
10+
Counterparty: HasChainTypes + CanBuildCreateClientPayload<Self>,
11+
{
12+
async fn build_create_client_message(
13+
&self,
14+
payload: Counterparty::CreateClientPayload,
15+
) -> Result<Self::Message>;
16+
}
17+
18+
#[async_trait]
19+
pub trait CanBuildUpdateClientMessage<Counterparty>:
20+
HasMessageTypes + HasIbcTypes<Counterparty>
21+
where
22+
Counterparty: HasChainTypes + CanBuildUpdateClientPayload<Self>,
23+
{
24+
async fn build_update_client_message(
25+
&self,
26+
client_id: &Self::ClientId,
27+
payload: Counterparty::UpdateClientPayload,
28+
) -> Result<Vec<Self::Message>>;
29+
}
30+
31+
#[async_trait]
32+
pub trait CanRegisterCounterparty<Counterparty>:
33+
HasMessageTypes + HasIbcTypes<Counterparty>
34+
where
35+
Counterparty: HasChainTypes + HasIbcTypes<Self>,
36+
{
37+
async fn build_register_counterparty_message(
38+
&self,
39+
client_id: &Self::ClientId,
40+
counterparty_client_id: &<Counterparty as HasIbcTypes<Self>>::ClientId,
41+
) -> Result<Self::Message>;
42+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use async_trait::async_trait;
2+
use mercury_core::error::Result;
3+
4+
use crate::types::HasMessageTypes;
5+
6+
#[async_trait]
7+
pub trait CanSendMessages: HasMessageTypes {
8+
async fn send_messages(
9+
&self,
10+
messages: Vec<Self::Message>,
11+
) -> Result<Vec<Self::MessageResponse>>;
12+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use async_trait::async_trait;
2+
use mercury_core::ThreadSafe;
3+
use mercury_core::error::Result;
4+
5+
use crate::types::{HasChainTypes, HasMessageTypes, HasPacketTypes};
6+
7+
#[async_trait]
8+
pub trait CanBuildReceivePacketMessage<Counterparty>:
9+
HasMessageTypes + HasPacketTypes<Counterparty>
10+
where
11+
Counterparty: HasChainTypes + HasPacketTypes<Self>,
12+
{
13+
type ReceivePacketPayload: ThreadSafe;
14+
async fn build_receive_packet_message(
15+
&self,
16+
packet: &<Counterparty as HasPacketTypes<Self>>::Packet,
17+
payload: Self::ReceivePacketPayload,
18+
) -> Result<Self::Message>;
19+
}
20+
21+
#[async_trait]
22+
pub trait CanBuildAckPacketMessage<Counterparty>:
23+
HasMessageTypes + HasPacketTypes<Counterparty>
24+
where
25+
Counterparty: HasChainTypes + HasPacketTypes<Self>,
26+
{
27+
type AckPacketPayload: ThreadSafe;
28+
async fn build_ack_packet_message(
29+
&self,
30+
packet: &Self::Packet,
31+
ack: &<Counterparty as HasPacketTypes<Self>>::Acknowledgement,
32+
payload: Self::AckPacketPayload,
33+
) -> Result<Self::Message>;
34+
}
35+
36+
#[async_trait]
37+
pub trait CanBuildTimeoutPacketMessage<Counterparty>:
38+
HasMessageTypes + HasPacketTypes<Counterparty>
39+
where
40+
Counterparty: HasChainTypes + HasPacketTypes<Self>,
41+
{
42+
type TimeoutPacketPayload: ThreadSafe;
43+
async fn build_timeout_packet_message(
44+
&self,
45+
packet: &Self::Packet,
46+
payload: Self::TimeoutPacketPayload,
47+
) -> Result<Self::Message>;
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use async_trait::async_trait;
2+
use mercury_core::error::Result;
3+
4+
use crate::types::{HasChainTypes, HasPacketTypes};
5+
6+
#[async_trait]
7+
pub trait CanQueryPacketCommitment<Counterparty: HasChainTypes + ?Sized>:
8+
HasPacketTypes<Counterparty>
9+
{
10+
async fn query_packet_commitment(
11+
&self,
12+
client_id: &Self::ClientId,
13+
sequence: u64,
14+
height: &Self::Height,
15+
) -> Result<(Option<Self::PacketCommitment>, Self::CommitmentProof)>;
16+
}
17+
18+
#[async_trait]
19+
pub trait CanQueryPacketReceipt<Counterparty: HasChainTypes + ?Sized>:
20+
HasPacketTypes<Counterparty>
21+
{
22+
async fn query_packet_receipt(
23+
&self,
24+
client_id: &Self::ClientId,
25+
sequence: u64,
26+
height: &Self::Height,
27+
) -> Result<(Option<Self::PacketReceipt>, Self::CommitmentProof)>;
28+
}
29+
30+
#[async_trait]
31+
pub trait CanQueryPacketAcknowledgement<Counterparty: HasChainTypes + ?Sized>:
32+
HasPacketTypes<Counterparty>
33+
{
34+
async fn query_packet_acknowledgement(
35+
&self,
36+
client_id: &Self::ClientId,
37+
sequence: u64,
38+
height: &Self::Height,
39+
) -> Result<(Option<Self::Acknowledgement>, Self::CommitmentProof)>;
40+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use async_trait::async_trait;
2+
use mercury_core::ThreadSafe;
3+
use mercury_core::error::Result;
4+
5+
use crate::types::{HasChainTypes, HasIbcTypes};
6+
7+
#[async_trait]
8+
pub trait CanBuildCreateClientPayload<Counterparty: HasChainTypes + ?Sized>: HasChainTypes {
9+
type CreateClientPayload: ThreadSafe;
10+
async fn build_create_client_payload(&self) -> Result<Self::CreateClientPayload>;
11+
}
12+
13+
#[async_trait]
14+
pub trait CanBuildUpdateClientPayload<Counterparty: HasChainTypes + ?Sized>:
15+
HasIbcTypes<Counterparty>
16+
{
17+
type UpdateClientPayload: ThreadSafe;
18+
async fn build_update_client_payload(
19+
&self,
20+
trusted_height: &Self::Height,
21+
target_height: &Self::Height,
22+
) -> Result<Self::UpdateClientPayload>;
23+
}

0 commit comments

Comments
 (0)