Skip to content

Commit

Permalink
feat(deps): switch from bee to iota-types (#813)
Browse files Browse the repository at this point in the history
* feat(deps): switch from `bee` to `iota-types`

* rename `bee::` alias to `iota::`

* Bump `packable` and `primitive-types`

* Fix CI

* Fix `cargo-sort`

* Fix `LICENSE`

* Remove macro for JSON responses

* Remove macros

* Consolodate enum responses

* fmt

Co-authored-by: Alex Coats <alexandcoats@gmail.com>
  • Loading branch information
grtlr and Alex Coats committed Oct 19, 2022
1 parent 770e8e1 commit 469dd4f
Show file tree
Hide file tree
Showing 58 changed files with 776 additions and 884 deletions.
227 changes: 49 additions & 178 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ humantime-serde = { version = "1.1", default-features = false }
mongodb = { version = "2.2", default-features = false, features = [ "tokio-runtime" ] }
pin-project = { version = "1.0", default-features = false }
prefix-hex = { version = "0.5.0", default-features = false, features = [ "primitive-types" ] }
primitive-types = { version = "0.11", default-features = false }
primitive-types = { version = "0.12", default-features = false }
serde = { version = "1.0", features = [ "derive" ], default-features = false }
serde_bytes = { version = "0.11", default-features = false }
serde_json = { version = "1.0", default-features = false, features = [ "std" ] }
Expand All @@ -57,7 +57,7 @@ ed25519-dalek = { version = "1.0", default-features = false, features = [ "u64_b
hex = { version = "0.4", default-features = false, optional = true }
hyper = { version = "0.14", default-features = false, features = [ "server", "tcp", "stream" ], optional = true }
lazy_static = { version = "1.4", default-features = false, optional = true }
packable = { version = "0.6", default-features = false, optional = true }
packable = { version = "0.7", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, features = [ "std" ], optional = true }
regex = { version = "1.5", default-features = false, features = [ "std" ], optional = true }
rust-argon2 = { version = "1.0.0", default-features = false, optional = true }
Expand All @@ -79,11 +79,10 @@ opentelemetry-jaeger = { version = "0.17", default-features = false, features =
tracing-opentelemetry = { version = "0.18", default-features = false, features = [ "tracing-log" ], optional = true }

# Stardust types
bee-api-types-stardust = { package = "bee-api-types", version = "1.0.1", default-features = false, features = [ "axum" ], optional = true }
bee-block-stardust = { package = "bee-block", version = "1.0.1", default-features = false, features = [ "dto", "inx", "rand", "std" ], optional = true }
iota-types = { git = "https://github.com/iotaledger/iota.rs", version = "1.0.0-rc", default-features = false, features = [ "dto", "std", "rand" ], optional = true }
iota-types = { git = "https://github.com/iotaledger/iota.rs", version = "1.0.0-rc", default-features = false, features = [ "api", "block", "std" ], optional = true }

[dev-dependencies]
iota-types = { git = "https://github.com/iotaledger/iota.rs", version = "1.0.0-rc", default-features = false, features = [ "api", "block", "std", "rand" ] }
rand = { version = "0.8", default-features = false, features = [ "std" ] }

[features]
Expand Down Expand Up @@ -122,11 +121,10 @@ opentelemetry = [
"dep:tracing-opentelemetry",
]
rand = [
"bee-block-stardust?/rand",
"iota-types?/rand",
]
stardust = [
"dep:bee-block-stardust",
"dep:bee-api-types-stardust",
"dep:iota-types",
]

[profile.production]
Expand Down
4 changes: 2 additions & 2 deletions src/bin/inx-chronicle/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tracing::error;
pub enum InternalApiError {
#[cfg(feature = "stardust")]
#[error(transparent)]
BeeStardust(#[from] bee_block_stardust::Error),
BeeStardust(#[from] iota_types::block::Error),
#[error(transparent)]
BsonDeserialize(#[from] mongodb::bson::de::Error),
#[error("corrupt state: {0}")]
Expand Down Expand Up @@ -112,7 +112,7 @@ pub enum ParseError {
BadPagingState,
#[cfg(feature = "stardust")]
#[error(transparent)]
BeeBlockStardust(#[from] bee_block_stardust::Error),
BeeBlockStardust(#[from] iota_types::block::Error),
#[error(transparent)]
Bool(#[from] ParseBoolError),
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/inx-chronicle/api/stardust/analytics/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use std::ops::Range;

use bee_api_types_stardust::responses::RentStructureResponse;
use chronicle::{db::collections::DistributionStat, types::tangle::MilestoneIndex};
use iota_types::api::response::RentStructureResponse;
use serde::{Deserialize, Serialize};

use crate::api::responses::impl_success_response;
Expand Down
4 changes: 2 additions & 2 deletions src/bin/inx-chronicle/api/stardust/analytics/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::str::FromStr;

use axum::{extract::Path, routing::get, Extension};
use bee_api_types_stardust::responses::RentStructureResponse;
use chronicle::{
db::{
collections::{BlockCollection, MilestoneCollection, OutputCollection, OutputKind, ProtocolUpdateCollection},
Expand All @@ -18,6 +17,7 @@ use chronicle::{
tangle::MilestoneIndex,
},
};
use iota_types::api::response::RentStructureResponse;

use super::{
extractors::{LedgerIndex, MilestoneRange, RichestAddressesQuery},
Expand Down Expand Up @@ -264,7 +264,7 @@ async fn richest_addresses_ledger_analytics(
.top
.into_iter()
.map(|stat| AddressStatDto {
address: bee_block_stardust::address::Address::from(stat.address).to_bech32(hrp.clone()),
address: iota_types::block::address::Address::from(stat.address).to_bech32(hrp.clone()),
balance: stat.balance,
})
.collect(),
Expand Down
29 changes: 21 additions & 8 deletions src/bin/inx-chronicle/api/stardust/core/responses.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use bee_api_types_stardust::responses::{ProtocolResponse, StatusResponse};
use iota_types::api::response as iota;
use serde::{Deserialize, Serialize};

use crate::api::responses::impl_success_response;
Expand All @@ -12,24 +12,37 @@ use crate::api::responses::impl_success_response;
pub struct InfoResponse {
pub name: String,
pub version: String,
pub status: StatusResponse,
pub protocol: ProtocolResponse,
pub status: iota::StatusResponse,
pub protocol: iota::ProtocolResponse,
}

impl_success_response!(InfoResponse);

/// A wrapper struct that allows us to implement [`IntoResponse`](axum::response::IntoResponse) for the foreign
/// responses from [`iota_types`](iota_types::api::response).
#[derive(Clone, Debug, Serialize, derive_more::From)]
pub struct IotaResponse<T: Serialize>(T);

impl<T: Serialize> axum::response::IntoResponse for IotaResponse<T> {
fn into_response(self) -> axum::response::Response {
axum::Json(self.0).into_response()
}
}

/// A wrapper struct that allows us to implement [`IntoResponse`](axum::response::IntoResponse) for the foreign
/// raw responses from [`iota_types`](iota_types::api::response).
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OutputResponse {
Json(Box<bee_api_types_stardust::responses::OutputResponse>),
pub enum IotaRawResponse<T: Serialize> {
Json(T),
Raw(Vec<u8>),
}

impl axum::response::IntoResponse for OutputResponse {
impl<T: Serialize> axum::response::IntoResponse for IotaRawResponse<T> {
fn into_response(self) -> axum::response::Response {
match self {
OutputResponse::Json(res) => axum::Json(res).into_response(),
OutputResponse::Raw(bytes) => bytes.into_response(),
Self::Json(res) => axum::Json(res).into_response(),
Self::Raw(bytes) => bytes.into_response(),
}
}
}
Loading

0 comments on commit 469dd4f

Please sign in to comment.