def request_recovery(account): """ Request the recovery of ACCOUNT. This action has to be initiated/signed by the recovery partner of ACCOUNT. """ acc = Account(account.replace("@", "")) if acc.get_owner_history() == []: logger.error("The owner key of @%s was not changed within " "the last 30 days - recovering this account is " "not possible!" % (acc['name'])) return # Ask and verify the new pubkey for the to-be-recovered account new_owner_key = input("Enter new PUBLIC owner key for @%s: " % (acc['name'])) # PublicKey call to make sure it is a valid public key pk_validity_check = PublicKey(new_owner_key, prefix=acc.blockchain.prefix) if format(pk_validity_check, acc.blockchain.prefix) != new_owner_key: raise ValueError("Invalid public owner key!") # Ask and verify the active key of the recovery account recovery_ak = getpass("Enter active key, owner key or master " "password for @%s: " % (acc['recovery_account'])) recovery_ak = passwordkey_to_key(recovery_ak, acc['recovery_account'], "active", prefix=acc.blockchain.prefix) # Assemble the account recovery request operation new_owner_authority = { 'key_auths': [[new_owner_key, 1]], 'account_auths': [], 'weight_threshold': 1, 'prefix': acc.blockchain.prefix } op = operations.Request_account_recovery( **{ 'account_to_recover': acc['name'], 'recovery_account': acc['recovery_account'], 'new_owner_authority': new_owner_authority, 'extensions': [], 'prefix': acc.blockchain.prefix }) # Send the operation to the blockchain tb = TransactionBuilder(blockchain_instance=acc.steem) tb.appendOps([op]) tb.appendWif(recovery_ak) tb.sign() tx = tb.broadcast() logger.debug(tx) logger.info("@%s requested account recovery for @%s." % (acc['recovery_account'], acc['name']))
def test_transfer_1of1(self): steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem', "to": 'beem1', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '1 of 1 transaction'})) self.assertEqual( tx["operations"][0]["type"], "transfer_operation" ) tx.appendWif(self.active_key) tx.sign() tx.sign() self.assertEqual(len(tx['signatures']), 1) tx.broadcast() steem.nobroadcast = True
def test_transfer_2of2_simple(self): # Send a 2 of 2 transaction from elf which needs beem4's cosign to send funds steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem5', "to": 'beem1', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 simple transaction'})) tx.appendWif(self.active_private_key_of_beem5) tx.sign() tx.clearWifs() tx.appendWif(self.active_private_key_of_beem4) tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
def test_verifyAuthority_appbase(self): stm = self.appbase tx = TransactionBuilder(steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) account = Account("test", steem_instance=stm) tx.appendSigner(account, "active") tx.appendWif(wif) self.assertTrue(len(tx.wifs) > 0) tx.sign() with self.assertRaises(exceptions.MissingRequiredActiveAuthority): tx.verify_authority() self.assertTrue(len(tx["signatures"]) > 0)
def test_transfer_1of1(self): steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '1 of 1 transaction' })) self.assertEqual(tx["operations"][0][0], "transfer") tx.appendWif(self.active_key) tx.sign() tx.sign() self.assertEqual(len(tx['signatures']), 1) tx.broadcast() steem.nobroadcast = True
def test_appendWif(self, node_param): if node_param == "non_appbase": stm = self.stm else: stm = self.appbase tx = TransactionBuilder(steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) with self.assertRaises(MissingKeyError): tx.sign() with self.assertRaises(InvalidWifError): tx.appendWif("abcdefg") tx.appendWif(wif) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_transfer_2of2_simple(self): # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send funds steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'elf', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '2 of 2 simple transaction' })) tx.appendWif(self.active_private_key_of_elf) tx.sign() tx.clearWifs() tx.appendWif(self.active_private_key_of_steemfiles) tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
def test_appendWif(self): nodelist = NodeList() stm = Steem(node=self.nodes, nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps( Transfer( **{ "from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) with self.assertRaises(MissingKeyError): tx.sign() with self.assertRaises(InvalidWifError): tx.appendWif("abcdefg") tx.appendWif(self.active_key) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_verifyAuthorityException(self): nodelist = NodeList() stm = Steem(node=self.nodes, keys=[self.posting_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) account = Account("beem2", steem_instance=stm) tx.appendSigner(account, "active") tx.appendWif(self.posting_key) self.assertTrue(len(tx.wifs) > 0) tx.sign() with self.assertRaises( exceptions.MissingRequiredActiveAuthority ): tx.verify_authority() self.assertTrue(len(tx["signatures"]) > 0)
def test_post(wls): op1 = operations.Social_action( **{ "account": "guest123", "social_action_comment_create": { "permlink": 'just-a-test-post', "parent_author": "", "parent_permlink": "test", "title": "just a test post", "body": "test post body", "json_metadata": '{"app":"wls_python"}' } }) op2 = operations.Social_action( **{ "account": "guest123", "social_action_comment_update": { "permlink": 'just-a-test-post', "title": "just a test post", "body": "test post body", } }) op3 = operations.Vote( **{ 'voter': 'guest123', 'author': 'wlsuser', 'permlink': 'another-test-post', 'weight': 10000, }) privateWif = "5K..." tx = TransactionBuilder(use_condenser_api=True, steem_instance=wls) tx.appendOps(op1) tx.appendWif(privateWif) tx.sign() tx.broadcast()
h = postsordered[0] print("\n\nVotando post https://hive.blog/@" + h.author + "/" + h.permlink, " | ", h["created"], " | ", h.reward) # Make transaction and broadcast: tx = TransactionBuilder(blockchain_instance=hive) tx.appendOps( Vote( **{ "voter": account, "author": h.author, "permlink": h.permlink, "weight": int(float(weight) * 100) })) tx.appendWif(pkey) signed_tx = tx.sign() if not dryrun: broadcast_tx = tx.broadcast(trx_id=True) votado = True votos.append({ "time": datetime.datetime.now(), "permlink": h.permlink, "author": h.author, "rewards": float(h.reward) }) # Update and save script state with open("state.pickle", "wb") as f: state["votos"] = votos
new_owner_authority = { 'key_auths': [[new_owner_key, 1]], 'account_auths': [], 'weight_threshold': 1, 'prefix': stm.prefix } op = operations.Request_account_recovery(**{ 'account_to_recover': args.account_to_recover, 'recovery_account': args.recovery_account, 'new_owner_authority': new_owner_authority, 'extensions': [], 'prefix': stm.prefix }) ##################################################################### # Send the operation to the blockchain ##################################################################### tb = TransactionBuilder(steem_instance=stm) tb.appendOps([op]) tb.appendWif(recovery_ak) tb.sign() result = tb.broadcast() if args.dry_mode: print("The following operation would have been sent:") else: print("SUCCESS: @%s requested account recovery for @%s:" % (args.recovery_account, args.account_to_recover)) print(json.dumps(result, indent=2))
def recover_account(account): """Recover ACCOUNT. This action has to be initiated/signed by the account to be recovered. """ acc = Account(account) if acc.get_owner_history() == []: logger.error("@%s has an empty owner history - recovering " "this account is not possible!" % (acc['name'])) return # ask & verify the old owner key old_priv_owner_key = getpass("Enter the old master password or owner " "key for @%s: " % (acc['name'])) old_pk = passwordkey_to_key(old_priv_owner_key, acc['name'], role="owner", prefix=acc.steem.prefix) old_public_owner_key = format(old_pk.get_public(), acc.steem.prefix) # get the new password to prepare all new keys new_pwd = getpass("Enter the new master password for @%s: " % (acc['name'])) key_auths = {} for role in ['owner', 'active', 'posting', 'memo']: pk = PasswordKey(acc['name'], new_pwd, role=role) key_auths[role] = format(pk.get_public_key(), acc.steem.prefix) if role == 'owner': new_priv_owner_key = str(pk.get_private()) # Assemble the account recovery operation recent_owner_authority = { "key_auths": [[old_public_owner_key, 1]], "account_auths": [], "weight_threshold": 1, "prefix": acc.steem.prefix } new_owner_authority = { "key_auths": [[key_auths['owner'], 1]], "account_auths": [], "weight_threshold": 1, "prefix": acc.steem.prefix } op = operations.Recover_account( **{ 'account_to_recover': acc['name'], 'new_owner_authority': new_owner_authority, 'recent_owner_authority': recent_owner_authority, 'extensions': [], "prefix": acc.steem.prefix }) # Send the recovery operations to the blockchain tb = TransactionBuilder(steem_instance=acc.steem) tb.appendOps([op]) tb.appendWif(new_priv_owner_key) tb.appendWif(old_priv_owner_key) tb.sign() tb.broadcast() logger.info("@%s recovered." % (acc['name'])) # Assemble the account update operation op = operations.Account_update( **{ "account": acc["name"], 'active': { 'account_auths': [], 'key_auths': [[key_auths['active'], 1]], "address_auths": [], 'weight_threshold': 1, 'prefix': acc.steem.prefix }, 'posting': { 'account_auths': acc['posting']['account_auths'], 'key_auths': [[key_auths['posting'], 1]], "address_auths": [], 'weight_threshold': 1, 'prefix': acc.steem.prefix }, 'memo_key': key_auths['memo'], "json_metadata": acc['json_metadata'], "prefix": acc.steem.prefix }) # Send the recovery operations to the blockchain tb = TransactionBuilder(steem_instance=acc.steem) tb.appendOps([op]) tb.appendWif(new_priv_owner_key) tb.sign() tb.broadcast() logger.info("SUCCESS: @%s's active, posting and memo keys updated." % (acc['name']))
from beem.nodelist import NodeList from beembase.transactions import getBlockParams log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) # example wif wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" if __name__ == "__main__": stm_online = Steem() ref_block_num, ref_block_prefix = getBlockParams(stm_online) print("ref_block_num %d - ref_block_prefix %d" % (ref_block_num, ref_block_prefix)) stm = Steem(offline=True) op = operations.Transfer({ 'from': 'beembot', 'to': 'holger80', 'amount': "0.001 SBD", 'memo': "" }) tb = TransactionBuilder(steem_instance=stm) tb.appendOps([op]) tb.appendWif(wif) tb.constructTx(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix) tx = tb.sign(reconstruct_tx=False) print(tx.json())
"" } #recover account initialisation and transmission s = Steem(node=['https://api.steemit.com'], keys=[recovery_account_private_key]) op_recover_account = beembase.operations.Recover_account( **op_recover_account_data) print('op_recover_account') print(op_recover_account) tb = TransactionBuilder() tb.appendOps([op_recover_account]) tb.appendWif(str(old_account_owner_private_key)) tb.appendWif(str(new_account_owner_private_key)) tb.sign() result = tb.broadcast() print('result') print(result) #update account keys initialisation and transmission s = Steem(node=['https://api.steemit.com'], keys=[new_account_owner_private_key]) op_account_update = beembase.operations.Account_update( **op_account_update_data) print('op_account_update')
try: exit_code = 1 tx = TransactionBuilder(hive_instance=node_client) ops = [] op = operations.Comment_options(**{ 'author' : accounts[0]['name'], 'permlink' : "hivepy-proposal-title-{}".format(accounts[0]['name']), 'max_accepted_payout' : '1000.000 TBD', 'percent_steem_dollars' : 5000, 'allow_votes' : True, 'allow_curation_rewards' : True, 'prefix': node_client.prefix }) ops.append(op) tx.appendOps(ops) tx.appendWif(accounts[0]['private_key']) tx.sign() tx.broadcast() logger.exception( "Expected exception for old style op was not thrown" ) except Exception as ex: if str(ex) == "Assert Exception:false: Obsolete form of transaction detected, update your wallet.": logger.info("Expected exception on old style op: {}".format(ex)) exit_code = 0 else: logger.info("Unexpected exception on old style op: {}".format(ex)) hive_utils.common.wait_n_blocks(node_client.rpc.url, 5) # use hybrid op with new keys logger.info("Using hybrid op with new keys") try:
} op = operations.Recover_account( **{ 'account_to_recover': acc['name'], 'new_owner_authority': new_owner_authority, 'recent_owner_authority': recent_owner_authority, 'extensions': [], "prefix": stm.prefix }) ##################################################################### # Send the recovery operations to the blockchain ##################################################################### tb = TransactionBuilder(steem_instance=stm) tb.appendOps([op]) tb.appendWif(new_priv_owner_key) tb.appendWif(old_priv_owner_key) tb.sign() result = tb.broadcast() if args.dry_mode: print("The following operation would have been sent:") else: print("SUCCESS: @%s recovered:" % (acc['name'])) print(json.dumps(result, indent=2)) ##################################################################### # Assemble the account update operation ##################################################################### op = operations.Account_update( **{ "account": acc["name"],
tx = TransactionBuilder(steem_instance=stm) update_witness = { "owner": ACCT, "url": "No website yet", "block_signing_key": NATIVE_PREFIX + '1111111111111111111111111111111114T1Anm', "props": { "account_creation_fee": Amount("0.100 %s" % (NATIVE_SYMBOL)), "maximum_block_size":131072, }, "fee": Amount("0.000 %s" % (NATIVE_SYMBOL)), "prefix": NATIVE_PREFIX, } op = operations.Witness_update(**update_witness) tx.appendOps(op) #tx.appendSigner(ACCT, "active") tx.appendWif(WIF) signed_tx = tx.sign() broadcast_tx = tx.broadcast() status_logger.logger.warning("Total missed at or above threshold. Disabling witness server. \nOperation: " + json.dumps(broadcast_tx, indent=4)) sys.exit() else: status_logger.logger.info("Witness " + ACCT + " current total missed: " + str(total_missed) + "\nWitness server operational\n--------------------------") time.sleep(60) #Pause script for 60 seconds. except KeyboardInterrupt: sys.exit() except Exception as WitnessDoesNotExistsException: status_logger.logger.exception("Exception occured\n") status_logger.logger.info("Reconnecting...") stm = Steem( node=["https://peer.vit.tube/"], bundle=True,