Skip to content
Snippets Groups Projects
Commit b2252da1 authored by Fabian Schuh's avatar Fabian Schuh
Browse files

[committee] approve/disapprove committe members

parent 93a8b755
No related branches found
No related tags found
No related merge requests found
...@@ -13,5 +13,6 @@ __all__ = [ ...@@ -13,5 +13,6 @@ __all__ = [
"storage", "storage",
"price", "price",
"utils", "utils",
"wallet" "wallet",
"committee"
] ]
...@@ -11,6 +11,7 @@ from .asset import Asset ...@@ -11,6 +11,7 @@ from .asset import Asset
from .account import Account from .account import Account
from .amount import Amount from .amount import Amount
from .witness import Witness from .witness import Witness
from .committee import Committee
from .storage import configStorage as config from .storage import configStorage as config
from .exceptions import ( from .exceptions import (
AccountExistsException, AccountExistsException,
...@@ -402,7 +403,7 @@ class BitShares(object): ...@@ -402,7 +403,7 @@ class BitShares(object):
def _test_weights_treshold(self, authority): def _test_weights_treshold(self, authority):
""" This method raises an error if the threshold of an authority cannot """ This method raises an error if the threshold of an authority cannot
be reached by the weights. be reached by the weights.
:param dict authority: An authority of an account :param dict authority: An authority of an account
:raises ValueError: if the threshold is set too high :raises ValueError: if the threshold is set too high
""" """
...@@ -591,7 +592,7 @@ class BitShares(object): ...@@ -591,7 +592,7 @@ class BitShares(object):
def approvewitness(self, witnesses, account=None): def approvewitness(self, witnesses, account=None):
""" Approve a witness """ Approve a witness
:param str witnesses: (list of) Witness name or id :param list witnesses: list of Witness name or id
:param str account: (optional) the account to allow access :param str account: (optional) the account to allow access
to (defaults to ``default_account``) to (defaults to ``default_account``)
""" """
...@@ -625,7 +626,7 @@ class BitShares(object): ...@@ -625,7 +626,7 @@ class BitShares(object):
def disapprovewitness(self, witnesses, account=None): def disapprovewitness(self, witnesses, account=None):
""" Disapprove a witness """ Disapprove a witness
:param str witnesses: (list of) Witness name or id :param list witnesses: list of Witness name or id
:param str account: (optional) the account to allow access :param str account: (optional) the account to allow access
to (defaults to ``default_account``) to (defaults to ``default_account``)
""" """
...@@ -657,6 +658,75 @@ class BitShares(object): ...@@ -657,6 +658,75 @@ class BitShares(object):
}) })
return self.finalizeOp(op, account["name"], "active") return self.finalizeOp(op, account["name"], "active")
def approvecommittee(self, committees, account=None):
""" Approve a committee
:param list committees: list of committee member name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in config:
account = config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account)
options = account["options"]
for committee in committees:
committee = Committee(committee)
options["votes"].append(committee["vote_id"])
options["votes"] = list(set(options["votes"]))
options["num_committee"] = len(list(filter(
lambda x: float(x.split(":")[0]) == 0,
options["votes"]
)))
op = operations.Account_update(**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.rpc.chain_params["prefix"]
})
return self.finalizeOp(op, account["name"], "active")
def disapprovecommittee(self, committees, account=None):
""" Disapprove a committee
:param list committees: list of committee name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in config:
account = config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account)
options = account["options"]
for committee in committees:
committee = Committee(committee)
if committee["vote_id"] in options["votes"]:
options["votes"].remove(committee["vote_id"])
options["votes"] = list(set(options["votes"]))
options["num_committee"] = len(list(filter(
lambda x: float(x.split(":")[0]) == 0,
options["votes"]
)))
op = operations.Account_update(**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.rpc.chain_params["prefix"]
})
return self.finalizeOp(op, account["name"], "active")
def cancel(self, orderNumber, account=None): def cancel(self, orderNumber, account=None):
""" Cancels an order you have placed in a given market. Requires """ Cancels an order you have placed in a given market. Requires
only the "orderNumber". An order number takes the form only the "orderNumber". An order number takes the form
...@@ -678,6 +748,5 @@ class BitShares(object): ...@@ -678,6 +748,5 @@ class BitShares(object):
"fee": {"amount": 0, "asset_id": "1.3.0"}, "fee": {"amount": 0, "asset_id": "1.3.0"},
"fee_paying_account": account["id"], "fee_paying_account": account["id"],
"order": order, "order": order,
"extensions": [] "extensions": []}))
}))
return self.finalizeOp(op, account["name"], "active") return self.finalizeOp(op, account["name"], "active")
from bitshares.instance import shared_bitshares_instance
from .account import Account
from .exceptions import CommitteeMemberDoesNotExistsException
class Committee(dict):
""" Read data about a Committee Member in the chain
:param str member: Name of the Committee Member
:param bitshares bitshares_instance: BitShares() instance to use when accesing a RPC
:param bool lazy: Use lazy loading
"""
def __init__(
self,
member,
bitshares_instance=None,
lazy=False
):
self.cached = False
self.member = member
self.bitshares = bitshares_instance or shared_bitshares_instance()
if not lazy:
self.refresh()
def refresh(self):
account = Account(self.member)
member = self.bitshares.rpc.get_committee_member_by_account(account["id"])
if not member:
raise CommitteeMemberDoesNotExistsException
super(Committee, self).__init__(member)
self.cached = True
def __getitem__(self, key):
if not self.cached:
self.refresh()
return super(Committee, self).__getitem__(key)
def items(self):
if not self.cached:
self.refresh()
return super(Committee, self).items()
@property
def account(self):
return Account(self.member)
...@@ -64,3 +64,9 @@ class WrongMasterPasswordException(Exception): ...@@ -64,3 +64,9 @@ class WrongMasterPasswordException(Exception):
""" The password provided could not properly unlock the wallet """ The password provided could not properly unlock the wallet
""" """
pass pass
class CommitteeMemberDoesNotExistsException(Exception):
""" Committee Member does not exist
"""
pass
...@@ -42,3 +42,7 @@ class Witness(dict): ...@@ -42,3 +42,7 @@ class Witness(dict):
if not self.cached: if not self.cached:
self.refresh() self.refresh()
return super(Witness, self).items() return super(Witness, self).items()
@property
def account(self):
return Account(self.witness)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment