Function near_contract_tools::utils::apply_storage_fee_and_refund
source · [−]pub fn apply_storage_fee_and_refund(
initial_storage_usage: u64,
additional_fees: u128
) -> Option<Promise>
Expand description
Calculates the storage fee of an action, given an initial storage amount, and refunds the predecessor a portion of the attached deposit if necessary. Returns refund Promise if refund was applied.
Examples
use near_contract_tools::utils::apply_storage_fee_and_refund;
let initial_storage_usage = near_sdk::env::storage_usage();
let additional_fees = 0;
// Action that consumes storage.
near_sdk::env::storage_write(b"key", b"value");
near_sdk::testing_env!(near_sdk::test_utils::VMContextBuilder::new()
.attached_deposit(near_sdk::ONE_NEAR)
.build());
// Attached deposit must cover storage fee or this function will panic
apply_storage_fee_and_refund(initial_storage_usage, additional_fees);