pub fn request(&mut self, payment: U128, spec_id: Base64String, callback_address: AccountId, callback_method: String, nonce: U128, data_version: U128, data: Base64String) {
        self._check_callback_address(&callback_address);
        let nonce_u128: u128 = nonce.into();

        let entry_option = self.requests.get(&env::predecessor_account_id());
        if entry_option.is_some() {
            // Ensure there isn't already the same nonce
            let nonce_entry = entry_option.unwrap();
            if nonce_entry.contains_key(&nonce_u128) {
                env::panic(b"Existing account and nonce in requests");
            }
        }

        let last_nonce_option: Option<U128> = self.get_nonce(env::predecessor_account_id());
        if last_nonce_option.is_some() {
            let last_nonce_u128: u128 = last_nonce_option.unwrap().into();
            assert!(last_nonce_u128 < nonce_u128, format!("Invalid, already used nonce: {:?}", nonce_u128));
        }
        let has_nonce_option = self.nonces.get(&env::predecessor_account_id());
        let transfer_cost = if has_nonce_option.is_some() {
            0u128
        } else {
            TRANSFER_FROM_NEAR_COST
        };
        // first transfer token
        let promise_transfer_tokens = env::promise_create(
            self.link_account.clone(),
            b"transfer_from",
            json!({
                "owner_id": env::predecessor_account_id(),
                "new_owner_id": env::current_account_id(),
                "amount": payment,
            }).to_string().as_bytes(),
            transfer_cost,
            SINGLE_CALL_GAS,
        );

        // call this contract's request function after the transfer
        let promise_call_self_request = env::promise_then(
            promise_transfer_tokens,
            env::current_account_id(),
            b"store_request",
            json!({
                "sender": env::predecessor_account_id(),
                "payment": payment,
                "spec_id": spec_id,
                "callback_address": callback_address,
                "callback_method": callback_method,
                "nonce": nonce,
                "data_version": data_version,
                "data": data
            }).to_string().as_bytes(),
            0,
            SINGLE_CALL_GAS
        );

        env::promise_return(promise_call_self_request);
    }
/// This is the entry point that will use the escrow transfer_from.
/// Afterwards, it essentially calls itself (store_request) which stores the request in state.
This is the entry point that will use the escrow transfer_from.
Afterwards, it essentially calls itself (store_request) which stores the request in state.
This is the entry point that will use the escrow transfer_from . Afterwards it essentially calls itself ( store_request ) which stores the request in state .
pub fn request(&mut self, payment: U128, spec_id: Base64String, callback_address: AccountId, callback_method: String, nonce: U128, data_version: U128, data: Base64String) {
        self._check_callback_address(&callback_address);
        let nonce_u128: u128 = nonce.into();
        let entry_option = self.requests.get(&env::predecessor_account_id());
        if entry_option.is_some() {
            // Ensure there isn't already the same nonce
            let nonce_entry = entry_option.unwrap();
            if nonce_entry.contains_key(&nonce_u128) {
                env::panic(b"Existing account and nonce in requests");
            }
        }
        let last_nonce_option: Option<U128> = self.get_nonce(env::predecessor_account_id());
        if last_nonce_option.is_some() {
            let last_nonce_u128: u128 = last_nonce_option.unwrap().into();
            assert!(last_nonce_u128 < nonce_u128, format!("Invalid, already used nonce: {:?}", nonce_u128));
        }
        let has_nonce_option = self.nonces.get(&env::predecessor_account_id());
        let transfer_cost = if has_nonce_option.is_some() {
            0u128
        } else {
            TRANSFER_FROM_NEAR_COST
        };
        // first transfer token
        let promise_transfer_tokens = env::promise_create(
            self.link_account.clone(),
            b"transfer_from",
            json!({
                "owner_id": env::predecessor_account_id(),
                "new_owner_id": env::current_account_id(),
                "amount": payment,
            }).to_string().as_bytes(),
            transfer_cost,
            SINGLE_CALL_GAS,
        );
        // call this contract's request function after the transfer
        let promise_call_self_request = env::promise_then(
            promise_transfer_tokens,
            env::current_account_id(),
            b"store_request",
            json!({
                "sender": env::predecessor_account_id(),
                "payment": payment,
                "spec_id": spec_id,
                "callback_address": callback_address,
                "callback_method": callback_method,
                "nonce": nonce,
                "data_version": data_version,
                "data": data
            }).to_string().as_bytes(),
            0,
            SINGLE_CALL_GAS
        );
        env::promise_return(promise_call_self_request);
    }
pub fn request ( & mut self , payment : U128 , spec_id : Base64String , callback_address : AccountId , callback_method : String , nonce : U128 , data_version : U128 , data : Base64String ) { self . _check_callback_address ( & callback_address ) ; let nonce_u128 : u128 = nonce . into ( ) ; let entry_option = self . requests . get ( & env :: predecessor_account_id ( ) ) ; if entry_option . is_some ( ) { // Ensure there isn't already the same nonce let nonce_entry = entry_option . unwrap ( ) ; if nonce_entry . contains_key ( & nonce_u128 ) { env :: panic ( b" " ) ; } } let last_nonce_option : Option < U128 > = self . get_nonce ( env :: predecessor_account_id ( ) ) ; if last_nonce_option . is_some ( ) { let last_nonce_u128 : u128 = last_nonce_option . unwrap ( ) . into ( ) ; assert ! ( last_nonce_u128 nonce_u128 format ( " " nonce_u128 ) ) ; } let has_nonce_option = self . nonces . get ( & env :: predecessor_account_id ( ) ) ; let transfer_cost = if has_nonce_option . is_some ( ) { 0u128 } else { TRANSFER_FROM_NEAR_COST } ; // first transfer token let promise_transfer_tokens = env :: promise_create ( self . link_account . clone ( ) , b" " , json ! ( { " " env predecessor_account_id ( ) " " env current_account_id ( ) " " payment } ) . to_string ( ) . as_bytes ( ) , transfer_cost , SINGLE_CALL_GAS , ) ; // call this contract's request function after the transfer let promise_call_self_request = env :: promise_then ( promise_transfer_tokens , env :: current_account_id ( ) , b" " , json ! ( { " " env predecessor_account_id ( ) " " payment " " spec_id " " callback_address " " callback_method " " nonce " " data_version " " data } ) . to_string ( ) . as_bytes ( ) , 0 , SINGLE_CALL_GAS ) ; env :: promise_return ( promise_call_self_request ) ; }
This is the entry point that will use the escrow transfer_from.
This is the entry point that will use the escrow transfer_from .
&mut self
payment
U128
spec_id
Base64String
callback_address
AccountId
callback_method
String
nonce
U128
data_version
U128
data
Base64String
&mut self
payment
U128
spec_id
Base64String
callback_address
AccountId
callback_method
String
nonce
U128
data_version
U128
data
Base64String