/// Calls another canister and returns a future.
Calls another canister and returns a future.
Calls another canister and returns a future .
pub fn call_bytes(
    id: CanisterId,
    method: &str,
    data: &[u8],
    funds: Funds,
) -> impl Future<Output = futures::FutureResult<Vec<u8>>> {
    // the callback from IC dereferences the future from a raw pointer, assigns the
    // result and calls the waker
    fn callback(future_ptr: *mut ()) {
        let ref_counted = unsafe { RefCounted::from_raw(future_ptr as *const RefCell<CallFuture>) };
        let top_level_future = ref_counted.borrow_mut().top_level_future;
        let maybe_waker = {
            let mut future = ref_counted.borrow_mut();
            future.result = Some(match reject_code() {
                0 => Ok(arg_data()),
                n => Err((Some(n), reject_message())),
            });
            future.waker.take()
        };
        if let Some(waker) = maybe_waker {
            waker.wake();
        }
        std::mem::drop(ref_counted);
        if !top_level_future.is_null() {
            unsafe {
                TopLevelFuture::release(top_level_future);
            }
        }
    }
    let future_for_closure = RefCounted::new(CallFuture::new());
    let future = future_for_closure.clone();
    let future_ptr = future_for_closure.into_raw();
    let err_code = call_raw(
        id,
        method,
        data,
        callback,
        callback,
        None,
        future_ptr as *mut (),
        funds,
    );
    // 0 is a special error code, meaning call_simple call succeeded
    if err_code != 0 {
        // Decrease the refcount as the closure will not be called.
        std::mem::drop(unsafe { RefCounted::from_raw(future_ptr) });
        future.borrow_mut().result =
            Some(Err((Some(err_code), "Couldn't send message".to_string())));
    }
    future
}
pub fn call_bytes ( id : CanisterId , method : & str , data : & [ u8 ] , funds : Funds , ) -> impl Future < Output = futures :: FutureResult < Vec < u8 > > > { // the callback from IC dereferences the future from a raw pointer, assigns the // result and calls the waker fn callback ( future_ptr : * mut ( ) ) { let ref_counted = unsafe { RefCounted :: from_raw ( future_ptr as * const RefCell < CallFuture > ) } ; let top_level_future = ref_counted . borrow_mut ( ) . top_level_future ; let maybe_waker = { let mut future = ref_counted . borrow_mut ( ) ; future . result = Some ( match reject_code ( ) { 0 => Ok ( arg_data ( ) ) , n => Err ( ( Some ( n ) , reject_message ( ) ) ) , } ) ; future . waker . take ( ) } ; if let Some ( waker ) = maybe_waker { waker . wake ( ) ; } std :: mem :: drop ( ref_counted ) ; if ! top_level_future . is_null ( ) { unsafe { TopLevelFuture :: release ( top_level_future ) ; } } } let future_for_closure = RefCounted :: new ( CallFuture :: new ( ) ) ; let future = future_for_closure . clone ( ) ; let future_ptr = future_for_closure . into_raw ( ) ; let err_code = call_raw ( id , method , data , callback , callback , None , future_ptr as * mut ( ) , funds , ) ; // 0 is a special error code, meaning call_simple call succeeded if err_code != 0 { // Decrease the refcount as the closure will not be called. std :: mem :: drop ( unsafe { RefCounted :: from_raw ( future_ptr ) } ) ; future . borrow_mut ( ) . result = Some ( Err ( ( Some ( err_code ) , " " . to_string ( ) ) ) ) ; } future }
Calls another canister and returns a future.
Calls another canister and returns a future .
id
CanisterId
method
&str
data
&[u8]
funds
Funds