def test_Transfer_broadcast(self): nodelist = NodeList() hv = Hive(node=self.nodes, keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, expiration=10, hive_instance=hv) tx.appendOps(Transfer(**{"from": "bhive", "to": "bhive1", "amount": Amount("1 HIVE", hive_instance=hv), "memo": ""})) tx.appendSigner("bhive", "active") tx.sign() tx.broadcast()
def test_appendSigner(self): nodelist = NodeList() hv = Hive(node=self.nodes, keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv) tx.appendOps(Transfer(**{"from": "bhive", "to": "bhive1", "amount": Amount("1 HIVE", hive_instance=hv), "memo": ""})) account = Account("bhive", hive_instance=hv) 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_verifyAuthorityException(self): nodelist = NodeList() hv = Hive(node=self.nodes, keys=[self.posting_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv) tx.appendOps(Transfer(**{"from": "bhive", "to": "bhive1", "amount": Amount("1 HIVE", hive_instance=hv), "memo": ""})) account = Account("bhive2", hive_instance=hv) 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_appendWif(self): nodelist = NodeList() hv = Hive(node=self.nodes, nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv) tx.appendOps(Transfer(**{"from": "bhive", "to": "bhive1", "amount": Amount("1 HIVE", hive_instance=hv), "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 setUpClass(cls): cls.nodelist = NodeList() cls.nodelist.update_nodes(hive_instance=Hive( node=cls.nodelist.get_nodes( exclude_limited=False), num_retries=10)) hv = Hive(node=cls.nodelist.get_nodes()) hv.config.refreshBackup() hv.set_default_nodes(["xyz"]) del hv cls.urls = cls.nodelist.get_nodes(exclude_limited=True) cls.bts = Hive(node=cls.urls, nobroadcast=True, num_retries=10) set_shared_hive_instance(cls.bts) acc = Account("bhive.app", hive_instance=cls.bts) comment = acc.get_blog(limit=20)[-1] cls.authorperm = comment.authorperm votes = acc.get_account_votes() last_vote = votes[-1] cls.authorpermvoter = '@' + last_vote['authorperm'] + '|' + acc["name"]
def test_properties(self): bts = Hive(node=self.nodelist.get_nodes(), nobroadcast=True, data_refresh_time_seconds=900, keys={ "active": wif, "owner": wif, "memo": wif }, num_retries=10) self.assertTrue( bts.get_feed_history(use_stored_data=False) is not None) self.assertTrue( bts.get_reward_funds(use_stored_data=False) is not None) self.assertTrue( bts.get_current_median_history(use_stored_data=False) is not None) self.assertTrue( bts.get_hardfork_properties(use_stored_data=False) is not None) self.assertTrue(bts.get_network(use_stored_data=False) is not None) self.assertTrue( bts.get_witness_schedule(use_stored_data=False) is not None) self.assertTrue(bts.get_config(use_stored_data=False) is not None) self.assertTrue(bts.get_block_interval() is not None) self.assertTrue(bts.get_blockchain_version() is not None)
def test_offline(self): bts = Hive(node=self.nodelist.get_nodes(), offline=True, data_refresh_time_seconds=900, keys={ "active": wif, "owner": wif, "memo": wif }) bts.refresh_data() self.assertTrue(bts.get_feed_history(use_stored_data=False) is None) self.assertTrue(bts.get_feed_history(use_stored_data=True) is None) self.assertTrue(bts.get_reward_funds(use_stored_data=False) is None) self.assertTrue(bts.get_reward_funds(use_stored_data=True) is None) self.assertTrue( bts.get_current_median_history(use_stored_data=False) is None) self.assertTrue( bts.get_current_median_history(use_stored_data=True) is None) self.assertTrue( bts.get_hardfork_properties(use_stored_data=False) is None) self.assertTrue( bts.get_hardfork_properties(use_stored_data=True) is None) self.assertTrue(bts.get_network(use_stored_data=False) is None) self.assertTrue(bts.get_network(use_stored_data=True) is None) self.assertTrue( bts.get_witness_schedule(use_stored_data=False) is None) self.assertTrue(bts.get_witness_schedule(use_stored_data=True) is None) self.assertTrue(bts.get_config(use_stored_data=False) is None) self.assertTrue(bts.get_config(use_stored_data=True) is None) self.assertEqual(bts.get_block_interval(), 3) self.assertEqual(bts.get_blockchain_version(), '0.0.0')
def test_create_account(self): bts = Hive(node=self.nodelist.get_nodes(), nobroadcast=True, unsigned=True, data_refresh_time_seconds=900, keys={"active": wif, "owner": wif, "memo": wif}, num_retries=10) core_unit = "STM" name = ''.join(random.choice(string.ascii_lowercase) for _ in range(12)) key1 = PrivateKey() key2 = PrivateKey() key3 = PrivateKey() key4 = PrivateKey() key5 = PrivateKey() bts.txbuffer.clear() tx = bts.create_account( name, creator="test", # 1.2.7 owner_key=format(key1.pubkey, core_unit), active_key=format(key2.pubkey, core_unit), posting_key=format(key3.pubkey, core_unit), memo_key=format(key4.pubkey, core_unit), additional_owner_keys=[format(key5.pubkey, core_unit)], additional_active_keys=[format(key5.pubkey, core_unit)], additional_posting_keys=[format(key5.pubkey, core_unit)], additional_owner_accounts=["test1"], # 1.2.0 additional_active_accounts=["test2"], additional_posting_accounts=["test3"], storekeys=False, ) self.assertEqual( tx["operations"][0][0], "account_create" ) op = tx["operations"][0][1] role = "active" self.assertIn( format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( "test2", [x[0] for x in op[role]["account_auths"]]) role = "posting" self.assertIn( format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( "test3", [x[0] for x in op[role]["account_auths"]]) role = "owner" self.assertIn( format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( format(key5.pubkey, core_unit), [x[0] for x in op[role]["key_auths"]]) self.assertIn( "test1", [x[0] for x in op[role]["account_auths"]]) self.assertEqual( op["creator"], "test")
import time import io from bhive import Hive from bhive.account import Account from bhive.amount import Amount from bhive.utils import parse_time from hive.account import Account as hiveAccount from hive.post import Post as hivePost from hive import Hive as hiveHive import logging log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": hv = Hive("https://api.hive.blog") bhive_acc = Account("thecrazygm", hive_instance=hv) hv2 = hiveHive(nodes=["https://api.hive.blog"]) hive_acc = hiveAccount("thecrazygm", hived_instance=hv2) # profile print("bhive_acc.profile {}".format(bhive_acc.profile)) print("hive_acc.profile {}".format(hive_acc.profile)) # hp print("bhive_acc.hp {}".format(bhive_acc.hp)) print("hive_acc.hp {}".format(hive_acc.hp)) # rep print("bhive_acc.rep {}".format(bhive_acc.rep)) print("hive_acc.rep {}".format(hive_acc.rep)) # balances print("bhive_acc.balances {}".format(bhive_acc.balances))
time_diff_est = "%.2f days" % next_block_d elif next_block_h > 1: time_diff_est = "%.2f hours" % next_block_h elif next_block_min > 1: time_diff_est = "%.2f minutes" % next_block_min else: time_diff_est = "%.2f seconds" % next_block_s return time_diff_est if __name__ == "__main__": if len(sys.argv) != 2: witness = "thecrazygm" else: witness = sys.argv[1] hv = Hive() witness = Witness(witness, hive_instance=hv) witness_schedule = hv.get_witness_schedule() config = hv.get_config() if "VIRTUAL_SCHEDULE_LAP_LENGTH2" in config: lap_length = int(config["VIRTUAL_SCHEDULE_LAP_LENGTH2"]) else: lap_length = int(config["HIVE_VIRTUAL_SCHEDULE_LAP_LENGTH2"]) witnesses = WitnessesRankedByVote(limit=250, hive_instance=hv) vote_sum = witnesses.get_votes_sum() virtual_time_to_block_num = int( witness_schedule["num_scheduled_witnesses"]) / (lap_length / (vote_sum + 1)) while True:
def tearDownClass(cls): hv = Hive(node=cls.nodelist.get_nodes()) hv.config.recover_with_latest_backup()
def test_hive(self, node_param): if node_param == "instance": set_shared_hive_instance(self.bts) o = Hive(node=self.urls) o.get_config() self.assertIn(o.rpc.url, self.urls) with self.assertRaises(RPCConnection): hv = Hive(node="https://abc.d", autoconnect=False, num_retries=1) hv.get_config() else: set_shared_hive_instance( Hive(node="https://abc.d", autoconnect=False, num_retries=1)) hv = self.bts o = hv o.get_config() self.assertIn(o.rpc.url, self.urls) with self.assertRaises(RPCConnection): hv = shared_hive_instance() hv.get_config()
from bhive import Hive import numpy as np from bhive.utils import reputation_to_score from bhive.amount import Amount from bhive.constants import HIVE_100_PERCENT import matplotlib as mpl # mpl.use('Agg') # mpl.use('TkAgg') import matplotlib.pyplot as plt if __name__ == "__main__": hv = Hive() price = Amount(hv.get_current_median_history()["base"]) reps = [0] for i in range(26, 91): reps.append(int(10**((i - 25) / 9 + 9))) # reps = np.logspace(9, 16, 60) used_power = hv._calc_resulting_vote() last_hp = 0 hp_list = [] rep_score_list = [] for goal_rep in reps: score = reputation_to_score(goal_rep) rep_score_list.append(score) needed_rshares = int(goal_rep) << 6 needed_vests = needed_rshares / used_power / 100 needed_hp = hv.vests_to_hp(needed_vests) hp_list.append(needed_hp / 1000) # print("| %.1f | %.2f | %.2f | " % (score, needed_hp / 1000, needed_hp / 1000 - last_hp / 1000)) last_hp = needed_hp
from django.shortcuts import get_object_or_404, redirect, render from django.utils import timezone from bhive import Hive from bhive.account import Account from bhive.comment import Comment from bhive.discussions import Query from bhive.instance import set_shared_hive_instance from bhive.utils import construct_authorperm from hive import Hive as Hivepy from markupsafe import Markup #nodes = ["https://api.hive.blog", "https://anyx.io"] q = Query(limit=10) hvpy = Hivepy() # nodes=nodes) hv = Hive() # node=nodes) set_shared_hive_instance(hv) image_proxy = "https://images.hive.blog/480x0/" def strip(text): text['body'] = markdown.markdown(text['body'], extensions=[ 'nl2br', 'codehilite', 'pymdownx.extra', 'pymdownx.magiclink', 'pymdownx.betterem', 'pymdownx.inlinehilite']) text['body'] = re.sub("(<h1>|<h2>)", "<h3>", text['body']) text['body'] = re.sub(r"<img\b(?=\s)(?=(?:[^>=]|='[^']*'|=\"[^\"]*\"|=[^'\"][^\s>]*)*?\ssrc=['\"]([^\"]*)['\"]?)(?:[^>=]|='[^']*'|=\"[^\"]*\"|=[^'\"\s]*)*\"\s?\/?>", rf'<img src={image_proxy}\1 >', text['body']) text['body'] = Markup(text['body']) return text def trending(request):