Skip to content

Commit

Permalink
feat: implement grpc_gateway api client (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccartney authored Sep 29, 2023
1 parent 246209f commit 1b05872
Show file tree
Hide file tree
Showing 34 changed files with 4,596 additions and 189 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bindings_wasm_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: dev/up
- uses: nanasess/setup-chromedriver@master
- run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run: wasm-pack test --headless --chrome
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/xmtp_api_grpc_gateway_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
push:
branches:
- main
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: dev/up
- uses: nanasess/setup-chromedriver@master
- run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run: wasm-pack test --headless --chrome
working-directory: xmtp_api_grpc_gateway
87 changes: 53 additions & 34 deletions Cargo.lock

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

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ members = [
"examples/cli",
"xmtp",
"xmtp_cryptography",
"xmtp_networking",
# TODO: replace ^ with:
# "xmtp_api_grpc",
# "xmtp_api_grpc_gateway",
"xmtp_api_grpc",
"xmtp_proto",
"xmtp_v2",
]

# Exclude since
# 1) no reason to share profile with other core crates
# 2) moreover, bindings_swift and xmtp_dh need their own size-optimized profile
exclude = ["bindings_ffi", "bindings_js", "bindings_wasm"]
exclude = [
"bindings_ffi",
"bindings_js",
"bindings_wasm",
"xmtp_api_grpc_gateway",
]

# Make the feature resolver explicit.
# See https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html#details
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Start Docker Desktop.

- [`xmtp`](https://github.com/xmtp/libxmtp/tree/main/xmtp): Pure Rust implementation of XMTP APIs, agnostic to any per-language or per-platform binding
- [`xmtp_cryptography`](https://github.com/xmtp/libxmtp/tree/main/xmtp_cryptography): Cryptographic operations
- [`xmtp_networking`](https://github.com/xmtp/libxmtp/tree/main/xmtp_networking): API client for XMTP's gRPC API, using code from `xmtp_proto`
- [`xmtp_api_grpc`](https://github.com/xmtp/libxmtp/tree/main/xmtp_api_grpc): API client for XMTP's gRPC API, using code from `xmtp_proto`
- [`xmtp_api_grpc_gateway`](https://github.com/xmtp/libxmtp/tree/main/xmtp_api_grpc_gateway): API client for XMTP's gRPC Gateway API, using code from `xmtp_proto` (in progress)
- [`xmtp_proto`](https://github.com/xmtp/libxmtp/tree/main/xmtp_proto): Generated code for handling XMTP protocol buffers
- [`examples/cli`](https://github.com/xmtp/libxmtp/tree/main/examples/cli): Example XMTP console client. Use the CLI to try out sending double ratchet messages on the XMTP `dev` network.
- [`examples/android/xmtpv3_example`](https://github.com/xmtp/libxmtp/tree/main/examples/android/xmtpv3_example): Example Android app (in progress)
Expand Down
2 changes: 1 addition & 1 deletion bindings_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "cae8edc45ba5b56b
uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "cae8edc45ba5b56bfcbf35b60c1ab6a97d1bf9da" }
xmtp = { path = "../xmtp", features = ["grpc", "native"] }
xmtp_cryptography = { path = "../xmtp_cryptography" }
xmtp_networking = { path = "../xmtp_networking" }
xmtp_api_grpc = { path = "../xmtp_api_grpc" }
xmtp_v2 = { path = "../xmtp_v2" }

[build_dependencies]
Expand Down
12 changes: 6 additions & 6 deletions bindings_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use xmtp::conversation::{ListMessagesOptions, Conversation};
use xmtp::conversations::Conversations;
use xmtp::storage::{EncryptedMessageStore, EncryptionKey, StorageOption, StoredMessage};
use xmtp::types::Address;
use xmtp_networking::grpc_api_helper::Client as TonicApiClient;
use xmtp_api_grpc::grpc_api_helper::Client as TonicApiClient;

use crate::inbox_owner::RustInboxOwner;
pub use crate::inbox_owner::SigningError;
Expand Down Expand Up @@ -315,7 +315,7 @@ mod tests {
create_client(
Box::new(MockLogger {}),
Box::new(ffi_inbox_owner),
xmtp_networking::LOCALHOST_ADDRESS.to_string(),
xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(),
false,
None,
None,
Expand All @@ -340,7 +340,7 @@ mod tests {
let client_a = create_client(
Box::new(MockLogger {}),
Box::new(ffi_inbox_owner.clone()),
xmtp_networking::LOCALHOST_ADDRESS.to_string(),
xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(),
false,
Some(path.to_string_lossy().to_string()),
None,
Expand All @@ -354,7 +354,7 @@ mod tests {
let client_b = create_client(
Box::new(MockLogger {}),
Box::new(ffi_inbox_owner),
xmtp_networking::LOCALHOST_ADDRESS.to_string(),
xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(),
false,
Some(path.to_string_lossy().to_string()),
None,
Expand Down Expand Up @@ -382,7 +382,7 @@ mod tests {
let client_a = create_client(
Box::new(MockLogger {}),
Box::new(ffi_inbox_owner.clone()),
xmtp_networking::LOCALHOST_ADDRESS.to_string(),
xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(),
false,
Some(path.to_string_lossy().to_string()),
Some(key),
Expand All @@ -398,7 +398,7 @@ mod tests {
let result_errored = create_client(
Box::new(MockLogger {}),
Box::new(ffi_inbox_owner),
xmtp_networking::LOCALHOST_ADDRESS.to_string(),
xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(),
false,
Some(path.to_string_lossy().to_string()),
Some(other_key.to_vec()),
Expand Down
4 changes: 3 additions & 1 deletion bindings_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ prost = { version = "0.11", features = ["prost-derive"] }
prost-types = "0.11"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.37"
xmtp_cryptography = { path = "../xmtp_cryptography" }
xmtp_api_grpc_gateway = { path = "../xmtp_api_grpc_gateway" }
xmtp_cryptography = { path = "../xmtp_cryptography", features = ["ws"] }
xmtp_proto = { path = "../xmtp_proto", features = ["proto_full"] }

[dev-dependencies]
uuid = { version = "1.3.1", features = ["v4"] }
wasm-bindgen-test = "0.3.34"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion bindings_wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
This code is still under development.

- `$ cd bindings_wasm`
- `$ wasm-pack test --headless chrome`
- `$ wasm-pack test --headless --chrome`
- `$ wasm-pack build`
18 changes: 14 additions & 4 deletions bindings_wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::prelude::{wasm_bindgen, JsError};
use xmtp_api_grpc_gateway::XmtpGrpcGatewayClient;

#[wasm_bindgen]
pub struct WasmXmtpClient {
// TODO
api: XmtpGrpcGatewayClient,
// inbox_owner: WasmInboxOwner,
}

impl WasmXmtpClient {
pub fn api(&self) -> &XmtpGrpcGatewayClient {
&self.api
}
}

#[wasm_bindgen]
impl WasmXmtpClient {
#[wasm_bindgen(constructor)]
pub fn new() -> Result<WasmXmtpClient, JsError> {
pub fn new(url: String) -> Result<WasmXmtpClient, JsError> {
// TODO
Ok(WasmXmtpClient {})
Ok(WasmXmtpClient {
api: XmtpGrpcGatewayClient::new(url),
})
}
}
Loading

0 comments on commit 1b05872

Please sign in to comment.