Skip to content

Commit

Permalink
[Example] more example scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Oct 19, 2016
1 parent 9558561 commit 80ad624
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/claim_withdraw_permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from grapheneapi.grapheneclient import GrapheneClient
from pprint import pprint


class Config():
wallet_host = "localhost"
wallet_port = 8092
witness_url = "ws://testnet.bitshares.eu/ws"
broadcast = True


def claim_from_withdraw_permission(rpc,
withdraw_permission,
amount_to_withdraw,
asset_to_widthdraw,
withdraw_from_account,
withdraw_to_account,
broadcast=True):

op = rpc.get_prototype_operation("withdraw_permission_claim_operation")
withdraw_from_account = rpc.get_account(withdraw_from_account)
withdraw_to_account = rpc.get_account(withdraw_to_account)
op[1]['amount_to_withdraw'] = {'amount': int(amount_to_withdraw * 10 ** rpc.get_asset(asset_to_widthdraw)["precision"]),
'asset_id': rpc.get_asset(asset_to_widthdraw)["id"]}
op[1]['withdraw_permission'] = withdraw_permission
op[1]['withdraw_from_account'] = withdraw_from_account["id"]
op[1]['withdraw_to_account'] = withdraw_to_account["id"]
buildHandle = rpc.begin_builder_transaction()
rpc.add_operation_to_builder_transaction(buildHandle, op)
rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
return rpc.sign_builder_transaction(buildHandle, broadcast)

if __name__ == '__main__':

asset_to_widthdraw = "PEG.FAKEUSD"
amount_to_withdraw = 100
withdraw_permission = "1.12.0"
withdraw_from_account = "maker"
withdraw_to_account = "xeroc"

client = GrapheneClient(Config)
tx = claim_from_withdraw_permission(client.rpc, withdraw_permission, amount_to_withdraw, asset_to_widthdraw, withdraw_from_account, withdraw_to_account)
pprint(tx)
66 changes: 66 additions & 0 deletions examples/create_vesting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from grapheneapi.grapheneclient import GrapheneClient
from pprint import pprint
from datetime import datetime
import time


class Config():
wallet_host = "localhost"
wallet_port = 8092
witness_url = "ws://testnet.bitshares.eu/ws"
broadcast = True


def formatTimeFromNow(secs=0):
""" Properly Format Time that is `x` seconds in the future
:param int secs: Seconds to go in the future (`x>0`) or the
past (`x<0`)
:return: Properly formated time for Graphene (`%Y-%m-%dT%H:%M:%S`)
:rtype: str
"""
return datetime.utcfromtimestamp(
time.time() + int(secs)).strftime('%Y-%m-%dT%H:%M:%S')

if __name__ == '__main__':

creator = "xeroc"
owner = "maker"
amount = 15
amount_asset = "PEG.FAKEUSD"
zero_date = datetime.utcfromtimestamp(0).strftime('%Y-%m-%dT%H:%M:%S')

policy = [1, {"vesting_seconds": 60 * 5, # vesting period
"start_claim": formatTimeFromNow(10)
}]

# policy = [ 0, { # This is the time at which funds begin vesting
# "begin_timestamp": formatTimeFromNow(60),
# # No amount may be withdrawn before this many seconds
# # of the vesting period have elapsed
# "vesting_cliff_seconds": 10,
# # Duration of the vesting period, in seconds. Must be
# # greater than 0 and greater than vesting_cliff_seconds.
# "vesting_duration_seconds": 60 * 60 * 5
# }
# ]

client = GrapheneClient(Config)
op = client.rpc.get_prototype_operation("vesting_balance_create_operation")
creator = client.rpc.get_account(creator)
owner = client.rpc.get_account(owner)
asset = client.rpc.get_asset(amount_asset)
op[1]['creator'] = creator["id"]
op[1]['owner'] = owner["id"]
op[1]['amount']["amount"] = int(amount * 10 ** asset["precision"])
op[1]['amount']["asset_id"] = asset["id"]
op[1]['policy'] = policy
ops = [op]
buildHandle = client.rpc.begin_builder_transaction()
for op in ops:
pprint(op)
client.rpc.add_operation_to_builder_transaction(buildHandle, op)
client.rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
tx = client.rpc.sign_builder_transaction(buildHandle, Config.broadcast)
pprint(tx)
51 changes: 51 additions & 0 deletions examples/propose_asset_whitelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from grapheneapi.grapheneclient import GrapheneClient
from pprint import pprint


def formatTimeFromNow(secs=0):
from datetime import datetime
import time
""" Properly Format Time that is `x` seconds in the future
:param int secs: Seconds to go in the future (`x>0`) or the
past (`x<0`)
:return: Properly formated time for Graphene (`%Y-%m-%dT%H:%M:%S`)
:rtype: str
"""
return datetime.utcfromtimestamp(time.time() + int(secs)).strftime('%Y-%m-%dT%H:%M:%S')


class Config():
wallet_host = "localhost"
wallet_port = 8092
broadcast = True


if __name__ == '__main__':
expiration = formatTimeFromNow(60 * 60 * 24)
proposer = "fabian"
asset = "TMP"
whitelist_accounts = ["tmp-asset-issuer"]

client = GrapheneClient(Config)
asset = client.rpc.get_asset(asset)

op = client.rpc.get_prototype_operation("asset_update_operation")
op[1]["asset_to_update"] = asset["id"]
op[1]["issuer"] = asset["issuer"]
op[1]["new_options"] = asset["options"]

whitelist_authorities = []
for a in whitelist_accounts:
ac = client.rpc.get_account(a)
whitelist_authorities.append(ac["id"])
op[1]["new_options"]["whitelist_authorities"] = whitelist_authorities

buildHandle = client.rpc.begin_builder_transaction()
client.rpc.add_operation_to_builder_transaction(buildHandle, op)
client.rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
client.rpc.propose_builder_transaction2(buildHandle, proposer, expiration, 0, False)
client.rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
tx = client.rpc.sign_builder_transaction(buildHandle, True)
pprint(tx)
35 changes: 35 additions & 0 deletions examples/setup_asset_whitelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from grapheneapi.grapheneclient import GrapheneClient
from pprint import pprint


class Config():
wallet_host = "localhost"
wallet_port = 8092
witness_url = "wss://bitshares.openledger.info/ws"
broadcast = True


if __name__ == '__main__':

asset = "TMPASSET"
whitelist_accounts = ["null", "committee-account"]

client = GrapheneClient(Config)
asset = client.rpc.get_asset(asset)

op = client.rpc.get_prototype_operation("asset_update_operation")
op[1]["asset_to_update"] = asset["id"]
op[1]["issuer"] = asset["issuer"]
op[1]["new_options"] = asset["options"]

whitelist_authorities = []
for a in whitelist_accounts:
ac = client.rpc.get_account(a)
whitelist_authorities.append(ac["id"])

op[1]["new_options"]["whitelist_authorities"] = whitelist_authorities
buildHandle = client.rpc.begin_builder_transaction()
client.rpc.add_operation_to_builder_transaction(buildHandle, op)
client.rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
tx = client.rpc.sign_builder_transaction(buildHandle, Config.broadcast)
pprint(tx)
53 changes: 53 additions & 0 deletions examples/setup_withdraw_permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from grapheneapi.grapheneclient import GrapheneClient
from pprint import pprint


class Config():
wallet_host = "localhost"
wallet_port = 8092
witness_url = "ws://testnet.bitshares.eu/ws"
broadcast = True


def formatTimeFromNow(secs=0):
from datetime import datetime
import time
""" Properly Format Time that is `x` seconds in the future
:param int secs: Seconds to go in the future (`x>0`) or the
past (`x<0`)
:return: Properly formated time for Graphene (`%Y-%m-%dT%H:%M:%S`)
:rtype: str
"""
return datetime.utcfromtimestamp(time.time() + int(secs)).strftime('%Y-%m-%dT%H:%M:%S')

if __name__ == '__main__':

authorized_account = "xeroc"
withdraw_from_account = "maker"
period_start_time = formatTimeFromNow(+60)
withdrawal_period_sec = 60 * 60 * 24 * 30
periods_until_expiration = 12 * 15
withdrawal_limit_asset = "PEG.FAKEUSD"
withdrawal_limit_amount = 100

client = GrapheneClient(Config)
op = client.rpc.get_prototype_operation("withdraw_permission_create_operation")
authorized_account = client.rpc.get_account(authorized_account)
withdraw_from_account = client.rpc.get_account(withdraw_from_account)
op[1]['authorized_account'] = authorized_account["id"]
op[1]['period_start_time'] = period_start_time
op[1]['withdrawal_period_sec'] = withdrawal_period_sec
op[1]['periods_until_expiration'] = periods_until_expiration
op[1]['withdraw_from_account'] = withdraw_from_account["id"]
op[1]['withdrawal_limit'] = {'amount': int(withdrawal_limit_amount * 10 ** client.rpc.get_asset(withdrawal_limit_asset)["precision"]),
'asset_id': client.rpc.get_asset(withdrawal_limit_asset)["id"]}
ops = [op]
buildHandle = client.rpc.begin_builder_transaction()
for op in ops :
pprint(op)
client.rpc.add_operation_to_builder_transaction(buildHandle, op)
client.rpc.set_fees_on_builder_transaction(buildHandle, "1.3.0")
tx = client.rpc.sign_builder_transaction(buildHandle, Config.broadcast)
pprint(tx)

0 comments on commit 80ad624

Please sign in to comment.