thesimplekid / cashcrab

Cashu mobile wallet with nostr contacts and direct messaging
BSD 3-Clause "New" or "Revised" License
20 stars 1 forks source link

receive_token error #1

Open shanelau opened 1 year ago

shanelau commented 1 year ago

Thank you for working on this project, it has been very inspiring for my own project. However, I have encountered some issues.

If try to execute receive_token function twice, always get an error.

My code

    let encoded_token: &str = "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6IkkyeU4raVJZZmt6VCIsImFtb3VudCI6MSwiQyI6IjAzOGFjZDI2ZGExZTFlYzc0M2E4NmIxNTkwM2FiYjIyNzdjNDAwMDlkZDM2ZGMxZGJhOGQ0MjM5MWE2YjcyMmEwYSIsInNlY3JldCI6IlNXa0lnbDNIYXhOTUcxL1REbk9qazVqVEI1cVc0MzRYV1ZldUE2cmNSb1E9In1dLCJtaW50IjoiaHR0cHM6Ly84MzMzLnNwYWNlOjMzMzgifV19";
    let r6 = api::receive_token(encoded_token.to_string());
    let r6 = api::receive_token(encoded_token.to_string());
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/liuxing/.cargo/git/checkouts/cashu-crab-236eaaf426c3a3cb/eb31150/src/wallet.rs:121:40
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panicking.rs:117:5
   3: core::option::Option<T>::unwrap
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/option.rs:935:21
   4: cashu_crab::wallet::Wallet::receive::{{closure}}
             at /Users/liuxing/.cargo/git/checkouts/cashu-crab-236eaaf426c3a3cb/eb31150/src/wallet.rs:121:21
   5: rust::cashu::receive_token::{{closure}}

Flutter ffi call

In the Flutter project, the process gets stuck and the cannot get lock. Any function call results in an error.

FfiException (FfiException(RESULT_ERROR, Failed to lock the runtime mutex: poisoned lock: another task failed inside, null))

thesimplekid commented 1 year ago

Hey,

Thanks for taking a look. I have seen this before and worked around it by droping the runtime in the api so I'm a little surprised to see it happening again.

Are you using the rust crate from this project in your own flutter project? You may have more flexibility not calling the api from this project and calling the cashu-crab library directly. Though just a warning I'm in the middle of a refactor (see below).

I found using flutter and rust in the way I did in this project while interesting, quite difficult especially around async. Which is in part why I haven't worked on this in a bit, I am currently in the middle of refactoring the cashu-crab library to have native ffi bindings. This would enable the library to be used more easily in native apps as in theory at least I should be able to support kotlin, swift, and flutter bindings.