浏览代码

Fixed wasm build

Cesar Rodas 2 周之前
父节点
当前提交
6c1593b0df
共有 1 个文件被更改,包括 18 次插入5 次删除
  1. 18 5
      crates/cdk/src/wallet/try_proof_operation.rs

+ 18 - 5
crates/cdk/src/wallet/try_proof_operation.rs

@@ -1,11 +1,24 @@
 use std::future::Future;
 
-use futures::future::BoxFuture;
-
 use crate::amount::SplitTarget;
 use crate::nuts::{Proofs, State};
 use crate::{Error, Wallet};
 
+#[cfg(not(target_arch = "wasm32"))]
+type MaybeBoxFuture<'a, T> = futures::future::BoxFuture<'a, T>;
+#[cfg(target_arch = "wasm32")]
+type MaybeBoxFuture<'a, T> = futures::future::LocalBoxFuture<'a, T>;
+
+#[cfg(not(target_arch = "wasm32"))]
+pub trait MaybeSend: Send {}
+#[cfg(target_arch = "wasm32")]
+pub trait MaybeSend {}
+
+#[cfg(not(target_arch = "wasm32"))]
+impl<T: ?Sized + Send> MaybeSend for T {}
+#[cfg(target_arch = "wasm32")]
+impl<T: ?Sized> MaybeSend for T {}
+
 /// Size of proofs to send to avoid hitting the mint limit.
 const BATCH_PROOF_SIZE: usize = 100;
 
@@ -18,10 +31,10 @@ impl Wallet {
         &'a self,
         inputs: Proofs,
         f: F,
-    ) -> BoxFuture<'a, F::Output>
+    ) -> MaybeBoxFuture<'a, F::Output>
     where
-        F: Future<Output = Result<R, Error>> + Send + 'a,
-        R: Send + Sync,
+        F: Future<Output = Result<R, Error>> + MaybeSend + 'a,
+        R: MaybeSend + Sync + 'a,
     {
         Box::pin(async move {
             match f.await {