#
Manabar calculations
Manabars in the Hive ecosystem represent the available resources for different activities such as upvoting, downvoting, and resource credits (RC). Each type of manabar regenerates over time and is pivotal in understanding an account's capacity to perform these activities.
#
Common Parameters for Manabar Calculation for Wax Base interface
The calculations for each type of manabar follow a similar methodology, and they require some common parameters:
now: Current head block time. (Timestamp in seconds)maxMana: Maximum account mana. Can be any numeric type, string orBigInt*currentMana: Current account mana. Can be any numeric type, string orBigInt*lastUpdateTime: Last update time of the current mana (in seconds)
* - (Only in JavaScript for large numbers)
#
Calculation Methods using Wax Base Interface
#
Upvote Manabar Calculation
To calculate the upvote manabar, you need to gather the following values:
now: Can be obtained using thetimeproperty from the dynamic global properties.maxMana: Equivalent topost_voting_power.amountfrom thefind_accountAPI call.currentMana: Equivalent tovoting_manabar.current_manafrom thefind_accountAPI call.lastUpdateTime: Equivalent tovoting_manabar.last_update_timefrom thefind_accountAPI call
#
Downvote Manabar Calculation
To calculate the downvote manabar, you need to gather the following values:
now: Can be obtained using thetimeproperty from the dynamic global properties.maxMana: Equivalent topost_voting_power.amountmultiplied bydownvote_pool_percentfrom the dynamic global properties.currentMana: Equivalent todownvote_manabar.current_manafrom thefind_accountAPI call.lastUpdateTime: Equivalent todownvote_manabar.current_manafrom thefind_accountAPI call.
#
RC Manabar Calculation
To calculate the RC manabar, you need to gather the following values:
now: Can be obtained using thetimeproperty from the dynamic global properties.maxMana: Equivalent tomax_rcvalue from therc_accountsAPI call.currentMana: Equivalent torc_manabar.current_manafrom therc_accountsAPI call.lastUpdateTime: Equivalent torc_manabar.last_update_timefrom therc_accountsAPI call.
Blockchain state
Manabar calculations are sensitive to the latest blockchain state. Always fetch up-to-date dynamic global properties via API calls when using Wax Base interface. Wax Chain interface can automatically fetch required resources from the network using specified API endpoint.
#
Example Usage
High level usage
You can also calculate the manabar values using high-level Wax Chain interface that automatically parses mentioned values from the chain and uses them for calculation for requested account.
#
Calculation of Upvote Manabar for an Account
import { createHiveChain, EManabarType } from '@hiveio/wax';
const chain = await createHiveChain();
const fullRegenTime = await chain.calculateManabarFullRegenerationTimeForAccount(
"gtg",
EManabarType.UPVOTE
);
const manabarValue = await chain.calculateCurrentManabarValueForAccount(
"gtg",
EManabarType.UPVOTE
);
console.log("Full Regeneration Time for Upvote Manabar:", fullRegenTime, manabarValue.percent);
import asyncio
from datetime import datetime
from wax import create_hive_chain
async def main():
chain = create_hive_chain()
gdpo = await chain.api.database_api.get_dynamic_global_properties()
response = await chain.api.database_api.find_accounts(accounts=["gtg"])
gtg = response.accounts[0]
post_voting_power = gtg.post_voting_power.amount
upvoting_manabar = chain.calculate_current_manabar_value(
head_block_time=datetime.fromisoformat(gdpo.time),
max_mana=int(post_voting_power),
current_mana=gtg.voting_manabar.current_mana,
last_update_time=gtg.voting_manabar.last_update_time,
)
upvoting_manabar_full_regeneration_time = chain.calculate_manabar_full_regeneration_time(
head_block_time=datetime.fromisoformat(gdpo.time),
max_mana=int(post_voting_power),
current_mana=gtg.voting_manabar.current_mana,
last_update_time=gtg.voting_manabar.last_update_time,
)
print(
f"Full Regeneration Time for Upvote Manabar:",
{upvoting_manabar_full_regeneration_time},
{upvoting_manabar.percent},
)
asyncio.run(main())
#
Calculation of Full Regeneration Time for Downvote Manabar
import { createHiveChain, EManabarType } from '@hiveio/wax';
const chain = await createHiveChain();
const fullRegenTime = await chain.calculateManabarFullRegenerationTimeForAccount(
"gtg",
EManabarType.DOWNVOTE
);
const manabarValue = await chain.calculateCurrentManabarValueForAccount(
"gtg",
EManabarType.DOWNVOTE
);
console.log("Full Regeneration Time for Downvote Manabar:", fullRegenTime, manabarValue.percent);
import asyncio
from datetime import datetime
from wax import create_hive_chain
async def main():
chain = create_hive_chain()
gdpo = await chain.api.database_api.get_dynamic_global_properties()
response = await chain.api.database_api.find_accounts(accounts=["gtg"])
gtg = response.accounts[0]
post_voting_power = gtg.post_voting_power.amount
bps_downvote_value = gdpo.downvote_pool_percent
downvote_pool_percent = bps_downvote_value / 100
downvote_max_mana = int(post_voting_power) * (downvote_pool_percent / 100)
downvote_manabar = chain.calculate_current_manabar_value(
head_block_time=datetime.fromisoformat(gdpo.time),
max_mana=int(downvote_max_mana),
current_mana=gtg.downvote_manabar.current_mana,
last_update_time=gtg.downvote_manabar.last_update_time,
)
downvote_manabar_full_regeneration_time = chain.calculate_manabar_full_regeneration_time(
head_block_time=datetime.fromisoformat(gdpo.time),
max_mana=int(downvote_max_mana),
current_mana=gtg.downvote_manabar.current_mana,
last_update_time=gtg.downvote_manabar.last_update_time,
)
print(
f"Full Regeneration Time for Downvote Manabar:",
{downvote_manabar_full_regeneration_time},
{downvote_manabar.percent},
)
asyncio.run(main())
#
Calculation of Full Regeneration Time for Resource Credits Manabar
import { createHiveChain, EManabarType } from '@hiveio/wax';
const chain = await createHiveChain();
const fullRegenTime = await chain.calculateManabarFullRegenerationTimeForAccount(
"gtg",
EManabarType.RC
);
const manabarValue = await chain.calculateCurrentManabarValueForAccount(
"gtg",
EManabarType.RC
);
console.log("Full Regeneration Time for Resource Credits Manabar:", fullRegenTime, manabarValue.percent);
Results parsing
Function calculateManabarFullRegenerationTimeForAccount returns a JavaScript Date object, which can be easily processed.
calculateCurrentManabarValueForAccount returns an object with manabar values and percent loaded.
import asyncio
from datetime import datetime
from wax import create_hive_chain
from rc_api.rc_api_client import RcApi
class ExtendedApis:
def __init__(self):
self.rc_api = RcApi
async def main():
chain = create_hive_chain()
chain = chain.extends(ExtendedApis)
gdpo = await chain.api.database_api.get_dynamic_global_properties()
response = await chain.api.rc_api.find_rc_accounts(accounts=["gtg"])
rc_gtg = response.rc_accounts[0]
rc_manabar = chain.calculate_current_manabar_value(
head_block_time=datetime.fromisoformat(gdpo.time),
max_mana=rc_gtg.max_rc,
current_mana=rc_gtg.rc_manabar.current_mana,
last_update_time=rc_gtg.rc_manabar.last_update_time,
)
rc_manabar_full_regeneration_time = chain.calculate_manabar_full_regeneration_time(
head_block_time=datetime.fromisoformat(gdpo.time),
max_mana=rc_gtg.max_rc,
current_mana=rc_gtg.rc_manabar.current_mana,
last_update_time=rc_gtg.rc_manabar.last_update_time,
)
print(
f"Full Regeneration Time for Resource Credits Manabar:",
{rc_manabar_full_regeneration_time},
{rc_manabar.percent},
)
asyncio.run(main())