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) 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.steem.prefix) if format(pk_validity_check, acc.steem.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.steem.prefix) # Assemble the account recovery request operation new_owner_authority = { 'key_auths': [[new_owner_key, 1]], 'account_auths': [], 'weight_threshold': 1, 'prefix': acc.steem.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.steem.prefix }) # Send the operation to the blockchain tb = TransactionBuilder(steem_instance=acc.steem) tb.appendOps([op]) tb.appendWif(recovery_ak) tb.sign() tb.broadcast() logger.info("@%s requested account recovery for @%s:" % (acc['recovery_account'], acc['name']))
def test_verifyAuthority(self): stm = self.bts stm.wallet.unlock("123") tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1.300 SBD", steem_instance=stm), "memo": "Foobar"})) account = Account("beem", steem_instance=stm) tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() tx.verify_authority() self.assertTrue(len(tx["signatures"]) > 0)
def check_post(self): com = dict() com = { 'parent_author': '', 'parent_permlink': 'steem', 'author': 'me', 'permlink': 'testpost', 'title': 'testpost pls ignore', 'body': 'do not upvote', 'json_metadata': { 'tags': ('test', 'post', 'pls', 'ignore', 'steem'), } } print(len(com['body'])) tx = TransactionBuilder(steem_instance=self.stm) tx.appendOps(Comment(com)) tx.appendSigner("petertag", "active") signed_tx = tx.sign() sz = getsizeof(com) pprint(com) pprint(signed_tx) print("Size is %i" % sz) self.compute_cost(type=1, tx_size=sz, perm_len=len(com['permlink']), pperm_len=len(com['parent_permlink'])) broadcast_tx = tx.broadcast() pprint(broadcast_tx)
def test_Transfer_broadcast(self): nodelist = NodeList() stm = Steem(node=self.nodes, keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, expiration=10, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) tx.appendSigner("beem", "active") tx.sign() tx.broadcast()
def test_Transfer_broadcast_appbase(self): stm = Steem(node=get_node_list(appbase=True), keys=[wif], num_retries=10) tx = TransactionBuilder(expiration=10, steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) tx.appendSigner("test", "active") tx.sign() with self.assertRaises(exceptions.MissingRequiredActiveAuthority): tx.broadcast()
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_transactionbuilder(self, node_param): if node_param == "instance": set_shared_steem_instance(self.bts) o = TransactionBuilder() self.assertIn(o.blockchain.rpc.url, self.urls) with self.assertRaises(RPCConnection): o = TransactionBuilder(steem_instance=Steem( node="https://abc.d", autoconnect=False, num_retries=1)) o.blockchain.get_config() else: set_shared_steem_instance( Steem(node="https://abc.d", autoconnect=False, num_retries=1)) stm = self.bts o = TransactionBuilder(steem_instance=stm) self.assertIn(o.blockchain.rpc.url, self.urls) with self.assertRaises(RPCConnection): o = TransactionBuilder() o.blockchain.get_config()
def test_transactionbuilder(self, node_param): if node_param == "instance": stm = Steem(node="abc", autoconnect=False, num_retries=1) set_shared_steem_instance(self.bts) o = TransactionBuilder() self.assertIn(o.steem.rpc.url, self.urls) with self.assertRaises(NumRetriesReached): o = TransactionBuilder(steem_instance=stm) o.steem.get_config() else: set_shared_steem_instance( Steem(node="abc", autoconnect=False, num_retries=1)) stm = self.bts o = TransactionBuilder(steem_instance=stm) self.assertIn(o.steem.rpc.url, self.urls) with self.assertRaises(NumRetriesReached): o = TransactionBuilder() o.steem.get_config()
def test_transfer_2of2_wallet(self): # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send # priv key of beem5 and beem4 are stored in the wallet # appendSigner fetches both keys and signs automatically with both keys. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") 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 serialized/deserialized transaction'})) tx.appendSigner("beem5", "active") tx.sign() self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
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_appendSigner(self): nodelist = NodeList() stm = Steem(node=self.nodes, keys=[self.active_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("beem", steem_instance=stm) with self.assertRaises( AssertionError ): tx.appendSigner(account, "abcdefg") tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_appendSigner(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": "" })) account = Account("test", steem_instance=stm) with self.assertRaises(AssertionError): tx.appendSigner(account, "abcdefg") tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() 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()
def test_transfer_2of2_wallet(self): # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send # priv key of elf and steemfiles are stored in the wallet # appendSigner fetches both keys and signs automatically with both keys. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'elf', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("elf", "active") tx.sign() self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
role='memo').get_private_key().pubkey), "json_metadata": "" } #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)
if mivoto is None: posts.append(h) print("Post https://hive.blog/@" + cuenta + "/" + h.permlink, " | ", h["created"], " | ", h.reward) if len(posts) > 0: postsordered = sorted( posts, key=lambda x: datetime.datetime.timestamp(x["created"]), reverse=True) 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
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_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)
"Hivepy proposal body [{}]".format(accounts[0]['name']), accounts[0]['name'], permlink = "hivepy-proposal-title-{}".format(accounts[0]['name']), tags = "firstpost" ) hive_utils.common.wait_n_blocks(node_client.rpc.url, 5) from beem.transactionbuilder import TransactionBuilder from beembase import operations exit_code = 0 # use hybrid op with old keys logger.info("Using hybrid op with old keys") 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()
def test_emptyTransaction(self): stm = self.stm tx = TransactionBuilder(steem_instance=stm) self.assertTrue(tx.is_empty()) self.assertTrue(tx["ref_block_num"] is not None)
def test_TransactionConstructor(self, node_param): if node_param == "non_appbase": stm = self.stm else: stm = self.appbase opTransfer = Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" }) tx1 = TransactionBuilder(steem_instance=stm) tx1.appendOps(opTransfer) tx = TransactionBuilder(tx1, steem_instance=stm) self.assertFalse(tx.is_empty()) self.assertTrue(len(tx.list_operations()) == 1) self.assertTrue(repr(tx) is not None) self.assertTrue(str(tx) is not None) account = Account("test", steem_instance=stm) tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
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_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_transfer_2of2_wif(self): nodelist = NodeList() # Send a 2 of 2 transaction from elf which needs beem4's cosign to send # funds but sign the transaction with elf's key and then serialize the transaction # and deserialize the transaction. After that, sign with beem4's key. steem = Steem( node=self.nodes, num_retries=10, keys=[self.active_private_key_of_beem5], expiration=360, ) tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem5', "to": 'beem', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("beem5", "active") tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) tx_json = tx.json() del steem del tx steem = Steem( node=self.nodes, num_retries=10, keys=[self.active_private_key_of_beem4], expiration=360, ) new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) new_tx.broadcast()
def test_transfer_2of2_offline(self): # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send # funds but sign the transaction with beem5's key and then serialize the transaction # and deserialize the transaction. After that, sign with beem4's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") # steem.wallet.removeAccount("beem4") steem.wallet.removePrivateKeyFromPublicKey( str(PublicKey(self.active_private_key_of_beem4, prefix=core_unit))) tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem5', "to": 'beem', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("beem5", "active") tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) # steem.wallet.removeAccount("beem5") steem.wallet.removePrivateKeyFromPublicKey( str(PublicKey(self.active_private_key_of_beem5, prefix=core_unit))) steem.wallet.addPrivateKey(self.active_private_key_of_beem4) tx.appendMissingSignatures() tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True steem.wallet.addPrivateKey(self.active_private_key_of_beem5)
def test_transactionbuilder(self): o = TransactionBuilder() self.assertEqual(o.steem.rpc.url, self.url)
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)
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())
def test_TransactionConstructor(self): stm = self.bts opTransfer = Transfer( **{ "from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" }) tx1 = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx1.appendOps(opTransfer) tx = TransactionBuilder(tx1, steem_instance=stm) self.assertFalse(tx.is_empty()) self.assertTrue(len(tx.list_operations()) == 1) self.assertTrue(repr(tx) is not None) self.assertTrue(str(tx) is not None) account = Account("beem", steem_instance=stm) tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_transfer_2of2_serialized_deserialized(self): # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send # funds but sign the transaction with beem5's key and then serialize the transaction # and deserialize the transaction. After that, sign with beem4's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") steem.wallet.removeAccount("beem4") tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem5', "to": 'beem1', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("beem5", "active") tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) steem.wallet.removeAccount("beem5") tx_json = tx.json() del tx new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) self.assertEqual(len(new_tx['signatures']), 1) steem.wallet.addPrivateKey(self.active_private_key_of_beem4) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) new_tx.broadcast() steem.nobroadcast = True