def update_account_profile(self, profile, account=None): """ Update an account's meta data (json_meta) :param dict json: The meta data to use (i.e. use Profile() from account.py) :param str account: (optional) the account to allow access to (defaults to ``default_account``) """ if not account: account = configStorage.get("default_account") if not account: raise ValueError("You need to provide an account") account = Account(account, steemd_instance=self.steemd) op = operations.AccountUpdate( **{ "account": account["name"], "memo_key": account["memo_key"], "json_metadata": profile }) return self.finalizeOp(op, account["name"], "active")
def update_account(): with open("config_update_account.json", 'r') as load_f: input_args = json.load(load_f) for i in range(len(input_args)): args = input_args[i] key = args['key'] update_account_object = args['update_account'] account_name = update_account_object['account'] steem = Steem(nodes=nodes_remote, keys=key) # now we can construct the transaction # we will set no_broadcast to True because # we don't want to really send funds, just testing. tb = TransactionBuilder() # lets serialize our transfers into a format Steem can understand operationsList = [] operationsList.append( operations.AccountUpdate(**update_account_object)) # tell TransactionBuilder to use our serialized transfers tb.appendOps(operationsList) # we need to tell TransactionBuilder about # everyone who needs to sign the transaction. # since all payments are made from `richguy`, # we just need to do this once tb.appendSigner(account_name, 'owner') # sign the transaction tb.sign() # broadcast the transaction (publish to steem) # since we specified no_broadcast=True earlier # this method won't actually do anything tx = tb.broadcast() print(account_name + " done")
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: account = configStorage.get("default_account") if not account: raise ValueError("You need to provide an account") PublicKey(key) # raises exception if invalid account = Account(account, steemd_instance=self.steemd) op = operations.AccountUpdate( **{ "account": account["name"], "memo_key": key, "json_metadata": account["json_metadata"] }) return self.finalizeOp(op, account["name"], "active")
def test_account_update(self): op = operations.AccountUpdate( **{ "account": "streemian", "posting": { "weight_threshold": 1, "account_auths": [["xeroc", 1], ["fabian", 1]], "key_auths": [[ "STM6KChDK2sns9MwugxkoRvPEnyjuTxHN5upGsZ1EtanCffqBVVX3", 1 ], [ "STM7sw22HqsXbz7D2CmJfmMwt9rimtk518dRzsR1f8Cgw52dQR1pR", 1 ]] }, "owner": { "weight_threshold": 1, "account_auths": [], "key_auths": [[ "STM7sw22HqsXbz7D2CmJfmMwt9rimtk518dRzsR1f8Cgw52dQR1pR", 1 ], [ "STM6KChDK2sns9MwugxkoRvPEnyjuTxHN5upGsZ1EtanCffqBVVX3", 1 ]] }, "active": { "weight_threshold": 2, "account_auths": [], "key_auths": [[ "STM6KChDK2sns9MwugxkoRvPEnyjuTxHN5upGsZ1EtanCffqBVVX3", 1 ], [ "STM7sw22HqsXbz7D2CmJfmMwt9rimtk518dRzsR1f8Cgw52dQR1pR", 1 ]] }, "memo_key": "STM728uLvStTeAkYJsQefks3FX8yfmpFHp8wXw3RY3kwey2JGDooR", "json_metadata": "" }) ops = [operations.Operation(op)] tx = SignedTransaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=self.steem.chain_params) tx_wire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c80457010a0973747265656d69616e01010000" "00000202bbcf38855c9ae9d55704ee50ff56552af1242266c105" "44a75b61005e17fa78a601000389d28937022880a7f0c7deaa6f" "46b4d87ce08bd5149335cb39b5a8e9b04981c201000102000000" "000202bbcf38855c9ae9d55704ee50ff56552af1242266c10544" "a75b61005e17fa78a601000389d28937022880a7f0c7deaa6f46" "b4d87ce08bd5149335cb39b5a8e9b04981c20100010100000002" "0666616269616e0100057865726f6301000202bbcf38855c9ae9" "d55704ee50ff56552af1242266c10544a75b61005e17fa78a601" "000389d28937022880a7f0c7deaa6f46b4d87ce08bd5149335cb" "39b5a8e9b04981c201000318c1ae46b3e98b26684c87737a04ec" "b1a390efdc7671ced448a92b745372deff000001206a8896c0ce" "0c949d901c44232694252348004cf9a74ec2f391c0e0b7a4108e" "7f71522c186a92c17e23a07cdb108a745b9760316daf16f20434" "53fbeccb331067") self.assertEqual(compare[:-130], tx_wire[:-130])
], "account_auths": [], "weight_threshold": 1 }, "active": { "key_auths": [ [new_public_keys["active"], 1] ], "account_auths": [], "weight_threshold": 1 }, "posting": { "key_auths": [ [new_public_keys["posting"], 1] ], "account_auths": [], "weight_threshold": 1 }, "memo_key": new_public_keys["memo"] } print("New data:") print(new_data) op = operations.AccountUpdate(**new_data) result = client.commit.finalizeOp(op, account, "owner") print("Result:") print(result)
def disallow(self, foreign, permission="posting", 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 ``posting``) :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: account = configStorage.get("default_account") if not account: raise ValueError("You need to provide an account") if permission not in ["owner", "posting", "active"]: raise ValueError( "Permission needs to be either 'owner', 'posting', or 'active") account = Account(account, steemd_instance=self.steemd) authority = account[permission] try: pubkey = PublicKey(foreign, prefix=self.steemd.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: # noqa FIXME(sneak) try: foreign_account = Account(foreign, steemd_instance=self.steemd) affected_items = list( filter(lambda x: x[0] == foreign_account["name"], authority["account_auths"])) authority["account_auths"] = list( filter(lambda x: x[0] != foreign_account["name"], authority["account_auths"])) except: # noqa FIXME(sneak) 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: # noqa FIXME(sneak) 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.AccountUpdate( **{ "account": account["name"], permission: authority, "memo_key": account["memo_key"], "json_metadata": account["json_metadata"] }) 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="posting", 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 ``posting``) :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: account = configStorage.get("default_account") if not account: raise ValueError("You need to provide an account") if permission not in ["owner", "posting", "active"]: raise ValueError( "Permission needs to be either 'owner', 'posting', or 'active") account = Account(account, steemd_instance=self.steemd) if not weight: weight = account[permission]["weight_threshold"] authority = account[permission] try: pubkey = PublicKey(foreign) authority["key_auths"].append([str(pubkey), weight]) except: # noqa FIXME(sneak) try: foreign_account = Account(foreign, steemd_instance=self.steemd) authority["account_auths"].append( [foreign_account["name"], weight]) except: # noqa FIXME(sneak) raise ValueError( "Unknown foreign account or unvalid public key") if threshold: authority["weight_threshold"] = threshold self._test_weights_treshold(authority) op = operations.AccountUpdate( **{ "account": account["name"], permission: authority, "memo_key": account["memo_key"], "json_metadata": account["json_metadata"], 'prefix': self.steemd.chain_params["prefix"] }) if permission == "owner": return self.finalizeOp(op, account["name"], "owner") else: return self.finalizeOp(op, account["name"], "active")