Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Add http & http_client wasm bindings #130

Merged
merged 21 commits into from
Oct 2, 2024
Merged

Add http & http_client wasm bindings #130

merged 21 commits into from
Oct 2, 2024

Conversation

KendallWeihe
Copy link
Contributor

No description provided.

* main:
  Add Missing Test Vectors (#128)
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;

fn convert_to_object_recursive(value: &JsValue) -> Result<JsValue, JsValue> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This replaces the mapToObject() which was removed in the typescript code, I figure it's a bit more robust to move this in to the rust layer. But also, I suspect in the future we may revamp our bindings code with the intent of improving maintainability, in which case this may go away.

@@ -0,0 +1,36 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nitro-neal check it, vectors/ here

I generated these values from our kt example app, and checked them in here. They're here right now for sanity, so we may choose to move these to official vectors in due time, or maybe find a different testing solution altogether. Just making you aware.

Copy link
Contributor

Choose a reason for hiding this comment

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

yup awesome, will add a task in our running list to add these to official test vectors basically

Copy link
Contributor

Choose a reason for hiding this comment

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

probably have a new folder for end2end flow or something, maybe doesn't belong in official test vector spot but good to have

@@ -430,6 +420,30 @@ export namespace InputDescriptor {
};
}

export type JsonSerializedMessage = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

some of our http types are multi-type so we json serialize over the ffi

Comment on lines +24 to +25
if (kind === "order") message = Order.fromJSONString(json);
else if (kind === "cancel") message = Cancel.fromJSONString(json);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the right spot to do logic?

shouldn't all logic basically be in rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah good question, the TL;DR is the wasm FFI needs concrete types, and the UpdateExchangeRequestBody has a message property that can either be an Order or a Cancel, so JSON serialize it over the FFI. so we have to embed logic on the ts side to deserialize it back into the concrete type, such that then the DX has a true WalletUpdateMessage type, so they can do conditionals like if (message instanceof Order) { ... } else if (message instanceof Cancel) { ... }. this is one of those things I'd like to spend time optimizing if we ever have the time.

Copy link
Contributor

@nitro-neal nitro-neal left a comment

Choose a reason for hiding this comment

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

Great stuff!

@KendallWeihe KendallWeihe merged commit 40445ac into main Oct 2, 2024
20 checks passed
@KendallWeihe KendallWeihe deleted the kendall/wasm-http branch October 2, 2024 11:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants