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

refactor: FM-321 move orb relay client #340

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
74 changes: 71 additions & 3 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"mcu-interface",
"mcu-util",
"qr-link",
"relay-client",
"security-utils",
"seek-camera/sys",
"seek-camera/wrapper",
Expand Down Expand Up @@ -95,6 +96,7 @@ orb-build-info.path = "build-info"
orb-const-concat.path = "const-concat"
orb-header-parsing.path = "header-parsing"
orb-mcu-interface.path = "mcu-interface"
orb-relay-client.path = "relay-client"
orb-security-utils.path = "security-utils"
orb-slot-ctrl.path = "slot-ctrl"
orb-telemetry.path = "telemetry"
Expand All @@ -106,6 +108,11 @@ seek-camera.path = "seek-camera/wrapper"
git = "https://github.com/worldcoin/orb-messages"
rev = "787ab78581b705af0946bcfe3a0453b64af2193f"

[workspace.dependencies.orb-relay-messages]
git = "https://github.com/worldcoin/orb-relay-messages.git"
rev = "f1c73751200ea9df7f1712ec203c7882f30f60f4"
features = ["client"]

[workspace.dependencies.nusb]
git = "https://github.com/kevinmehall/nusb"
rev = "3ec3508324cdd01ca288b91ddcb2f92fd6a6f813"
Expand Down
20 changes: 20 additions & 0 deletions relay-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "orb-relay-client"
version = "0.1.0"
edition.workspace = true
publish = false

[dependencies]
clap = { version = "4", features = ["derive"] }
eyre.workspace = true
json5 = "0.4"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unless we actually need json5, it might be better to stick with json. Will keep our dependency tree smaller and will be more familiar.

orb-relay-messages.workspace = true
orb-security-utils = { workspace = true, features = ["reqwest"] }
rand = "0.8"
serde_json.workspace = true
sha2 = "0.10"
tokio-stream.workspace = true
tokio-util.workspace = true
tokio.workspace = true
tracing-subscriber = "0.3"
tracing.workspace = true
39 changes: 39 additions & 0 deletions relay-client/src/bin/decode-msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use clap::Parser;
use eyre::{eyre, Result};
use orb_relay_client::debug_any;
use orb_relay_messages::prost_types::Any;
use serde_json::Value;

#[derive(Parser, Debug)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be good to add a doc comment here or at the module level explaining what this binary is for

struct Args {
#[arg()]
json: String,
}

fn main() -> Result<()> {
let args = Args::parse();
println!("{}", decode_payload(&args.json)?);
Ok(())
}

fn decode_payload(json: &str) -> Result<String> {
println!("json: {}", json);
let v: Value = json5::from_str(json)?;
let any = Any {
type_url: v["type_url"]
.as_str()
.ok_or_else(|| eyre!("Invalid type_url"))?
.to_string(),
value: v["value"]
.as_array()
.ok_or_else(|| eyre!("Invalid value"))?
.iter()
.map(|n| {
n.as_u64()
.ok_or_else(|| eyre!("Invalid number"))
.map(|n| n as u8)
})
.collect::<Result<_>>()?,
};
Ok(debug_any(&Some(any)))
}
Loading
Loading