Skip to content

Commit

Permalink
fix!: rename Block and update inx (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
grtlr committed May 20, 2022
1 parent daf1010 commit e12a925
Show file tree
Hide file tree
Showing 47 changed files with 876 additions and 865 deletions.
65 changes: 33 additions & 32 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ tower = { version = "0.4", default-features = false, optional = true }
tower-http = { version = "0.3", default-features = false, features = ["cors", "catch-panic", "trace"], optional = true }

# INX
inx = { git = "https://github.com/iotaledger/inx", version = "0.3", default-features = false, features = ["types"], optional = true }
inx = { git = "https://github.com/iotaledger/inx", version = "0.4", default-features = false, features = ["types"], optional = true }

# Metrics
bee-metrics = { git = "https://github.com/iotaledger/bee", branch = "mainnet-develop-0.4", default-features = false, optional = true }

# Stardust types
bee-message-stardust = { package = "bee-message", git = "https://github.com/iotaledger/bee.git", branch = "shimmer-develop", default-features = false, features = ["std", "serde", "dto"], optional = true }
bee-block-stardust = { package = "bee-block", git = "https://github.com/iotaledger/bee.git", branch = "shimmer-develop", default-features = false, features = ["std", "serde", "dto"], optional = true }
bee-rest-api-stardust = { package = "bee-rest-api", git = "https://github.com/iotaledger/bee.git", branch = "shimmer-develop", default-features = false, optional = true }

# Tokio Console
Expand Down Expand Up @@ -105,7 +105,7 @@ metrics = [
"dep:bee-metrics",
]
stardust = [
"dep:bee-message-stardust",
"dep:bee-block-stardust",
"dep:bee-rest-api-stardust",
]

Expand Down
8 changes: 5 additions & 3 deletions bin/inx-chronicle/src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum InternalApiError {
MongoDb(#[from] mongodb::error::Error),
#[cfg(feature = "stardust")]
#[error(transparent)]
BeeMessageStardust(#[from] bee_message_stardust::Error),
BeeStardust(#[from] bee_block_stardust::Error),
#[error(transparent)]
UnexpectedLedgerInclusionState(#[from] UnexpectedLedgerInclusionState),
#[error(transparent)]
Expand Down Expand Up @@ -99,6 +99,8 @@ pub enum ParseError {
Bool(#[from] ParseBoolError),
#[cfg(feature = "stardust")]
#[error(transparent)]
BeeBlockStardust(#[from] bee_block_stardust::Error),
#[error(transparent)]
StorageType(#[from] chronicle::types::error::ParseError),
#[error(transparent)]
TimeRange(#[from] time::error::ComponentRange),
Expand All @@ -114,7 +116,7 @@ pub struct ErrorBody {
#[serde(skip_serializing)]
status: StatusCode,
code: u16,
message: String,
block: String,
}

impl IntoResponse for ErrorBody {
Expand All @@ -139,7 +141,7 @@ impl From<ApiError> for ErrorBody {
Self {
status: err.status(),
code: err.code(),
message: err.to_string(),
block: err.to_string(),
}
}
}
12 changes: 6 additions & 6 deletions bin/inx-chronicle/src/api/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ pub struct Transfer {
pub is_spending: bool,
#[serde(rename = "inclusionState")]
pub inclusion_state: Option<LedgerInclusionState>,
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "blockId")]
pub block_id: String,
pub amount: u64,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MaybeSpentOutput {
pub output: Value,
#[serde(rename = "spendingMessageId")]
pub spending_message_id: Option<String>,
#[serde(rename = "spendingBlockId")]
pub spending_block_id: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Unlock {
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "blockId")]
pub block_id: String,
pub block: Value,
}

Expand Down
4 changes: 2 additions & 2 deletions bin/inx-chronicle/src/api/stardust/explorer/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct Transfer {
pub is_spent: bool,
#[serde(rename = "inclusionState")]
pub inclusion_state: Option<LedgerInclusionState>,
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "blockId")]
pub block_id: String,
#[serde(rename = "milestoneIndex")]
pub milestone_index: Option<u32>,
pub amount: u64,
Expand Down
4 changes: 2 additions & 2 deletions bin/inx-chronicle/src/api/stardust/explorer/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::str::FromStr;

use axum::{extract::Path, routing::get, Extension, Router};
use chronicle::{db::MongoDb, types::stardust::message::Address};
use chronicle::{db::MongoDb, types::stardust::block::Address};
use futures::TryStreamExt;

use super::responses::{TransactionHistoryResponse, Transfer};
Expand Down Expand Up @@ -54,7 +54,7 @@ async fn transaction_history(
output_index: rec.output_index,
is_spent: rec.is_spent,
inclusion_state: rec.inclusion_state,
message_id: rec.message_id.to_hex(),
block_id: rec.block_id.to_hex(),
amount: rec.amount,
milestone_index: rec.milestone_index,
})
Expand Down
54 changes: 26 additions & 28 deletions bin/inx-chronicle/src/api/stardust/v2/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@
use axum::response::IntoResponse;
use chronicle::types::{
ledger::LedgerInclusionState,
stardust::message::{Input, Output, Payload},
stardust::block::{Input, Output, Payload},
};
use serde::{Deserialize, Serialize};

use crate::api::{impl_success_response, responses::Expansion};

/// Response of `GET /api/v2/messages/<message_id>`
/// and `GET /api/v2/transactions/<transaction_id>/included-message`.
/// Response of `GET /api/v2/blocks/<block_id>`
/// and `GET /api/v2/transactions/<transaction_id>/included-block`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MessageResponse {
pub struct BlockResponse {
#[serde(rename = "protocolVersion")]
pub protocol_version: u8,
#[serde(rename = "parentMessageIds")]
pub parents: Vec<String>,
pub payload: Option<Payload>,
pub nonce: u64,
}

impl_success_response!(MessageResponse);
impl_success_response!(BlockResponse);

/// Response of `GET /api/v2/messages/<message_id>/metadata`.
/// Response of `GET /api/v2/blocks/<block_id>/metadata`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MessageMetadataResponse {
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "parentMessageIds")]
pub parent_message_ids: Vec<String>,
pub struct BlockMetadataResponse {
#[serde(rename = "blockId")]
pub block_id: String,
#[serde(rename = "parentBlockIds")]
pub parents: Vec<String>,
#[serde(rename = "isSolid")]
pub is_solid: Option<bool>,
#[serde(rename = "referencedByMilestoneIndex", skip_serializing_if = "Option::is_none")]
Expand All @@ -47,27 +46,26 @@ pub struct MessageMetadataResponse {
pub should_reattach: Option<bool>,
}

impl_success_response!(MessageMetadataResponse);
impl_success_response!(BlockMetadataResponse);

/// Response of `GET /api/v2/messages/<message_id>/children`.
/// Response of `GET /api/v2/blocks/<block_id>/children`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MessageChildrenResponse {
#[serde(rename = "messageId")]
pub message_id: String,
pub struct BlockChildrenResponse {
#[serde(rename = "blockId")]
pub block_id: String,
#[serde(rename = "maxResults")]
pub max_results: usize,
pub count: usize,
#[serde(rename = "childrenMessageIds")]
pub children_message_ids: Vec<Expansion>,
pub children: Vec<Expansion>,
}

impl_success_response!(MessageChildrenResponse);
impl_success_response!(BlockChildrenResponse);

/// Response of `GET /api/v2/outputs/<output_id>`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OutputResponse {
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "blockId")]
pub block_id: String,
#[serde(rename = "transactionId")]
pub transaction_id: String,
#[serde(rename = "outputIndex")]
Expand All @@ -90,8 +88,8 @@ impl_success_response!(OutputResponse);
/// Response of `GET /api/v2/outputs/<output_id>/metadata`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OutputMetadataResponse {
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "blockId")]
pub block_id: String,
#[serde(rename = "transactionId")]
pub transaction_id: String,
#[serde(rename = "outputIndex")]
Expand All @@ -112,12 +110,12 @@ pub struct OutputMetadataResponse {

impl_success_response!(OutputMetadataResponse);

/// Response of `GET /api/v2/transactions/<message_id>`.
/// Response of `GET /api/v2/transactions/<block_id>`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransactionResponse {
/// The created output's message id
#[serde(rename = "messageId")]
pub message_id: String,
/// The created output's block id
#[serde(rename = "blockId")]
pub block_id: String,
/// The confirmation timestamp
#[serde(rename = "milestoneIndex")]
pub milestone_index: Option<u32>,
Expand Down
Loading

0 comments on commit e12a925

Please sign in to comment.