create account

[pybitshares/uptick] How to add new on-chain features by xeroc

View this thread on: hive.blogpeakd.comecency.com
· @xeroc ·
$162.51
[pybitshares/uptick] How to add new on-chain features
![](https://raw.githubusercontent.com/xeroc/python-bitshares/develop/docs/_static/python-bitshares-logo.png)

This post serves as a quick guide into the underlying functionality of pybitshares and uptick.

In this tutorial, we add a new feature that allows you to create a new committee member that can then be voted by BTS hodlers.

## 1. Implement operation

This step sets up a new `class` that tells the library how that particular operation is called and what it does.
The definition of those are burried deeply into bitshares-core. In this case, we take a closer look into [porotocol/committee-member.hpp](https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/include/graphene/chain/protocol/committee_member.hpp#L37-L48), identify the struct's members and add them in the same order to pybitshares:

```
   struct committee_member_create_operation : public base_operation
   {
      struct fee_parameters_type { uint64_t fee = 5000 * GRAPHENE_BLOCKCHAIN_PRECISION; };

      asset                                 fee;
      /// The account which owns the committee_member. This account pays the fee for this operation.
      account_id_type                       committee_member_account;
      string                                url;

      account_id_type fee_payer()const { return committee_member_account; }
      void            validate()const;
};
```

For python-bitshares:
```
class Committee_member_create(GrapheneObject):
    def __init__(self, *args, **kwargs):
        if isArgsThisClass(self, args):
                self.data = args[0].data
        else:
            if len(args) == 1 and len(kwargs) == 0:
                kwargs = args[0]
            super().__init__(OrderedDict([
                ('fee', Asset(kwargs["fee"])),
                ('committee_member_account', ObjectId(kwargs["committee_member_account"], "account")),
                ('url', String(kwargs["url"])),
]))
```

What is important here is that the class **name** is identical to the operations [listed here](https://github.com/xeroc/python-bitshares/blob/master/bitsharesbase/operationids.py), except that the first letter is capital.

[commit](https://github.com/xeroc/python-bitshares/commit/8a556c0031186abe3084d3e44e3dd38bbe40f0cb#diff-af90940fbf9ac565ffa6cfdce4188895)

## 2. Test operation

Now we go further and test the new operation against the cli_wallet. For that, we start a cli wallet and expose the cli_wallet's API locally at port `8092`. We then install the new operation into the `compareConstructedTX()` call [like this](https://github.com/xeroc/python-bitshares/blob/8a556c0031186abe3084d3e44e3dd38bbe40f0cb/tests/test_transactions.py#L661-L668).

When calling `python3 tests/test_transactions.py `, we now get
```
{'expiration': '2016-04-06T08:29:27',
 'extensions': [],
 'operations': [[29,
                 {'committee_member_account': '1.2.0',
                  'fee': {'amount': 0, 'asset_id': '1.3.0'},
                  'url': 'foobar'}]],
 'ref_block_num': 34294,
 'ref_block_prefix': 3707022213,
 'signatures': ['2035e1564b63c8fe55c0ba176044468ffbddffe0241792625de8365e55522f2488261ac0dd2e22aca4aeb6da48b0773837e89c4f36cfd86df1eb78119fe8a2d21e']}
================================================================================
soll: f68585abf4dce7c80457011d0000000000000000000006666f6f6261720001
ist:  f68585abf4dce7c80457011d0000000000000000000006666f6f6261720001
True
```
Which compares the serialization of cli-wallet with pybitshares.
In this case, it all looks fine and we add a unit test [like this](https://github.com/xeroc/python-bitshares/blob/8a556c0031186abe3084d3e44e3dd38bbe40f0cb/tests/test_transactions.py#L644-L657)

Since we initially don't know the output to compare with, we can use `self.doIt(True)` to let the unittest provide the string we want to compare it with later on.

We execute the unit test with

     python3 -m unittest tests.test_transactions.Testcases.test_committee_create 

The outputed string is then stored in `self.cm` so that the unittest succeeeds afterwards.

## 3. Expose the functionality in bitshares.py

We now write an API into bitshares.py to expose the feature for easier usage:

https://github.com/xeroc/python-bitshares/blob/8a556c0031186abe3084d3e44e3dd38bbe40f0cb/bitshares/bitshares.py#L1407-L1431

Here, all we do is make sure we use some account (default if not present), make sure the account exists, construct the operation and forward it for signing through `finalizeOp`. This signs it with the active key of `account` if the key is present in the wallet.

## 4. Integrate into uptick

`uptick` is a command line tool that makes heavy use of pybitshares and python-click.
using the new feature is easy as all we need to do is add a new method [like here](https://github.com/xeroc/uptick/commit/9e1801b9e12b11a11cd967ed393948cfaa2e0144)

```
@main.command()
@click.pass_context
@onlineChain
@click.argument('url', type=str)
@click.option(
    "--account",
    help="Account that takes this action",
    default=config["default_account"],
    type=str)
@unlockWallet
def createcommittee(ctx, url, account):
    """ Setup a committee account for your account
    """
    pprint(ctx.bitshares.create_committee_member(
        url,
        account=account
))
```

I hope this makes it clear how easy it is to use python bitshares and uptick.
If you decide to take on some of the missing operations, please feel free to send pull requests my way.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 91 others
👎  , ,
properties (23)
authorxeroc
permlinkpybitshares-uptick-how-to-add-new-on-chain-features
categorybitshares
json_metadata{"tags":["bitshares","python","uptick"],"image":["https://raw.githubusercontent.com/xeroc/python-bitshares/develop/docs/_static/python-bitshares-logo.png"],"links":["https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/include/graphene/chain/protocol/committee_member.hpp#L37-L48","https://github.com/xeroc/python-bitshares/blob/master/bitsharesbase/operationids.py","https://github.com/xeroc/python-bitshares/commit/8a556c0031186abe3084d3e44e3dd38bbe40f0cb#diff-af90940fbf9ac565ffa6cfdce4188895","https://github.com/xeroc/python-bitshares/blob/8a556c0031186abe3084d3e44e3dd38bbe40f0cb/tests/test_transactions.py#L661-L668","https://github.com/xeroc/python-bitshares/blob/8a556c0031186abe3084d3e44e3dd38bbe40f0cb/tests/test_transactions.py#L644-L657","https://github.com/xeroc/python-bitshares/blob/8a556c0031186abe3084d3e44e3dd38bbe40f0cb/bitshares/bitshares.py#L1407-L1431","https://github.com/xeroc/uptick/commit/9e1801b9e12b11a11cd967ed393948cfaa2e0144"],"app":"steemit/0.1","format":"markdown"}
created2018-02-20 10:23:15
last_update2018-02-20 10:23:15
depth0
children14
last_payout2018-02-27 10:23:15
cashout_time1969-12-31 23:59:59
total_payout_value135.846 HBD
curator_payout_value26.659 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,447
author_reputation118,819,064,085,695
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id39,033,344
net_rshares28,966,251,066,034
author_curate_reward""
vote details (158)
@anniversary ·
<center>![post.JPG](http://res.cloudinary.com/duvrfxmpc/image/upload/v1510241264/2-Year_py3dwj.jpg)<h1>Congratulation</h1><b>Today 2 years ago you joined SteemIt
 Thank you, for making SteemIt great and Steem on for more years to come!</b>
 (You are being celebrated  [here](/steemit/@anniversary/20180408t030020346z-celebration-post))<br/></center>
properties (22)
authoranniversary
permlink20180408t030625874z
categorybitshares
json_metadata{"tags":["comment"],"app":"steemjs/comment"}
created2018-04-08 03:06:27
last_update2018-04-08 03:06:27
depth1
children0
last_payout2018-04-15 03:06:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length351
author_reputation1,856,978,117,082
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id48,907,661
net_rshares0
@bitgeek ·
comment
Congratulations @xeroc, this post is the ninth most rewarded post (based on pending payouts) in the last 12 hours written by a Superuser account holder (accounts that hold between 1 and 10 Mega Vests). The total number of posts by Superuser account holders during this period was 1646 and the total pending payments to posts in this category was $15943.36. To see the full list of highest paid posts across all accounts categories, [click here](www.steemit.com/steemit/@bitgeek/payout-stats-report-for-20th-february-2018--part-i). 

If you do not wish to receive these messages in future, please reply stop to this comment.
properties (22)
authorbitgeek
permlinkre-pybitshares-uptick-how-to-add-new-on-chain-features-20180220t201811
categorybitshares
json_metadata""
created2018-02-20 20:18:12
last_update2018-02-20 20:18:12
depth1
children0
last_payout2018-02-27 20:18:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length624
author_reputation13,049,044,453,787
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,157,110
net_rshares0
@emrebeyler · (edited)
$0.04
> class Committee_member_create(GrapheneObject):

Is there a specific reason why pybitshares  break the python convention on class names? This should be CommitteeMemberCreate for example. :)
👍  
properties (23)
authoremrebeyler
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180222t220142840z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-02-22 22:01:42
last_update2018-02-22 22:03:51
depth1
children1
last_payout2018-03-01 22:01:42
cashout_time1969-12-31 23:59:59
total_payout_value0.043 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length190
author_reputation448,535,049,068,622
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,706,091
net_rshares8,330,532,953
author_curate_reward""
vote details (1)
@xeroc ·
Yes, the reason is that I don't want the developer to manually provide the OperationID for that operation and instead obtain it automatically from the list of operation ids by using the operation name:
https://github.com/xeroc/python-graphenelib/blob/master/graphenebase/objects.py#L19-L38
properties (22)
authorxeroc
permlinkre-emrebeyler-re-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180226t152208937z
categorybitshares
json_metadata{"tags":["bitshares"],"links":["https://github.com/xeroc/python-graphenelib/blob/master/graphenebase/objects.py#L19-L38"],"app":"steemit/0.1"}
created2018-02-26 15:22:09
last_update2018-02-26 15:22:09
depth2
children0
last_payout2018-03-05 15:22:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length289
author_reputation118,819,064,085,695
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,625,987
net_rshares0
@ethanthefighter ·
Cool stuff dude! I'm not really good with coding, I tried two different times, but hey its still really spectacular!
properties (22)
authorethanthefighter
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180307t145509432z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-03-07 14:52:51
last_update2018-03-07 14:52:51
depth1
children0
last_payout2018-03-14 14:52:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length116
author_reputation2,674,103,331,455
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,890,120
net_rshares0
@gangas ·
Hey @xeroc , this is great information to us , thanks for the enlighten.
properties (22)
authorgangas
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180220t105615257z
categorybitshares
json_metadata{"tags":["bitshares"],"users":["xeroc"],"app":"steemit/0.1"}
created2018-02-20 10:56:51
last_update2018-02-20 10:56:51
depth1
children0
last_payout2018-02-27 10:56:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length72
author_reputation-352,261,216,847
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,039,795
net_rshares0
@intelli-jan-tam ·
 brilliant &  exceptional!
properties (22)
authorintelli-jan-tam
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-1519124046008t6a535246-891c-469c-a706-09a909e09895uid
categorybitshares
json_metadata{"tags":["ilikeit"],"app":"SteemJ-Core/0.4.3","format":"markdown"}
created2018-02-20 10:54:06
last_update2018-02-20 10:54:06
depth1
children0
last_payout2018-02-27 10:54:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length26
author_reputation1,404,923,971,285
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,039,207
net_rshares0
@millerkay ·
Thanks for sharing this,  it's quite helpful
👍  
properties (23)
authormillerkay
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180220t103048664z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-02-20 10:30:57
last_update2018-02-20 10:30:57
depth1
children0
last_payout2018-02-27 10:30:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length44
author_reputation181,281,796,964
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,034,794
net_rshares197,416,634
author_curate_reward""
vote details (1)
@minhazahmed ·
thanks for the job we are waiting for your next welfare .
properties (22)
authorminhazahmed
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180220t110748704z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-02-20 11:07:54
last_update2018-02-20 11:07:54
depth1
children0
last_payout2018-02-27 11:07:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length57
author_reputation28,312,658,593
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,042,069
net_rshares0
@netuoso ·
Why are you powering up 100%??
properties (22)
authornetuoso
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180220t112529836z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-02-20 11:25:27
last_update2018-02-20 11:25:27
depth1
children1
last_payout2018-02-27 11:25:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length30
author_reputation151,901,967,807,285
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries
0.
accountsteemliberator
weight1,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,045,649
net_rshares0
@humash604 ·
Good job. Keep it up
👍  
properties (23)
authorhumash604
permlinkre-netuoso-re-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180220t113502378z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-02-20 11:35:09
last_update2018-02-20 11:35:09
depth2
children0
last_payout2018-02-27 11:35:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length20
author_reputation4,173,298,352
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,047,601
net_rshares144,530,149
author_curate_reward""
vote details (1)
@redditposh ·
https://www.reddit.com/r/BitShares/comments/1gv1ljd/pybitsharesuptick_how_to_add_new_onchain_features/
<sub> The rewards earned on this comment will go directly to the people sharing the post on Reddit as long as they are registered with @poshtoken. Sign up at https://hiveposh.com. Otherwise, rewards go to the author of the blog post.</sub>
properties (22)
authorredditposh
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-feature90974
categorybitshares
json_metadata"{"app":"Poshtoken 0.0.2","payoutToUser":[]}"
created2024-11-20 15:09:18
last_update2024-11-20 15:09:18
depth1
children0
last_payout2024-11-27 15:09:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length343
author_reputation2,203,814,399,097,741
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries
0.
accountnomnomnomnom
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id138,584,876
net_rshares0
@steemitboard ·
Congratulations @xeroc! You have received a personal award!

[![](https://steemitimages.com/70x70/http://steemitboard.com/@xeroc/birthday2.png)](http://steemitboard.com/@xeroc)  2 Years on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.

> Upvote this notificationto to help all Steemit users. Learn why [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-xeroc-20180408t144254000z
categorybitshares
json_metadata{"image":["https://steemitboard.com/img/notifications.png"]}
created2018-04-08 14:42:54
last_update2018-04-08 14:42:54
depth1
children0
last_payout2018-04-15 14:42:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length420
author_reputation38,975,615,169,260
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id48,981,053
net_rshares0
@toptensteemit ·
Great info . It is always nice to get fresh intel regarding pybitshares. Thanks
properties (22)
authortoptensteemit
permlinkre-xeroc-pybitshares-uptick-how-to-add-new-on-chain-features-20180316t012140857z
categorybitshares
json_metadata{"tags":["bitshares"],"app":"steemit/0.1"}
created2018-03-16 01:21:45
last_update2018-03-16 01:21:45
depth1
children0
last_payout2018-03-23 01:21:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length79
author_reputation29,205,060,035
root_title"[pybitshares/uptick] How to add new on-chain features"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,696,984
net_rshares0