复制源代码

eosio.contracts 项目中,复制eosio.contracts/eosio.system/src/exchange_state.cppeosio.contracts/eosio.system/include/eosio.system/exchange_state.hpp两个文件到你合约项目中。
并在你的合约中include

#include "common/exchange_state.hpp"
#include "common/exchange_state.cpp"

计算代码

uint64_t bcskill_contract::exchange_ram(eosio::asset quantity){
    rammarket market(k_eosio, k_eosio.value);
    auto it = market.find(k_ramcore_sym.raw());
    eosio_assert(it != market.end(), "125");
    auto tmp = *it;

    /* Convert EOS amount to ram bytes */
    auto out_ram_bytes = tmp.convert(quantity, k_ram_sym);
    return out_ram_bytes.amount;
}