Code Monkey home page Code Monkey logo

resources's Introduction

eosio-resources

Installation

The @wharfkit/resources package is distributed on npm.

yarn add @wharfkit/resources
# or
npm install --save @wharfkit/resources

Usage

TODO

Developing

You need Make, node.js and yarn installed.

Clone the repository and run make to checkout all dependencies and build the project. See the Makefile for other useful targets. Before submitting a pull request make sure to run make lint.


Made with ☕️ & ❤️ by Greymass, if you find this useful please consider supporting us.

resources's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

resources's Issues

cpu_frac and net_frac calculation

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,
          },
        ],
      },
    );
...

Add balance/quota tracking

Tables like powup.order can return and provide the status of current orders. A table for REX and Staking can also be accessed.

account resources weird behaviour

when i check my account resources, used cpu amount is decreasing and i cant understand why? i bought some resources using powerup model, im spending them. after sometime, my used cpu resource amount is decreasing, quite interesting and can't figure it out, could you please provide more information what might cause this or why this is happening?

thanks, dante

const result = await client.apiClient.v1.chain.get_account(address);
result.cpu_limit.used // this value is decreasing ???

cpu resource confusion

used: accountObject.cpu_limit.current_used,
usedAll: accountObject.cpu_limit.used,

what is difference of this fields? which one i can use to track my usedcpu amount, and why value of used continuously changing even though im not buying or spending cpu?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.