def approveworker(self, workers, account=None): """ Approve a worker :param list workers: list of worker 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, bitshares_instance=self) options = account["options"] if not isinstance(workers, (list, set)): workers = set(workers) for worker in workers: worker = Worker(worker, bitshares_instance=self) options["votes"].append(worker["vote_for"]) options["votes"] = list(set(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 update_memo_key(self, key, account=None): """ Update an account's memo public key This method does **not** add any private keys to your wallet but merely changes the memo public key. :param str key: New memo public key :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") PublicKey(key, prefix=self.rpc.chain_params["prefix"]) account = Account(account, bitshares_instance=self) account["options"]["memo_key"] = key op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], "new_options": account["options"], "extensions": {} }) return self.finalizeOp(op, account["name"], "active")
def test_update_account(self): op = operations.Account_update( **{ "fee": { "amount": 1467634, "asset_id": "1.3.0" }, "account": "1.2.15", "owner": { "weight_threshold": 1, "account_auths": [["1.2.96086", 1]], 'key_auths': [[ 'BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1 ]], "address_auths": [] }, "active": { "weight_threshold": 1, "account_auths": [["1.2.96086", 1]], 'key_auths': [[ 'BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7', 1 ]], "address_auths": [] }, "new_options": { "memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", "voting_account": "1.2.5", "num_witness": 0, "num_committee": 0, "votes": [], "extensions": [] }, "extensions": {} }) ops = [Operation(op)] tx = Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c804570106f264160000000000000" "f010100000001d6ee0501000102fe8cc11cc8251de6" "977636b55c1ab8a9d12b0b26154ac78e56e7c4257d8" "bcf69010000010100000001d6ee0501000103b453f4" "6013fdbccb90b09ba169c388c34d84454a3b9fbec68" "d5a7819a734fca001000001024ab336b4b14ba6d881" "675d1c782912783c43dbbe31693aa710ac1896bd7c3" "d61050000000000000000011f78b989df5ab29697a3" "311f8d7fa8599c548a93809e173ab550b7d8c5051fa" "432699d8e24ea82399990c43528ddaf2b3cd8cd2500" "1c91f8094d66ae2620effc25") self.assertEqual(compare[:-130], txWire[:-130])
def update_active_key(inst, key, account=None, **kwargs): btsAccount.PublicKey(key, prefix='CYB') account = cybex.Account(account) account["active"] = {'weight_threshold': 1, 'account_auths': [], 'key_auths': [[key, 1]], 'address_auths': []} op = operations.Account_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "account": account["id"], "active": account["active"], "extensions": {} }) return inst.finalizeOp(op, account["name"], "active", **kwargs)
def test_update_account(self): self.op = operations.Account_update( **{ "fee": { "amount": 1467634, "asset_id": "1.3.0" }, "account": "1.2.15", "owner": { "weight_threshold": 1, "account_auths": [["1.2.96086", 1]], "key_auths": [[ "BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x", 1 ]], "address_auths": [], }, "active": { "weight_threshold": 1, "account_auths": [["1.2.96086", 1]], "key_auths": [[ "BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7", 1 ]], "address_auths": [], }, "new_options": { "memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", "voting_account": "1.2.5", "num_witness": 0, "num_committee": 0, "votes": [], "extensions": [], }, "extensions": {}, "prefix": "BTS", }) self.cm = ("f68585abf4dce7c804570106f264160000000000000" "f010100000001d6ee0501000102fe8cc11cc8251de6" "977636b55c1ab8a9d12b0b26154ac78e56e7c4257d8" "bcf69010000010100000001d6ee0501000103b453f4" "6013fdbccb90b09ba169c388c34d84454a3b9fbec68" "d5a7819a734fca001000001024ab336b4b14ba6d881" "675d1c782912783c43dbbe31693aa710ac1896bd7c3" "d61050000000000000000011f78b989df5ab29697a3" "311f8d7fa8599c548a93809e173ab550b7d8c5051fa" "432699d8e24ea82399990c43528ddaf2b3cd8cd2500" "1c91f8094d66ae2620effc25") self.doit()
def update_active_keys(inst, obj, account=None, **kwargs): # for testing multi-Sig # need fee to update active keys fee = inst.fee[6]['fee']['fee']/100000 inst.transfer(account, fee, 'CYB', '', 'nathan') account = cybex.Account(account) account["active"] = obj op = operations.Account_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "account": account["id"], "active": account["active"], "extensions": {} }) return inst.finalizeOp(op, account["name"], "active", **kwargs)
def main(ctx, password, broadcast, account_name): """Use this script to change account keys. By default, a random will be generated. By default, transaction will not be broadcasted (dry-run mode). """ account = Account(account_name, bitshares_instance=ctx.bitshares) # random password if not password: password = generate_password() print('password: {}\n'.format(password)) key = get_keys_from_password(account_name, password, ctx.bitshares.prefix) # prepare for json format account['options']['memo_key'] = key['memo'] owner_key_authority = [(key['owner'], 1)] active_key_authority = [(key['active'], 1)] owner_accounts_authority: List[Tuple[str, int]] = [] active_accounts_authority: List[Tuple[str, int]] = [] pre_op = { 'account': account['id'], 'new_options': account['options'], 'owner': {'account_auths': owner_accounts_authority, 'key_auths': owner_key_authority, 'weight_threshold': 1}, 'active': { 'account_auths': active_accounts_authority, 'key_auths': active_key_authority, 'weight_threshold': 1, }, 'fee': {'amount': 0, 'asset_id': '1.3.0'}, 'extensions': {}, 'prefix': ctx.bitshares.prefix, } op = operations.Account_update(**pre_op) ctx.log.debug(pformat(op.json())) if not broadcast: ctx.log.info('Not broadcasting!') sys.exit(0) try: ctx.bitshares.finalizeOp(op, account_name, 'owner') except MissingKeyError: ctx.log.critical('No key for {} in storage, use `uptick addkey` to add'.format(account_name)) sys.exit(1)
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, bitshares_instance=self) options = account["options"] if not isinstance(committees, (list, set)): committees = set(committees) for committee in committees: committee = Committee(committee, bitshares_instance=self) 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 approvewitness(self, witnesses, account=None): """ Approve a witness :param list witnesses: list of Witness 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, bitshares_instance=self) options = account["options"] if not isinstance(witnesses, (list, set)): witnesses = set(witnesses) for witness in witnesses: witness = Witness(witness, bitshares_instance=self) options["votes"].append(witness["vote_id"]) options["votes"] = list(set(options["votes"])) options["num_witness"] = len( list( filter(lambda x: float(x.split(":")[0]) == 1, 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 main(debug, config, wallet_password, password, broadcast, account_name): """ Use this script to change account keys. By default, a random will be generated. By default, transaction will not be broadcasted (dry-run mode). """ # create logger if debug == True: log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) handler = logging.StreamHandler() formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s") handler.setFormatter(formatter) log.addHandler(handler) # parse config conf = yaml.safe_load(config) b = not broadcast bitshares = BitShares(node=conf['node_bts'], nobroadcast=b) account = Account(account_name, bitshares_instance=bitshares) # Wallet unlock try: bitshares.unlock(wallet_password) except WrongMasterPasswordException: log.critical('Wrong wallet password provided') sys.exit(1) # random password if password: password = password else: password = generate_password() print('password: {}\n'.format(password)) key = dict() for key_type in key_types: # PasswordKey object k = PasswordKey(account_name, password, role=key_type) privkey = k.get_private_key() print('{} private: {}'.format(key_type, str(privkey))) # we need explicit str() conversion! # pubkey with default prefix GPH pubkey = k.get_public_key() # pubkey with correct prefix key[key_type] = format(pubkey, bitshares.prefix) print('{} public: {}\n'.format(key_type, key[key_type])) # prepare for json format account['options']['memo_key'] = key['memo'] owner_key_authority = [[key['owner'], 1]] active_key_authority = [[key['active'], 1]] owner_accounts_authority = [] active_accounts_authority = [] posting_accounts_authority = [] s = { 'account': account['id'], 'new_options': account['options'], 'owner': {'account_auths': owner_accounts_authority, 'key_auths': owner_key_authority, 'weight_threshold': 1}, 'active': { 'account_auths': active_accounts_authority, 'key_auths': active_key_authority, 'weight_threshold': 1, }, 'fee': {'amount': 0, 'asset_id': '1.3.0'}, 'extensions': {}, 'prefix': bitshares.prefix, } # pprint(s) op = operations.Account_update(**s) try: bitshares.finalizeOp(op, account_name, 'owner') except MissingKeyError: log.critical('No key for {} in storage, use `uptick addkey` to add'.format(account_name)) sys.exit(1)
def disallow(self, foreign, permission="active", account=None, threshold=None): """ Remove additional access to an account by some other public key or account. :param str foreign: The foreign account that will obtain access :param str permission: (optional) The actual permission to modify (defaults to ``active``) :param str account: (optional) the account to allow access to (defaults to ``default_account``) :param int threshold: The threshold that needs to be reached by signatures to be able to interact """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") if permission not in ["owner", "active"]: raise ValueError( "Permission needs to be either 'owner', or 'active") account = Account(account, bitshares_instance=self) authority = account[permission] try: pubkey = PublicKey(foreign, prefix=self.rpc.chain_params["prefix"]) affected_items = list( filter(lambda x: x[0] == str(pubkey), authority["key_auths"])) authority["key_auths"] = list( filter(lambda x: x[0] != str(pubkey), authority["key_auths"])) except: try: foreign_account = Account(foreign, bitshares_instance=self) affected_items = list( filter(lambda x: x[0] == foreign_account["id"], authority["account_auths"])) authority["account_auths"] = list( filter(lambda x: x[0] != foreign_account["id"], authority["account_auths"])) except: raise ValueError( "Unknown foreign account or unvalid public key") removed_weight = affected_items[0][1] # Define threshold if threshold: authority["weight_threshold"] = threshold # Correct threshold (at most by the amount removed from the # authority) try: self._test_weights_treshold(authority) except: log.critical("The account's threshold will be reduced by %d" % (removed_weight)) authority["weight_threshold"] -= removed_weight self._test_weights_treshold(authority) op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], permission: authority, "extensions": {} }) if permission == "owner": return self.finalizeOp(op, account["name"], "owner") else: return self.finalizeOp(op, account["name"], "active")
def allow(self, foreign, weight=None, permission="active", account=None, threshold=None): """ Give additional access to an account by some other public key or account. :param str foreign: The foreign account that will obtain access :param int weight: (optional) The weight to use. If not define, the threshold will be used. If the weight is smaller than the threshold, additional signatures will be required. (defaults to threshold) :param str permission: (optional) The actual permission to modify (defaults to ``active``) :param str account: (optional) the account to allow access to (defaults to ``default_account``) :param int threshold: The threshold that needs to be reached by signatures to be able to interact """ from copy import deepcopy if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") if permission not in ["owner", "active"]: raise ValueError( "Permission needs to be either 'owner', or 'active") account = Account(account, bitshares_instance=self) if not weight: weight = account[permission]["weight_threshold"] authority = deepcopy(account[permission]) try: pubkey = PublicKey(foreign, prefix=self.rpc.chain_params["prefix"]) authority["key_auths"].append([str(pubkey), weight]) except: try: foreign_account = Account(foreign, bitshares_instance=self) authority["account_auths"].append( [foreign_account["id"], weight]) except: raise ValueError( "Unknown foreign account or invalid public key") if threshold: authority["weight_threshold"] = threshold self._test_weights_treshold(authority) op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], permission: authority, "extensions": {}, "prefix": self.rpc.chain_params["prefix"] }) if permission == "owner": return self.finalizeOp(op, account["name"], "owner") else: return self.finalizeOp(op, account["name"], "active")