update for beem - steem-engine token transfer possible and customjson added as beempy command

in #utopian-io5 years ago (edited)

Repository

https://github.com/holgern/beem


beem-logo

beem is a python library for steem. beem has now 495 unit tests and a coverage of 70 %. The current version is 0.20.19.
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

New Features

Improve derive_permlink and allow replies of comments with permlink lenght > 235

It is now possible to reply to posts or comments which have a permlink longer than 235 characters.
The reply permlink is built in the derive_permlink function. The parent_permlink is now limited to 235 chars and the reply permlink is build corrently:

        permlink += "re-"
        permlink += parent_permlink[:(max_permlink_length - 20)]
        permlink += "-" + formatTime(timenow.time()) + "z"

Before this changes, the reply function could not broadcast a reply when the permlink of the parent was longer than 235 chars.

Allow broadcasting custom_json with active keys

When the required_auths instead of the required_posting_auths field is set, the custom_json should be signed by the active key. This is now implemented:

        if len(required_auths) > 0:
            return self.finalizeOp(op, account, "active", **kwargs)
        else:
            return self.finalizeOp(op, account, "posting", **kwargs)

The json field of a custom_json op is now compressed (spaces are removed)

All spaces in the json field of a custom_json op are now removed. This decrease the consumption of RC. And fix parsing errors for specific dapps (e.g. steem-token).

Sending of steem-engine token is working

The implementation of signing a custom_json with active key and broadcasting the json field compressed, allows it now to send a steem-engine token using beem:

from beem import Steem
stm = Steem(keys=["5xx"])
account = "holger80"
data = {"contractName": "tokens", "contractAction":"transfer",  "contractPayload":{"symbol":"DRAGON", "to":"beembot", "quantity":0.01, "memo":"Test"}}
stm.custom_json("ssc-mainnet1", data, required_auths=[account])

beempy customjson

A new command was added to beempy, which allows it to broadcast custom_json ops.

Usage: beempy customjson [OPTIONS] JSONID [JSON_DATA]...
  Broadcasts a custom json

  First parameter is the cusom json id, the second field is a json file or a
  json key value combination e.g. beempy customjson -a holger80 dw-heist
  username holger80 amount 100

Options:
  -a, --account TEXT  The account which broadcasts the custom_json
  -t, --active        When set, the active key is used for broadcasting
  --help              Show this message and exit.

The customjson commands allows it to send easily all different kind of custom_jsons.
The first parameter JSONID is the custom json id, for a follow, it is for example follow.
The second parameter JSON_DATA can be either a json file or a combination of json key/value fields.

For not so complicated json_data fields, the keys and values can be given as parameters:
For example for a custom_json with an id = dw-heist and a simple json field = { "username": "holger80", "amount": "100"}, it can directly entered by removing all {, }, ,, ", and ::

beempy customjson -a holger80 dw-heist username holger80 amount 100

Giving the json field as key value sequence is only possible when all fields are strings.
This command is equivalent to the following command which reads the json data from a file:

beempy customjson -a holger80 dw-heist  dw_heist.json

with dw_heist.json:

{
    "username": "holger80",
    "amount": "100"
}

Results:

image.png

Sending a steem-engine token:

For more complicated cases, where the values inside the custom_json consisting of lists or dicts, it should given to the beempy command through a json file:

beempy customjson -a holger80 --active ssc-mainnet1 send_token.json

with the json file: send_token.json:

{
    "contractName": "tokens",
    "contractAction":"transfer",
    "contractPayload":{
        "symbol":"DRAGON",
        "to":"beembot",
        "quantity":0.01,
        "memo":"Test"
    }
}

Results

image.png
It worked and the balance has changed:
image.png

Commits

Add new beempy command customjson

  • commit ec75681
  • with beempy customjson sending of custom_json operation is easily possible
  • Changelog adapted to 0.20.19

Broadcast custom_json with active authority

  • commit 360f3e7
  • custom_json with required_auths are now broadcasted with active key
  • json field in custom_json is broadcasted compact (spaces are removed)

Improve derive_permlink and allow replies of comments with permlink lenght > 235

  • commit ba294ec
  • derive_permlink was improved so that replys to posts/comments with a permlink length of more than 235 characters is possible
  • unit tests added

Github account

https://github.com/holgern

Sort:  
Loading...

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

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

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!

Hi, @holger80!

You just got a 3.09% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

This post has been included in the latest edition of SoS Daily News - a digest of all you need to know about the State of Steem.