update for beem - adding RC costs calculation and witness_set_properties broadcasting

in utopian-io •  6 months ago




beem is a python library for steem. beem has now 489 unit tests and a coverage of 73 %. The current version is 0.20.5.
I created a discord channel for answering a question or discussing beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

pip install -U beem

or when using conda:

conda install beem

beem can be updated by:

conda update beem

As utopian-io was not available for quite a long time, I could not post development updates for beem. Thus this post contains the changes for beem releases 0.19.57, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.20.4 and 0.20.5. Hopefully, I will receive a utopian-io upvote this time. (my last developement update did not receive a vote).

New Features

Implementing witness_set_properties

Implementing this new operation was really hard work, as this operation uses a new and undocumented format. Finally after finding out:

  • each parameter value must be transmitted as hex number (e.g. (hexlify(Uint32(k[1]).__bytes__())).decode()) - commit 6cc303d
  • The map structure can be used for building the trx dict - commit 6cc303d
  • all key have to sorted (commit f63c0ce3)
  • A new HexString class was implemented, as each hex value must be transformed to bytes(unhexlify(bytes(self.data, 'ascii'))) for building the bytes field for signing - (commit f63c0ce3)
    The operation must be signed with the last set witness key and it is not possible to use this operation when a witness is disabled.

After being able to broadcast, a new function witness_set_properties for building the operation dict was added to witness_set_properties.

    def witness_set_properties(self, wif, owner, props, use_condenser_api=True):
        """ Set witness properties
             :param privkey wif: Private signing key
            :param dict props: Properties
            :param str owner: witness account name
                    "account_creation_fee": x,
                    "account_subsidy_budget": x,
                    "account_subsidy_decay": x,
                    "maximum_block_size": x,
                    "url": x,
                    "sbd_exchange_rate": x,
                    "sbd_interest_rate": x,
                    "new_signing_key": x

A new command witnessproperties was then also added to beempy.

Usage: beempy witnessproperties [OPTIONS] WITNESS WIF

  Update witness properties of witness WITNESS with the witness signing key WIF

  --account_creation_fee TEXT    Account creation fee (float)
  --account_subsidy_budget TEXT  Account subisidy per block
  --account_subsidy_decay TEXT   Per block decay of the account subsidy pool
  --maximum_block_size TEXT      Max block size
  --sbd_interest_rate TEXT       SBD interest rate in percent
  --new_signing_key TEXT         Set new signing key
  --url TEXT                     Witness URL
  --help                         Show this message and exit.

Only the set parameter is changed, all other remain unchanged.

Adding a class to calculate RC costs for different operation

The RC costs depend on the four pools (resource_execution_time is not used yet):

  • resource_history_bytes
  • resource_market_bytes
  • resource_new_accounts
  • resource_state_bytes

and the parameter from the price_curve_params field:

  • coeff_a
  • shift
  • coeff_b

as well as from

  • rc_regen (is the same for all pools: int(Amount(dyn_param["total_vesting_shares"], steem_instance=self)) / (STEEM_RC_REGEN_TIME / config["STEEM_BLOCK_INTERVAL"])
  • resource_unit is stored in the resource_dynamics_params field

There are rules to get the resource_count for each operation. For example for a comment it is:

state_bytes_count = state_object_size_info["comment_object_base_size"]
state_bytes_count += state_object_size_info["comment_object_permlink_char_size"] * permlink_length
state_bytes_count += state_object_size_info["comment_object_parent_permlink_char_size"] * parent_permlink_length
resource_count = {"resource_history_bytes": tx_size}
resource_count["resource_state_bytes"] = state_object_size_info["transaction_object_base_size"]
resource_count["resource_state_bytes"] += state_object_size_info["transaction_object_byte_size"] * tx_size
resource_count["resource_state_bytes"] += state_bytes_count

For a comment with:


the resource_count dict is

{'resource_history_bytes': 1000,
 'resource_state_bytes': 2290090}

These values can now be used to calculate the RC costs:

        total_cost = 0
        if rc_regen == 0:
            return total_cost
        for resource_type in resource_count:
            curve_params = params[resource_type]["price_curve_params"]
            current_pool = int(pools[resource_type]["pool"])
            count = resource_count[resource_type]
            count *= params[resource_type]["resource_dynamics_params"]["resource_unit"]
            cost = self._compute_rc_cost(curve_params, current_pool, count, rc_regen)
            total_cost += cost


def _compute_rc_cost(self, curve_params, current_pool, resource_count, rc_regen):
    """Helper function for computing the RC costs"""
    num = int(rc_regen)
    num *= int(curve_params['coeff_a'])
    num = int(num) >> int(curve_params['shift'])
    num += 1
    num *= int(resource_count)
    denom = int(curve_params['coeff_b'])
    if int(current_pool) > 0:
        denom += int(current_pool)
    num_denom = num / denom
    return int(num_denom) + 1

The function from the new RC class can also be used to calculate RC costs:

from beem.rc import RC
rc = RC()
comment_RC_costs = rc.comment(tx_size=1000, permlink_length=10, parent_permlink_length=0)
print("RC costs for a comment: %.2f G RC" % (comment_RC_costs  / 1e9))

It is also possible to use a comment operation dict with the comment_dict function. RC costs are implemented for

  • comment
  • vote
  • transfer
  • custom_json

As the RC values are really high, I use mainly G RC which is RC/1e9.

More HF20 related changes

  • add get_resource_params(), get_resource_pool(), claim_account(), create_claimed_account() to Steem
  • fix 30x fee for create_account
  • add find_rc_accounts() to Blockchain
  • get_rc(), get_rc_manabar(), get_manabar() added to Account
  • get_voting_power() fixed
  • get_manabar_recharge_time_str(), get_manabar_recharge_timedelta() and get_manabar_recharge_time() added
  • get_api_methods() and get_apis() added to Steem
  • get_effective_vesting_shares() added to calculated max_mana correctly
  • comment_benefactor_reward adapted for snapshot

Commit history

Release 0.20.5

Release 0.20.4

  • commit 3947677
  • get_effective_vesting_shares() added to calculated max_mana correctly
  • dict key words adapted to steemd for get_manabar() and get_rc_manabar()
  • Voting mana fixed for 0 SP accounts
  • comment_benefactor_reward adapted for snapshot
  • Custom_json RC costs added to print_info

Release of 0.20.3


  • add comment, vote, transfer RC costs in account.print_info() and beempy power
  • Shows number of possible comments, votes, tranfers with available RCs in account.print_info() and beempy power


  • add possibility to specify tx_size instead of constructing a dict for comment, transfer, vote and custom_json

Fix witness update for beempy disablewitness and beempy enablewitness

Implementation of a RC costs calculation class

  • commit 827f41cb
  • get_rc_cost was added to steem to calculation RC costs from resource count


  • get_tx_size(), get_resource_count(), comment(), vote(), transfer() and custom_json() added

several bug fixes

release of 0.20.2

  • commit 3ba1b97
  • estimated_mana is now capped by estimated_max
  • print_info fixed()
  • get_api_methods() and get_apis() added to Steem

Release of 0.20.1

  • commit a2ea86d
  • Improved get_rc_manabar(), get_manabar() output
  • get_voting_power() fixed again
  • print_info for account improved
  • get_manabar_recharge_time_str(), get_manabar_recharge_timedelta() and get_manabar_recharge_time() added
  • https://steemd-appbase.steemit.com added to nodelist

Release of 0.20.0

  • commit ebc508a
  • Fully supporting hf20
  • add get_resource_params(), get_resource_pool(), claim_account(), create_claimed_account() to Steem
  • fix 30x fee for create_account
  • add find_rc_accounts() to Blockchain
  • get_rc(), get_rc_manabar(), get_manabar() added to Account
  • get_voting_power() fixed

Preparing first release for HF20, adapt account create for HF20

add new witness_set_properties function

  • commit 4771398
  • witnessproperties is added to beempy for setting new witness parameter
  • witnessfeed uses the new witness_set_properties function when a wif is provided

Fix bytes representation of hex strings and add key sorting to Witness_set_properties

Update nodelist and add not_working parameter to get_nodes()

Add unit test for witness_set_properties

Implementation of Witness_set_properties

  • commit 6cc303d
  • All parameter are packed now in a correct way
  • Correct operationid for Witness_set_properties


  • naming of symbol and asset improved

Add missing changes to transactionbuilder

  • commit e1cea48
  • Add parameter for enabling usage of condenser_api for broadcasting
  • Add ref_block_num and ref_block_prefix to constructTx for offline signing

Add Witness_set_properties to operations and add Offline constructTx

  • commit e61c802
  • Example for using offline signing is provided
  • Next release prepared
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Implementing this new operation was really hard work, as this operation uses a new and undocumented format.

I know that feeling. I was about to try the new witness_set_properties before around 1-2 days the HF20 activation date, and can't find anyone tried it.

Thanks for the great updates on the HF20 process.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.

Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.


Thank you for your review, @emrebeyler!

So far this week you've reviewed 4 contributions. Keep up the good work!

Great work as always, thank you! Have my witness vote!

Good job holger! I missed out on some utopian-votes myself, but I'm sure you'll get a big one for your outstanding job.


Thanks for the important hint that the keys must be sorted in the witness_set_properties operation.


You're welcome! That was quite the eureka moment for me, when I realized this. :D

This post has been just added as new item to timeline of beem on Steem Projects.

If you want to be notified about new updates from this project, register on Steem Projects and add beem to your favorite projects.

Hi @holger80!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Great Job my friend!

Thanks for this post @holger80.

I wish I knew what it said. LOL.

It is wonderful that there is so much development taking place on the back end to enable this blockchain to progress forward.


Thanks, yes developement of such libraries as beem is important and reduce the work load for all other devs that developing something for steem.

Posted using Partiko Android

Thanks for the cool work. Just tried the CLI tool steempy for the first time and it is not as robust as I thought it is. Someone recommended me to the Beempy and I should really try it out. Keep up the work man.

each parameter value must be transmitted as hex number


Hey, @holger80!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!