Skip to content

Commit

Permalink
chore: remove BSON extension traits (#164)
Browse files Browse the repository at this point in the history
Remove bson extension traits
  • Loading branch information
Alexandcoats committed May 18, 2022
1 parent 7ca01fb commit 5d691b3
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 305 deletions.
4 changes: 1 addition & 3 deletions bin/inx-chronicle/src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::str::ParseBoolError;

use axum::{extract::rejection::QueryRejection, response::IntoResponse};
use chronicle::{db::bson::DocError, types::ledger::UnexpectedLedgerInclusionState};
use chronicle::types::ledger::UnexpectedLedgerInclusionState;
use hyper::{header::InvalidHeaderValue, StatusCode};
use mongodb::bson::document::ValueAccessError;
use serde::Serialize;
Expand All @@ -16,8 +16,6 @@ pub enum InternalApiError {
#[error(transparent)]
BsonDeserialize(#[from] mongodb::bson::de::Error),
#[error(transparent)]
Doc(#[from] DocError),
#[error(transparent)]
Config(#[from] ConfigError),
#[error(transparent)]
Hyper(#[from] hyper::Error),
Expand Down
8 changes: 4 additions & 4 deletions bin/inx-chronicle/src/api/stardust/analytics/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use axum::{routing::get, Extension, Router};
use chronicle::db::{bson::DocExt, MongoDb};
use chronicle::db::MongoDb;

use super::responses::AddressAnalyticsResponse;
use crate::api::{extractors::TimeRange, ApiError, ApiResult};
Expand Down Expand Up @@ -33,8 +33,8 @@ async fn address_analytics(
.ok_or(ApiError::NoResults)?;

Ok(AddressAnalyticsResponse {
total_addresses: res.get_as_u64("total_addresses")?,
recv_addresses: res.get_as_u64("recv_addresses")?,
send_addresses: res.get_as_u64("send_addresses")?,
total_addresses: res.total_addresses,
recv_addresses: res.recv_addresses,
send_addresses: res.send_addresses,
})
}
20 changes: 19 additions & 1 deletion bin/inx-chronicle/src/api/stardust/explorer/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

use axum::response::IntoResponse;
use chronicle::types::ledger::LedgerInclusionState;
use serde::{Deserialize, Serialize};

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

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransactionHistoryResponse {
Expand All @@ -13,3 +14,20 @@ pub struct TransactionHistoryResponse {
}

impl_success_response!(TransactionHistoryResponse);

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Transfer {
#[serde(rename = "transactionId")]
pub transaction_id: String,
#[serde(rename = "outputIndex")]
pub output_index: u16,
#[serde(rename = "isSpent")]
pub is_spent: bool,
#[serde(rename = "inclusionState")]
pub inclusion_state: Option<LedgerInclusionState>,
#[serde(rename = "messageId")]
pub message_id: String,
#[serde(rename = "milestoneIndex")]
pub milestone_index: Option<u32>,
pub amount: u64,
}
30 changes: 10 additions & 20 deletions bin/inx-chronicle/src/api/stardust/explorer/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@

use axum::{extract::Path, routing::get, Extension, Router};
use bee_message_stardust::address as bee;
use chronicle::{
db::{bson::DocExt, MongoDb},
types::{ledger::LedgerInclusionState, stardust::message::Address},
};
use chronicle::{db::MongoDb, types::stardust::message::Address};
use futures::TryStreamExt;

use super::responses::TransactionHistoryResponse;
use super::responses::{TransactionHistoryResponse, Transfer};
use crate::api::{
extractors::{Pagination, TimeRange},
responses::Transfer,
ApiError, ApiResult,
};

Expand Down Expand Up @@ -50,21 +46,15 @@ async fn transaction_history(

let transactions = records
.into_iter()
.map(|mut rec| {
let mut payload = rec.take_document("message.payload")?;
let spending_transaction = rec.take_document("spending_transaction").ok();
let output = payload.take_document("essence.outputs")?;
.map(|rec| {
Ok(Transfer {
transaction_id: payload.get_as_string("transaction_id")?,
output_index: output.get_as_u16("idx")?,
is_spending: spending_transaction.is_some(),
inclusion_state: rec
.get_as_u8("inclusion_state")
.ok()
.map(LedgerInclusionState::try_from)
.transpose()?,
message_id: rec.get_as_string("message_id")?,
amount: output.get_as_u64("amount")?,
transaction_id: rec.transaction_id.to_hex(),
output_index: rec.output_index,
is_spent: rec.is_spent,
inclusion_state: rec.inclusion_state,
message_id: rec.message_id.to_hex(),
amount: rec.amount,
milestone_index: rec.milestone_index,
})
})
.collect::<Result<_, ApiError>>()?;
Expand Down
4 changes: 1 addition & 3 deletions bin/inx-chronicle/src/collector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) mod stardust_inx;

use async_trait::async_trait;
use chronicle::{
db::{bson::DocError, MongoDb},
db::MongoDb,
runtime::{Actor, ActorContext, ActorError, Addr, ConfigureActor, HandleEvent, Report, RuntimeError},
};
use mongodb::bson::document::ValueAccessError;
Expand All @@ -19,8 +19,6 @@ use self::solidifier::Solidifier;

#[derive(Debug, Error)]
pub enum CollectorError {
#[error(transparent)]
Doc(#[from] DocError),
#[error(transparent)]
MongoDb(#[from] mongodb::error::Error),
#[error(transparent)]
Expand Down
257 changes: 0 additions & 257 deletions src/db/bson/mod.rs

This file was deleted.

Loading

0 comments on commit 5d691b3

Please sign in to comment.