i'm trying to rent cpu and net resources, but find out very strange behavior. when im trying to buy net, so my cpu_frac is 0, it only purchase cpu resource, i discovered the other way is also true. in my case, how should i adjust my code to get rid of this behavior of power up model and rent resources correctly?
briefly, i want to know how to calculate cpu and net frac correctly, thanks!
async rentResources(params: RentResourcesDto): Promise<AccountResource> {
const { payer, reciver, cpuAmountMs, netAmountKb } = params;
const apiClient = getClient().apiClient;
const eosResources = new Resources({
api: apiClient,
});
const [powerup, rexState, ramState, sampleUsage] =
await Promise.all([
eosResources.v1.powerup.get_state(),
eosResources.v1.rex.get_state(),
eosResources.v1.ram.get_state(),
eosResources.getSampledUsage(),
]);
const cpuPrice = powerup.cpu.price_per_ms(sampleUsage, cpuAmountMs);
const netPrice = powerup.net.price_per_kb(sampleUsage, netAmountKb);
const totalCost = cpuPrice + netPrice;
const days = powerup.powerup_days;
// weird problematic part?
const cpu_frac = powerup.cpu.frac_by_ms(sampleUsage, cpuAmountMs);
const net_frac = powerup.net.frac_by_kb(sampleUsage, netAmountKb);
const powerUpAction = contract.action(
EOS_ACTIONS.POWER_UP,
{
payer,
receiver: reciver,
days,
net_frac: net_frac,
cpu_frac: cpu_frac,
max_payment: `${totalCost.toFixed(NATIVE_DECIMALS)} ${EOS_SYMBOL}`,
},
{
authorization: [
{
actor: payer,
permission: ACTIVE_PERMISSION,
},
],
},
);
...
i'm trying to rent cpu and net resources, but find out very strange behavior. when im trying to buy net, so my cpu_frac is 0, it only purchase cpu resource, i discovered the other way is also true. in my case, how should i adjust my code to get rid of this behavior of power up model and rent resources correctly?
briefly, i want to know how to calculate cpu and net frac correctly, thanks!