Skip to content

Commit

Permalink
chore: update crates structure for api/uci and core (#436)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <simon.paitrault@gmail.com>
  • Loading branch information
Freyskeyd authored Jan 23, 2024
1 parent 4aa6a9e commit 355b08a
Show file tree
Hide file tree
Showing 71 changed files with 148 additions and 210 deletions.
63 changes: 19 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 0 additions & 50 deletions crates/topos-api/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions crates/topos-api/src/lib.rs

This file was deleted.

File renamed without changes.
39 changes: 34 additions & 5 deletions crates/topos-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,48 @@ edition = "2021"
workspace = true

[dependencies]
topos-uci = { path = "../topos-uci", optional = true }
topos-api = { path = "../topos-api", optional = true }
topos-crypto = { path = "../topos-crypto" }
serde.workspace = true
bincode.workspace = true
thiserror.workspace = true
hex.workspace = true
ethereum-types.workspace = true

tonic = { workspace = true, default-features = false, features = [
"prost",
"codegen",
"transport",
] }

async-graphql.workspace = true
async-trait.workspace = true
base64ct.workspace = true
prost.workspace = true
serde = { workspace = true, features = ["derive"] }
tracing.workspace = true
uuid.workspace = true

[build-dependencies]
tonic-build = { version = "0.10", default-features = false, features = [
"prost", "transport"
] }

[dev-dependencies]
async-stream.workspace = true
env_logger.workspace = true
futures.workspace = true
rstest.workspace = true
test-log.workspace = true
tokio-stream.workspace = true
tokio.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }
tracing.workspace = true

topos-test-sdk = { path = "../topos-test-sdk/" }
[features]
default = []

uci = ["topos-uci"]
api = ["topos-api"]
uci = []
api = []

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 2 additions & 2 deletions crates/topos-api/build.rs → crates/topos-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let descriptor_path = PathBuf::from("src/grpc/generated").join("topos.bin");
let descriptor_path = PathBuf::from("src/api/grpc/generated").join("topos.bin");

tonic_build::configure()
.file_descriptor_set_path(descriptor_path)
Expand Down Expand Up @@ -81,7 +81,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
".topos.uci.v1.Certificate",
"#[derive(Eq, Hash, serde::Deserialize, serde::Serialize)]",
)
.out_dir("src/grpc/generated")
.out_dir("src/api/grpc/generated")
.compile(
&[
"proto/topos/shared/v1/uuid.proto",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct Certificate {
pub verifier: u32,
}

impl From<&topos_uci::Certificate> for Certificate {
fn from(uci_cert: &topos_uci::Certificate) -> Self {
impl From<&crate::uci::Certificate> for Certificate {
fn from(uci_cert: &crate::uci::Certificate) -> Self {
Self {
id: uci_cert.id.to_string(),
prev_id: uci_cert.prev_id.to_string(),
Expand All @@ -40,8 +40,8 @@ impl From<&topos_uci::Certificate> for Certificate {
}
}

impl From<&topos_uci::SubnetId> for SubnetId {
fn from(uci_id: &topos_uci::SubnetId) -> Self {
impl From<&crate::uci::SubnetId> for SubnetId {
fn from(uci_id: &crate::uci::SubnetId) -> Self {
Self {
value: uci_id.to_string(),
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::graphql::subnet::SubnetId;
use crate::api::graphql::subnet::SubnetId;

#[derive(Debug, serde::Serialize, serde::Deserialize, async_graphql::OneofObject)]
pub enum SubnetFilter {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::graphql::certificate::{Certificate, CertificateId};
use crate::graphql::checkpoint::SourceCheckpoint;
use crate::graphql::errors::GraphQLServerError;
use crate::api::graphql::certificate::{Certificate, CertificateId};
use crate::api::graphql::checkpoint::SourceCheckpoint;
use crate::api::graphql::errors::GraphQLServerError;

use async_graphql::Context;
use async_trait::async_trait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SubnetId {
pub value: String,
}

impl TryFrom<&SubnetId> for topos_uci::SubnetId {
impl TryFrom<&SubnetId> for crate::uci::SubnetId {
type Error = GraphQLServerError;

fn try_from(value: &SubnetId) -> Result<Self, Self::Error> {
Expand All @@ -24,9 +24,9 @@ impl TryFrom<&SubnetId> for topos_uci::SubnetId {
}
}

impl PartialEq<topos_uci::SubnetId> for SubnetId {
fn eq(&self, other: &topos_uci::SubnetId) -> bool {
if let Ok(current) = topos_uci::SubnetId::from_str(&self.value) {
impl PartialEq<crate::uci::SubnetId> for SubnetId {
fn eq(&self, other: &crate::uci::SubnetId) -> bool {
if let Ok(current) = crate::uci::SubnetId::from_str(&self.value) {
other.as_array().eq(current.as_array())
} else {
warn!("Unexpected parsing error for subnet id during comparaison");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::grpc::shared::v1_conversions_subnet::Error;
use crate::api::grpc::shared::v1_conversions_subnet::Error;

#[derive(Debug, thiserror::Error)]
pub enum TargetCheckpointError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::grpc::shared::v1 as shared_v1;
use topos_uci::SubnetId;
use crate::api::grpc::shared::v1 as shared_v1;
use crate::uci::SubnetId;

mod errors;
mod positions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::grpc::checkpoints::StreamPositionError;
use crate::grpc::shared::v1 as shared_v1;
use topos_uci::{CertificateId, SubnetId};
use crate::api::grpc::checkpoints::StreamPositionError;
use crate::api::grpc::shared::v1 as shared_v1;
use crate::uci::{CertificateId, SubnetId};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TargetStreamPosition {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use topos_uci::CERTIFICATE_ID_LENGTH;
use crate::uci::CERTIFICATE_ID_LENGTH;

use super::v1::CertificateId;

Expand All @@ -22,15 +22,15 @@ impl From<[u8; CERTIFICATE_ID_LENGTH]> for CertificateId {
}
}

impl From<topos_uci::CertificateId> for CertificateId {
fn from(value: topos_uci::CertificateId) -> Self {
impl From<crate::uci::CertificateId> for CertificateId {
fn from(value: crate::uci::CertificateId) -> Self {
CertificateId {
value: value.as_array().to_vec(),
}
}
}

impl TryFrom<CertificateId> for topos_uci::CertificateId {
impl TryFrom<CertificateId> for crate::uci::CertificateId {
type Error = Error;

fn try_from(value: CertificateId) -> Result<Self, Self::Error> {
Expand All @@ -45,7 +45,7 @@ impl TryFrom<CertificateId> for topos_uci::CertificateId {
}
}

impl PartialEq<CertificateId> for topos_uci::CertificateId {
impl PartialEq<CertificateId> for crate::uci::CertificateId {
fn eq(&self, other: &CertificateId) -> bool {
if other.value.len() != CERTIFICATE_ID_LENGTH {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use topos_uci::SUBNET_ID_LENGTH;
use crate::uci::SUBNET_ID_LENGTH;

use super::v1::SubnetId;
use base64ct::{Base64, Encoding};
Expand All @@ -15,7 +15,7 @@ pub enum Error {
ValidationError(SubnetId),

#[error("Unable to parse UCI field ({0}))")]
UCI(#[from] topos_uci::Error),
UCI(#[from] crate::uci::Error),

#[error("Missing mandatory field: {0}")]
MissingField(&'static str),
Expand Down Expand Up @@ -53,15 +53,15 @@ impl TryFrom<SubnetId> for [u8; SUBNET_ID_LENGTH] {
}
}

impl From<topos_uci::SubnetId> for SubnetId {
fn from(value: topos_uci::SubnetId) -> Self {
impl From<crate::uci::SubnetId> for SubnetId {
fn from(value: crate::uci::SubnetId) -> Self {
SubnetId {
value: value.as_array().to_vec(),
}
}
}

impl TryFrom<SubnetId> for topos_uci::SubnetId {
impl TryFrom<SubnetId> for crate::uci::SubnetId {
type Error = Error;

fn try_from(value: SubnetId) -> Result<Self, Self::Error> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::grpc::tce::v1::{
use crate::api::grpc::tce::v1::{
watch_certificates_request::{Command, OpenStream},
watch_certificates_response::{CertificatePushed, Event, StreamOpened},
WatchCertificatesRequest, WatchCertificatesResponse,
Expand Down
Loading

0 comments on commit 355b08a

Please sign in to comment.