cpu_frac and net_frac calculation
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- blockchain
Research direction
Start at the rentResources entry point and trace powerup.cpu.frac_by_ms, powerup.net.frac_by_kb, and the POWER_UP action parameters. Reproduce the cases where either fraction is zero, then verify the resource calculation and action behavior for CPU-only, NET-only, and combined rentals.
Written by the indexing model from the issue text.
Description
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,
},
],
},
);
...
- Dominant language
- TypeScript
- Stars
- 9
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wharfkit/resources
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
All issues in wharfkit/resources
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·