Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions examples/factory-contract-global/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl GlobalFactoryContract {

/// Example of calling a status message contract that was deployed as global
pub fn call_global_status_contract(&mut self, account_id: AccountId, message: String) {
ext_status_message::ext(account_id).set_status(message);
ext_status_message::ext(account_id).set_status(message).detach();
}

/// Example of complex call using global contracts
Expand Down Expand Up @@ -156,7 +156,6 @@ mod tests {
.build()
}


#[test]
fn test_deploy_global_contract() {
let context = get_context(accounts(1));
Expand All @@ -166,11 +165,9 @@ mod tests {
let code = vec![0u8; 100]; // Mock bytecode
let account_id = accounts(2);

contract.deploy_global_contract(
"test_contract".to_string(),
code.clone().into(),
account_id,
);
contract
.deploy_global_contract("test_contract".to_string(), code.clone().into(), account_id)
.detach();

// Check that the contract was recorded
let stored_hash = contract.get_global_contract_hash("test_contract".to_string());
Expand All @@ -181,7 +178,6 @@ mod tests {
assert_eq!(stored_hash.unwrap(), expected_hash.into());
}


#[test]
fn test_list_global_contracts() {
let context = get_context(accounts(1));
Expand All @@ -191,11 +187,13 @@ mod tests {
let code = vec![0u8; 100];
let account_id = accounts(2);

contract.deploy_global_contract(
"test_contract".to_string(),
code.clone().into(),
account_id.clone(),
);
contract
.deploy_global_contract(
"test_contract".to_string(),
code.clone().into(),
account_id.clone(),
)
.detach();

let contracts = contract.list_global_contracts();
assert_eq!(contracts.len(), 1);
Expand Down
7 changes: 3 additions & 4 deletions examples/factory-contract/high-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ impl FactoryContract {
.create_account()
.transfer(amount)
.add_full_access_key(env::signer_account_pk())
.deploy_contract(
include_bytes!(env!("BUILD_RS_SUB_BUILD_STATUS-MESSAGE")).to_vec(),
);
.deploy_contract(include_bytes!(env!("BUILD_RS_SUB_BUILD_STATUS-MESSAGE")).to_vec())
.detach();
}

pub fn simple_call(&mut self, account_id: AccountId, message: String) {
ext_status_message::ext(account_id).set_status(message);
ext_status_message::ext(account_id).set_status(message).detach();
}
pub fn complex_call(&mut self, account_id: AccountId, message: String) -> Promise {
// 1) call status_message to record a message from the signer.
Expand Down
14 changes: 9 additions & 5 deletions near-contract-standards/src/fungible_token/storage_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ impl FungibleToken {
if balance == 0 || force {
self.accounts.remove(&account_id);
self.total_supply -= balance;
Promise::new(account_id.clone()).transfer(
self.storage_balance_bounds().min.saturating_add(NearToken::from_yoctonear(1)),
);
Promise::new(account_id.clone())
.transfer(
self.storage_balance_bounds()
.min
.saturating_add(NearToken::from_yoctonear(1)),
)
.detach();
Some((account_id, balance))
} else {
env::panic_str(
Expand Down Expand Up @@ -56,7 +60,7 @@ impl StorageManagement for FungibleToken {
if self.accounts.contains_key(&account_id) {
log!("The account is already registered, refunding the deposit");
if amount > NearToken::from_near(0) {
Promise::new(env::predecessor_account_id()).transfer(amount);
Promise::new(env::predecessor_account_id()).transfer(amount).detach();
}
} else {
let min_balance = self.storage_balance_bounds().min;
Expand All @@ -67,7 +71,7 @@ impl StorageManagement for FungibleToken {
self.internal_register_account(&account_id);
let refund = amount.saturating_sub(min_balance);
if refund > NearToken::from_near(0) {
Promise::new(env::predecessor_account_id()).transfer(refund);
Promise::new(env::predecessor_account_id()).transfer(refund).detach();
}
}
self.internal_storage_balance_of(&account_id).unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ impl NonFungibleTokenApproval for NonFungibleToken {
refund_approved_account_ids_iter(
predecessor_account_id,
core::iter::once(&account_id),
);
)
.detach();
// if this was the last approval, remove the whole HashMap to save space.
if approved_account_ids.is_empty() {
approvals_by_id.remove(&token_id);
Expand All @@ -108,7 +109,7 @@ impl NonFungibleTokenApproval for NonFungibleToken {
// if token has no approvals, do nothing
if let Some(approved_account_ids) = &mut approvals_by_id.get(&token_id) {
// otherwise, refund owner for storage costs of all approvals...
refund_approved_account_ids(predecessor_account_id, approved_account_ids);
refund_approved_account_ids(predecessor_account_id, approved_account_ids).detach();
// ...and remove whole HashMap of approvals
approvals_by_id.remove(&token_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl NonFungibleTokenResolver for NonFungibleToken {
// The token was burned and doesn't exist anymore.
// Refund storage cost for storing approvals to original owner and return early.
if let Some(approved_account_ids) = approved_account_ids {
refund_approved_account_ids(previous_owner_id, &approved_account_ids);
refund_approved_account_ids(previous_owner_id, &approved_account_ids).detach();
}
return true;
};
Expand All @@ -467,7 +467,7 @@ impl NonFungibleTokenResolver for NonFungibleToken {
// 2. reset approvals to what previous owner had set before call to nft_transfer_call
if let Some(by_id) = &mut self.approvals_by_id {
if let Some(receiver_approvals) = by_id.remove(&token_id) {
refund_approved_account_ids(receiver_id.clone(), &receiver_approvals);
refund_approved_account_ids(receiver_id.clone(), &receiver_approvals).detach();
}
if let Some(previous_owner_approvals) = approved_account_ids {
by_id.insert(&token_id, &previous_owner_approvals);
Expand Down
2 changes: 1 addition & 1 deletion near-contract-standards/src/non_fungible_token/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn refund_deposit_to_account(storage_used: u64, account_id: AccountId) {

let refund = attached_deposit.saturating_sub(required_cost);
if refund.as_yoctonear() > 1 {
Promise::new(account_id).transfer(refund);
Promise::new(account_id).transfer(refund).detach();
}
}

Expand Down
Loading
Loading