create account

Python scripts to test SPS by emrebeyler

View this thread on: hive.blogpeakd.comecency.com
· @emrebeyler · (edited)
$2.79
Python scripts to test SPS
Have been testing the SPS for a couple of hours. Ended up re-using some of the functions to simplify calls. This stupid set of Python functions covers the new operations and RPC calls related to SPS. 

Beware, the initial documentation on blocktrades' wiki page is outdated. You may need to skim the source code to learn about the parameters. (Or you can ask in the comments.)

```
from lightsteem.client import Client

from lightsteem.helpers.amount import Amount
from lightsteem.datastructures import Operation
import json

USER = ('emrebeyler', '<active_key>')
NODE = 'https://testnet.steemitdev.com/'

# monkey patch Amount class
Amount.ASSETS.update({
    "TBD": {
        "nai": "@@000000013",
        "precision": 3
    }
})


def create_proposal(c):

    # Assuming the USER[0] has a Comment with relevant permlink
    op = Operation('create_proposal', {
        "creator": USER[0],
        "receiver": USER[0],
        "start_date": "2019-11-01T00:00:00",
        "end_date": "2019-12-01T00:00:00",
        "daily_pay": "10.000 TBD",
        "subject": "Remove delegation ability from STEEM blockchain",
        "permlink": "remove-delegations"
    })
    c.broadcast(op)
    print("proposal created")


def vote_proposal(c, proposal_id):
    op = Operation('update_proposal_votes', {
        'voter': 'emrebeyler',
        'proposal_ids': [proposal_id, ],
        'approve': True,
    })
    c.broadcast(op)
    print("vote proposal casted")


def create_post(c):
    post = Operation('comment', {
        "parent_author": None,
        "parent_permlink": "sps",
        "author": "emrebeyler",
        "permlink": "remove-delegations",
        "title": "Removing delegation ability",
        "body": "This is a proposal to remove delegation ability with a daily pay of 10 TBD.",
        "json_metadata": json.dumps({"tags": "steemit steem delegations"})
    })

    c.broadcast(post)
    print("post created")


def list_proposals(c):
    return c('condenser_api').list_proposals(
        ["emrebeyler"],
        10,
        "by_creator",
        "ascending",
        "all"
    )


def find_proposals(c, ids):
    return c('condenser_api').find_proposals(ids)


def list_proposal_votes(c, proposal_id):
    return c('condenser_api').list_proposal_votes(
        [proposal_id],
        10,
        "by_proposal_voter",
        "ascending",
        "all"
    )


if __name__ == '__main__':
    c = Client(
        nodes=[NODE, ],
        keys=[USER[1]],
        chain=dict(
            chain_id="46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32",
            prefix="TST",
        ),
    )


    # create_post(c)
    # create_proposal(c)
    # print(vote_proposal(c, 7))
    # print(list_proposals(c))
    # print(find_proposals(c, [1, 3, 5]))
    # print(list_proposal_votes(c, 7))
```
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 113 others
properties (23)
authoremrebeyler
permlinkpython-scripts-to-test-sps
categorylightsteem
json_metadata{"community":"busy","app":"palnet/0.1","format":"markdown","tags":["lightsteem","python","development","hf","palnet"]}
created2019-07-11 21:34:00
last_update2019-07-11 22:19:51
depth0
children2
last_payout2019-07-18 21:34:00
cashout_time1969-12-31 23:59:59
total_payout_value2.240 HBD
curator_payout_value0.547 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,811
author_reputation448,528,959,341,273
root_title"Python scripts to test SPS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id88,173,202
net_rshares8,470,685,495,401
author_curate_reward""
vote details (177)
@abh12345 ·
Thanks for taking the time to do what many of us cannot Emre :)
👍  
properties (23)
authorabh12345
permlinkpui0cn
categorylightsteem
json_metadata{"tags":["lightsteem"],"app":"steemit/0.1"}
created2019-07-11 22:12:24
last_update2019-07-11 22:12:24
depth1
children1
last_payout2019-07-18 22:12:24
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_length63
author_reputation1,401,181,767,850,181
root_title"Python scripts to test SPS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id88,174,139
net_rshares49,197,589,305
author_curate_reward""
vote details (1)
@emrebeyler ·
💪 No thanks needed. This is fun for me :-)
👍  
properties (23)
authoremrebeyler
permlinkpulm6o
categorylightsteem
json_metadata{"tags":["lightsteem"],"app":"steemit/0.1"}
created2019-07-13 20:56:48
last_update2019-07-13 20:56:48
depth2
children0
last_payout2019-07-20 20:56:48
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_length42
author_reputation448,528,959,341,273
root_title"Python scripts to test SPS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id88,258,026
net_rshares3,206,926,626
author_curate_reward""
vote details (1)