Improved testnet/3rd party chain support in Beem

작년


Image: @creativista

Repository

https://github.com/holgern/beem

Introduction

The past few weeks have shown that testing new or changed blockchain functionality - before it is deployed to the production systems - is a crucial process also for Steem. Steem testnets are available from multiple sources, including the Steemit official testnet at https://testnet.steemitdev.com .
However, testnets are not an exact 1:1 copy of the production chain. They often have a custom prefix and own asset symbols. The prefix is, among others, used as the first characters in the string representation of public keys.

Steem prod-chainSteemit testnet
PrefixSTMTST
STEEM SymbolSTEEMTESTS
SBD SymbolSBDTBD
VESTS SymbolVESTSVESTS

Other use cases are the recently added initial support for the EFTG chain, Whaleshares.io, Weku, VIT, or others, where asset names are also different from the default Steem assets. While this seems like a trivial detail, providing the correct values to the transaction signing logic is crucial to properly sign transactions that are accepted by the corresponding chain.

Adding chain prefix handling

Commit 4d7fbc0

Let's take a transfer operation as an example, attempting to transfer "0.001 TESTS" to myself on the testnet:

from beem import Steem
from beem.account import Account
import getpass

key = getpass.getpass("active key: ")
s = Steem(node=['https://testnet.steemitdev.com'], keys=[key])
s.chain_params["chain_id"] = "46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32"

a = Account('crokkon', steem_instance=s)
print(a.transfer('crokkon', 0.001, 'TESTS'))

(Note: the chain_id override is required because the Steemit testnet reports a different chain_id than what it is using internally)

This snipped previously failed with an Exception: Asset unknown error. What happened in the background was that the amount "0.001 TESTS" was internally transformed into an Amount() instance. This step handled the asset "TESTS" correctly because it knows about the chain assets from the Steem() instance passed as one argument. The serialization step, however, failed because this chain/asset information was not passed on from there and the code didn't find the correct asset symbol in the default Steem chain parameters.

The situation was addressed by forwarding the chain prefix information into all chain-dependent object serialization methods: By providing the corresponding chain prefix to the transaction serialization logic, beem can now be used with any asset symbols and therefore any testnet or third-party Steem blockchain with non-default asset names. The above code sample works without an error now.

Adding generic symbol names

Commits 3bd5b08, a38250c, ad12c4b, d7c8a7c, e391bf6

The forwarding of the chain prefix in the serialization/transaction signing step makes it possible to use any blockchain ops also on the testnet or other third-party chains from the low-level TransactionBuilder interface or selected higher-level functions like Account.transfer() shown above. However, at various places across the code were references to amounts in STEEM, SBD or VESTS with hard-coded symbol names, especially in default values:

def claim_account(self, creator, fee="0 STEEM", **kwargs):
[...]
default_max_payout = "1000000.000 SBD"

Assignments like these are perfectly fine for the operation with the production chain, but bring asset name problems with the testnet or other third-party chains. For that reason, generic asset symbols were introduced: By adding asset symbol name properties for the equivalent of SBD, STEEM and VESTS of the currently used chain, these cases can be handled dynamically. e.g. steem.sbd_symbol will return 'SBD' on the production chain, but 'TBD' when connected to the Steemit testnet. With these properties, any default amounts in the code can use the corresponding asset symbols of the current chain without using hard-coded values.

Contained in beem-0.20.6

Both changes were merged into beem master with PR #91 and are contained in beem-0.20.6.

GitHub Account

https://github.com/crokkon

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!
STEEMKR.COM IS SPONSORED BY
ADVERTISEMENT
Sort Order:  trending

prefix.jpeg


Jokes aside, I had to do some lower level stuff yesterday with testnet on Beem. Looks like upgrading it would boost my productivity. :)

This is a great contribution to see since it requires extensive knowledge and research in the core of beem while you're not a part of the core team of the project.

On a side note, Looks like you have forgot a print here for the debugging?


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.
[utopian-moderator]

·

Oups, the print shouldn't be there indeed - thanks for the remark and the review! :)

·

Thank you for your review, @emrebeyler!

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

·

This makes vote selling operations.

Hi @crokkon!

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

Hey, @crokkon!

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!