airgap-it / tezos-rust-sdk

MIT License
20 stars 10 forks source link

Wasm target #7

Open 852Kerfunkle opened 1 year ago

852Kerfunkle commented 1 year ago

First of all, this is great, thank you!

Compiling with --target wasm32-unknown-unknown yields a bunch of future cannot be sent between threads safely errors.

Is this on the roadmap?

RomarQ commented 1 year ago

Hi @852Kerfunkle,

Currently, this is not on the roadmap.

The error above comes from the RPC crate. The remaining crates should compile fine for target wasm32-unknown-unknown.

We may have a look at it next year if we find some time.

852Kerfunkle commented 1 year ago

Thank you @RomarQ.

It is the rpc crate, indeed. It would be the one that is most interesting to me - I probably only need bigmap queries for now :)

I can probably get by otherwise and should I really need it, maybe I can try to make a PR.

Thanks!

m-kus commented 1 year ago

Hey @852Kerfunkle ! I was able to compile by making these two changes: https://github.com/m-kus/tezos-rust-sdk/pull/1 https://github.com/m-kus/tezos-rust-sdk/pull/3

Hope that will help.

852Kerfunkle commented 1 year ago

Amazing @m-kus, thank you!

I didn't even get to figuring out what was causing the issue.

I will give it a try soon :bow:

852Kerfunkle commented 1 year ago

Right, so, I got it to compile (with tezos-contracts) removing the Send trait from a few things (ContractFetcher, Http, FeeEstimator).

@m-kus as far as I can tell, your changes made no difference for me (rustc 1.66).

No idea if it works, didn't try to use it yet.

852Kerfunkle commented 1 year ago

image

Sure seems to work.

Not sure this is useful to anyone else, but basically:

diff --git a/tezos-contract/src/contract.rs b/tezos-contract/src/contract.rs
index 6d35ed1..8e7498f 100644
--- a/tezos-contract/src/contract.rs
+++ b/tezos-contract/src/contract.rs
@@ -469,7 +469,7 @@ impl CompatibleWith<Type> for DataSome {
     }
 }

-#[async_trait]
+#[async_trait(?Send)]
 pub trait ContractFetcher<'a, HttpClient: Http + Sync> {
     async fn contract_at(
         &'a self,
@@ -478,7 +478,7 @@ pub trait ContractFetcher<'a, HttpClient: Http + Sync> {
     ) -> Result<Contract<'a, HttpClient>>;
 }

-#[async_trait]
+#[async_trait(?Send)]
 impl<'a, HttpClient: Http + Sync> ContractFetcher<'a, HttpClient> for TezosRpc<HttpClient> {
     async fn contract_at(
         &'a self,
diff --git a/tezos-rpc/src/http.rs b/tezos-rpc/src/http.rs
index 8bfb59e..c2f08ae 100644
--- a/tezos-rpc/src/http.rs
+++ b/tezos-rpc/src/http.rs
@@ -4,7 +4,7 @@ use {
     serde::{de::DeserializeOwned, Serialize},
 };

-#[async_trait]
+#[async_trait(?Send)]
 pub trait Http {
     fn new(rpc_endpoint: String) -> Self;

@@ -76,7 +76,7 @@ pub mod default {
     }

     #[cfg(feature = "http")]
-    #[async_trait]
+    #[async_trait(?Send)]
     impl Http for HttpClient {
         /// Creates an Http client that will be used to send requests to the specified node.
         fn new(rpc_endpoint: String) -> Self {
diff --git a/tezos-rpc/src/internal/estimator.rs b/tezos-rpc/src/internal/estimator.rs
index b214457..6cd844b 100644
--- a/tezos-rpc/src/internal/estimator.rs
+++ b/tezos-rpc/src/internal/estimator.rs
@@ -27,7 +27,7 @@ use crate::{
     Error, Result,
 };

-#[async_trait]
+#[async_trait(?Send)]
 pub trait FeeEstimator {
     async fn min_fee<'a>(
         &self,
@@ -48,7 +48,7 @@ impl<'a, HttpClient: Http> OperationFeeEstimator<'a, HttpClient> {

 const PLACEHOLDER_SIGNATURE: &'static str = "edsigtXomBKi5CTRf5cjATJWSyaRvhfYNHqSUGrn4SdbYRcGwQrUGjzEfQDTuqHhuA8b2d8NarZjz8TRf65WkpQmo423BtomS8Q";

-#[async_trait]
+#[async_trait(?Send)]
 impl<'a, HttpClient: Http + Send + Sync> FeeEstimator for OperationFeeEstimator<'a, HttpClient> {
     async fn min_fee<'b>(
         &self,
RomarQ commented 1 year ago

@852Kerfunkle feel free to submit a PR with your changes. We will have a look when possible.

852Kerfunkle commented 1 year ago

@RomarQ Will do, once I figured out if there's maybe a better way to achieve it. Cheers.