Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LC in browser #714

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy
- run: cargo clippy --workspace -- -D warnings
# TODO: Enable avail-light-web once issue with rocksdb feature being applied
# accross the workspace is resolved
- run: cargo clippy --workspace --exclude avail-light-web -- -D warnings

test:
name: cargo test
Expand All @@ -42,7 +44,9 @@ jobs:
- uses: actions/checkout@v4
- uses: arduino/setup-protoc@v2
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo test --workspace --benches --tests
# TODO: Enable avail-light-web once issue with rocksdb feature being applied
# accross the workspace is resolved
- run: cargo test --workspace --benches --tests --exclude avail-light-web
env:
RUSTFLAGS: "-C instrument-coverage"
LLVM_PROFILE_FILE: "profile-%p-%m.profraw"
Expand Down
44 changes: 43 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"fat",
"monitor-client",
"relay",
"web",
]
default-members = ["client"]
resolver = "2"
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ color-eyre = { workspace = true }
ed25519-compact = "2.1.1"
# NOTE: This is used due bug explained at: https://github.com/tomaka/wasm-timer/pull/13
fluvio-wasm-timer = "0.2.5"
hyper = { version = "0.14.23", features = ["http1"] }
libp2p = { workspace = true, features = ["wasm-bindgen"] }
libp2p-webrtc-websys = { workspace = true }
rand = { workspace = true, features = ["std_rng"] }
thiserror-no-std = "2.0.2"
tokio_with_wasm = { version = "0.7.1", default-features = false, features = ["sync", "macros", "rt", "time"] }
wasm-bindgen = "0.2.90"
web-time = "1.1.0"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions core/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub mod configuration;
#[cfg(not(target_arch = "wasm32"))]
pub mod diagnostics;
#[cfg(not(target_arch = "wasm32"))]
pub mod server;
pub mod types;
#[cfg(not(target_arch = "wasm32"))]
mod v1;
pub mod v2;
38 changes: 29 additions & 9 deletions core/src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
AvailHeader, H256,
};
use codec::Encode;
use color_eyre::{
eyre::{eyre, WrapErr},
Report, Result,
};
#[cfg(not(target_arch = "wasm32"))]
use color_eyre::eyre::eyre;
use color_eyre::{eyre::WrapErr, Report, Result};
use derive_more::From;
use hyper::{http, StatusCode};
#[cfg(not(target_arch = "wasm32"))]
use hyper::http;
use hyper::StatusCode;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::collections::HashSet;
#[cfg(not(target_arch = "wasm32"))]
use std::{collections::HashMap, sync::Arc};
#[cfg(not(target_arch = "wasm32"))]
use tokio::sync::{mpsc::UnboundedSender, RwLock};
use uuid::Uuid;
#[cfg(not(target_arch = "wasm32"))]
use warp::{
ws::{self, Message},
Reply,
Expand All @@ -41,6 +43,7 @@
#[derive(Debug)]
pub struct InternalServerError {}

#[cfg(not(target_arch = "wasm32"))]
impl warp::reject::Reject for InternalServerError {}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand All @@ -49,6 +52,7 @@
pub network_version: String,
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for Version {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -124,6 +128,7 @@
pub index: u32,
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for SubmitResponse {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -174,6 +179,7 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for Status {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -318,6 +324,7 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for Block {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -347,6 +354,7 @@
digest: Digest,
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for Header {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -541,6 +549,7 @@
pub data_transactions: Vec<DataTransaction>,
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for DataResponse {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -612,6 +621,7 @@
DataVerified(DataMessage),
}

#[cfg(not(target_arch = "wasm32"))]
impl PublishMessage {
fn apply_filter(&mut self, fields: &HashSet<DataField>) {
match self {
Expand All @@ -624,6 +634,7 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
impl TryFrom<PublishMessage> for Message {
type Error = Report;
fn try_from(value: PublishMessage) -> Result<Self, Self::Error> {
Expand All @@ -633,13 +644,16 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
pub type Sender = UnboundedSender<Result<ws::Message, warp::Error>>;

#[cfg(not(target_arch = "wasm32"))]
pub struct WsClient {
pub subscription: Subscription,
pub sender: Option<Sender>,
}

#[cfg(not(target_arch = "wasm32"))]
impl WsClient {
pub fn new(subscription: Subscription) -> Self {
WsClient {
Expand All @@ -659,9 +673,11 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
#[derive(Clone)]
pub struct WsClients(pub Arc<RwLock<HashMap<String, WsClient>>>);

#[cfg(not(target_arch = "wasm32"))]
impl WsClients {
pub async fn set_sender(&self, subscription_id: &str, sender: Sender) -> Result<()> {
let mut clients = self.0.write().await;
Expand Down Expand Up @@ -701,6 +717,7 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
impl Default for WsClients {
fn default() -> Self {
Self(Arc::new(RwLock::new(HashMap::new())))
Expand All @@ -712,6 +729,7 @@
pub subscription_id: String,
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for SubscriptionId {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
Expand Down Expand Up @@ -748,6 +766,7 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
impl TryFrom<ws::Message> for Request {
type Error = Report;

Expand Down Expand Up @@ -810,7 +829,7 @@
Self::new(Some(request_id), None, ErrorCode::BadRequest, message)
}

fn status(&self) -> StatusCode {

Check failure on line 832 in core/src/api/types.rs

View workflow job for this annotation

GitHub Actions / wasm

method `status` is never used
match self.error_code {
ErrorCode::NotFound => StatusCode::NOT_FOUND,
ErrorCode::BadRequest => StatusCode::BAD_REQUEST,
Expand All @@ -819,6 +838,7 @@
}
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for Error {
fn into_response(self) -> warp::reply::Response {
http::Response::builder()
Expand Down
46 changes: 46 additions & 0 deletions core/src/api/v2/messages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use super::transactions;
use crate::{
api::{
configuration::SharedConfig,
types::{Error, Payload, Request, Response, Status, Version, WsResponse},
},
data::{Database, RpcNodeKey},
};
use std::sync::Arc;

pub async fn handle_request(

Check failure on line 11 in core/src/api/v2/messages.rs

View workflow job for this annotation

GitHub Actions / wasm

function `handle_request` is never used
request: Request,
version: &str,
config: &SharedConfig,
submitter: Option<Arc<impl transactions::Submit>>,
db: impl Database,
) -> Result<WsResponse, Error> {
let request_id = request.request_id;
match request.payload {
Payload::Version => {
let version = Version {
version: version.to_string(),
network_version: db.get(RpcNodeKey).unwrap_or_default().system_version,
};
Ok(Response::new(request_id, version).into())
},
Payload::Status => {
let status = Status::new(config, db);
Ok(Response::new(request_id, status).into())
},
Payload::Submit(transaction) => {
let Some(submitter) = submitter else {
return Err(Error::bad_request(request_id, "Submit is not configured."));
};
if transaction.is_empty() {
return Err(Error::bad_request(request_id, "Transaction is empty."));
}

submitter
.submit(transaction)
.await
.map(|response| Response::new(request_id, response).into())
.map_err(Error::internal_server_error)
},
}
}
Loading
Loading