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

RPPL-2514 Handling response.success in thunder response #621

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
38 changes: 35 additions & 3 deletions core/main/src/broker/thunder_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
tokio::{self, sync::mpsc},
utils::error::RippleError,
};
use serde_json::json;
use serde_json::{json, Value};
use std::{
sync::{Arc, RwLock},
vec,
Expand Down Expand Up @@ -161,12 +161,44 @@
}

fn update_response(response: &JsonRpcApiResponse) -> JsonRpcApiResponse {
let mut new_response = response.clone();
let mut new_response = JsonRpcApiResponse::default();
new_response.id = response.id;

Check failure on line 165 in core/main/src/broker/thunder_broker.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

field assignment outside of initializer for an instance created with Default::default()
new_response.jsonrpc = response.jsonrpc.clone();

println!("=====> update_response: {:?}", response);
if response.params.is_some() {
new_response = response.clone();
new_response.result = response.params.clone();
} else if response.error.is_some() {
new_response.result = response.error.clone();
new_response.error = response.error.clone();
} else {

Check failure on line 174 in core/main/src/broker/thunder_broker.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

this `else { if .. }` block can be collapsed
if let Some(result) = response.result.clone() {
if result.is_object() {
let mut new_result = result.as_object().unwrap().clone();
for (key, value) in result.as_object().unwrap() {
if key.eq("success") {
if let Some(succes) = value.as_bool() {
if succes == false {

Check failure on line 181 in core/main/src/broker/thunder_broker.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

equality checks against false can be replaced by a negation
let error: Value =
r#"{ "code": 1, "message": "ERROR_GENERAL"}"#.into();
new_response.error = Some(error);
new_response.result = None;
} else {
let _ = new_result.remove(key);
}
}
break;
}
}
if !new_result.is_empty() {
new_response.result = Some(Value::Object(new_result));
}
} else {
new_response.result = response.result.clone();
}
}
}
println!("<===== update_response: {:?}", new_response);
new_response
}

Expand Down
Loading