update for beem: automatic chain detection and several improvements/fixes

in HiveDevs4 years ago

Repository

https://github.com/holgern/beem


beem-logo

beem is a python library and command line tool for HIVE. The current version is 0.24.9.

There is also a discord channel for beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

pip install -U beem

Check that you are using hive nodes. The following command

beempy updatenodes --hive

updates the nodelist and uses only hive nodes. After setting hive as default_chain, beempy updatenodes can be used.

The list of nodes can be checked with

beempy config

and

beempy currentnode

shows the currently connected node.

Changelog for versions 0.24.6 - 0.24.9

  • Improved community selection in beempy createpost
  • Improved Transactionbuilder object representation
  • _fetchkeys function moved outside appendSigner
  • Fix get urls in parse body
  • Two more nodes have been added to nodelist
  • new beempy chaininfo command
  • Automatic chain detection (beempy will now connect to unknown chain ids)
  • Support for update_proposal_operation (thanks to dkedzierski)
  • Remove not needed SECP256K1 import
  • Fix corner case last_irreversible_block_num == head_block_number for Transactionbuilder (thanks to dkedzierski)
  • import keyring only when needed
  • Add use_condenser to config (can be set wtih beempy set), when set to False, condenser calls are not used
  • Add set_expiration to Object Cache
  • Use floor instead of round in beembase/Amount in order to handle floats which have a higher precision than allowed
  • json_str parameter has been added to beembase.Amount, when True, a json dict is returned as string (needing when broadcasting with use_condenser=False)
  • Handle deleted comments in beempy pending thanks to @crokkon

Automatic chain detection

beem is now able to connect to nodes with unknown chain ids.
This allows it to build a testnet with a new chain-id and use beem for testing.

E.g when running a witness server in a test net, beem can now be connected to the local node:

beempy set nodes ws://127.0.0.1:8091

It is also possible to connect to the testnet from @inertia (https://peakd.com/hive-139531/@inertia/testnet-update):

beempy set nodes http://134.209.41.170:8091

It is possible to view the chain config with

beempy chainconfig

The following commands can be used to go back to the hive blockchain (use_condenser is also set to true as explained in the next section):

beempy updatenodes --hive
beempy set use_condenser true

Disable condenser api calls

The testnet from inertia does not have the condenser API activated. Therefore, I added a new config parameter which can be used to disable condenser API calls.

The condenser API is disabled by

beempy set use_condenser false

The condenser API is enabled by

beempy set use_condenser true

This allows it to broadcast on the testnet.

beem uses normally the condenser API for broadcasting, as the non-condenser version needs all amounts in json format and not as string.

It is now possible to use the json format for broadcasting when setting json_str=True. This is automatically done, when setting use_condenser=True.

Use the beem to broadcast a transfer on the HF24 testnet

As the testnet has a different prefix (TST), keys have to be added again with addkey:

beempy set nodes http://134.209.41.170:8091
beempy set use_condenser false
beempy addkey

Now we can broadcast a transfer (HIVE -> TESTS and HBD -> TBD):

beempy transfer -a holger80 beembot 0.001 TESTS test

The balance can be checked with

beempy balance beembot

Here is also two small python snippets for broadcasting a transfer on the HF24 testnet:

from beem import Hive
from beem.transactionbuilder import TransactionBuilder
from beembase import operations
tstnet = Hive("http://134.209.41.170:8091")
tstnet.wallet.unlock("my_wallet_pass")
tx = TransactionBuilder(use_condenser=False, blockchain_instance=tstnet)
op = operations.Transfer(**{"from": 'holger80',
                            "to": 'beembot',
                            "amount": '0.001 TESTS',
                            "memo": 'test 1',
                            "json_str": True,
                            "prefix": "TST"})
tx.appendOps(op)
tx.appendSigner('holger80', 'active')
tx.sign()
tx.broadcast()
from beem import Hive
from beem.account import Account
tstnet = Hive("http://134.209.41.170:8091")
tstnet.wallet.unlock("my_wallet_pass")

condenser_config = tstnet.config["use_condenser"]
tstnet.config["use_condenser"] = False

acc = Account("holger80", blockchain_instance=tstnet)
acc.transfer("beembot", 0.001, "TESTS", "test 2")

# Set to old state
tstnet.config["use_condenser"] = condenser_config

Here, use_condenser is set to False before broadcasting. As this is stored, the old state is restored at the end of the script.

I'm not so happy with my solution for use_condenser. I will think of a better solution in the nest release.

Handling of amounts which have an higher precision than allowed

Beem does not handle amounts with more than 3 digits for HIVE and HBD and with more than 6 digits for VESTS.

Before 0.24.9, a float amount was rounded to 3 or 6 digits when calculating the bytes representation of an amount (which is needed for the signature). This bug makes it impossible to transfer 0.9999 HIVE (as it was rounded to 1.000 internally).

We can now try to transfer 0.0199 TESTS on the testnet (I changed the node to the testnet, set use_condenser=False and added my active key as described above):

beempy transfer -a holger80 beembot 0.0199 TESTS test

The 0.0199 are now correctly handled and 0.019 TESTS have been transferred.


If you like what I do, consider casting a vote for me as witness on Hivesigner or on PeakD

Sort:  

Upvoted to thank you @holger80 for supporting the CO2Fund by, e.g., supporting posts, banner presentation, SP/HP delegation, dustsweeper gifts, helpful tools, etc.

Congratulations @holger80! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You received more than 60000 upvotes. Your next target is to reach 65000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @hivebuzz:

HiveBuzz supports meetups of the Hive UK Community
Feedback from the September 1st Hive Power Up Day

Nice works with testnets easier :)

That is a big win!

I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!