def setUpClass(cls): nodelist = NodeList() nodelist.update_nodes(dpay_instance=DPay(node=nodelist.get_nodes( normal=True, appbase=True), num_retries=10)) cls.bts = DPay( node=nodelist.get_nodes(), nobroadcast=True, timeout=30, num_retries=30, ) # from getpass import getpass # self.bts.wallet.unlock(getpass()) set_shared_dpay_instance(cls.bts) cls.bts.set_default_account("test") b = Blockchain(dpay_instance=cls.bts) num = b.get_current_block_num() # num = 23346630 cls.start = num - 25 cls.stop = num
def setUpClass(cls): nodelist = NodeList() stm = shared_dpay_instance() stm.config.refreshBackup() cls.bts = DPay( node=nodelist.get_testnet(), nobroadcast=True, num_retries=10, expiration=120, ) # from getpass import getpass # self.bts.wallet.unlock(getpass()) cls.bts.set_default_account("dpaygo")
def setUpClass(cls): nodelist = NodeList() nodelist.update_nodes(dpay_instance=DPay(node=nodelist.get_nodes( normal=True, appbase=True), num_retries=10)) cls.bts = DPay(node=nodelist.get_nodes(appbase=False), nobroadcast=True, keys={"active": wif}, num_retries=10) cls.appbase = DPay(node=nodes_appbase, nobroadcast=True, keys={"active": wif}, num_retries=10) # from getpass import getpass # self.bts.wallet.unlock(getpass()) set_shared_dpay_instance(cls.bts) cls.bts.set_default_account("test") b = Blockchain(dpay_instance=cls.bts) num = b.get_current_block_num() cls.start = num - 25 cls.stop = num
def setUpClass(cls): nodelist = NodeList() nodelist.update_nodes(dpay_instance=DPay(node=nodelist.get_nodes( normal=True, appbase=True), num_retries=10)) cls.bts = DPay( node=nodelist.get_nodes(normal=False, appbase=True, dev=True), nobroadcast=True, num_retries=10, timeout=30, use_condenser=False, keys={"active": wif}, ) # from getpass import getpass # self.bts.wallet.unlock(getpass()) set_shared_dpay_instance(cls.bts) cls.bts.set_default_account("test") b = Blockchain(dpay_instance=cls.bts) num = b.get_current_block_num() cls.start = num - 100 cls.stop = num cls.max_batch_size = 1 # appbase does not support batch rpc calls at the momement (internal error)
def setUpClass(cls): nodelist = NodeList() nodelist.update_nodes(dpay_instance=DPay(node=nodelist.get_nodes( normal=True, appbase=True), num_retries=10)) cls.stm = DPay(node=nodelist.get_nodes(appbase=False), keys={ "active": wif, "owner": wif, "memo": wif }, nobroadcast=True, num_retries=10) cls.appbase = DPay(node=nodelist.get_nodes(normal=False, appbase=True), nobroadcast=True, keys={ "active": wif, "owner": wif, "memo": wif }, num_retries=10) set_shared_dpay_instance(cls.stm) cls.stm.set_default_account("test")
def test_properties(self, node_param): if node_param == "non_appbase": bts = DPay(node=self.nodelist.get_nodes(appbase=False), nobroadcast=True, data_refresh_time_seconds=900, keys={"active": wif, "owner": wif, "memo": wif}, num_retries=10) elif node_param == "appbase": bts = DPay(node=self.nodelist.get_nodes(normal=False, appbase=True), nobroadcast=True, data_refresh_time_seconds=900, keys={"active": wif, "owner": wif, "memo": wif}, num_retries=10) self.assertTrue(bts.get_reserve_ratio(use_stored_data=False) is not None) 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 setUpClass(cls): nodelist = NodeList() nodelist.update_nodes(dpay_instance=DPay(node=nodelist.get_nodes( normal=True, appbase=True), num_retries=10)) cls.bts = DPay(node=nodelist.get_nodes(appbase=False), nobroadcast=True, keys={"active": wif}, num_retries=10) cls.appbase = DPay(node=nodelist.get_nodes(normal=False, appbase=True), nobroadcast=True, keys={"active": wif}, num_retries=10) # from getpass import getpass # self.bts.wallet.unlock(getpass()) set_shared_dpay_instance(cls.bts) cls.bts.set_default_account("test") acc = Account("holger80", dpay_instance=cls.bts) n_votes = 0 index = 0 while n_votes == 0: comment = acc.get_feed(limit=30)[::-1][index] votes = comment.get_votes() n_votes = len(votes) index += 1 last_vote = votes[0] cls.authorpermvoter = construct_authorpermvoter( last_vote['author'], last_vote['permlink'], last_vote["voter"]) [author, permlink, voter] = resolve_authorpermvoter(cls.authorpermvoter) cls.author = author cls.permlink = permlink cls.voter = voter cls.authorperm = construct_authorperm(author, permlink)
def setUpClass(cls): nodelist = NodeList() nodelist.update_nodes(dpay_instance=DPay(node=nodelist.get_nodes(normal=True, appbase=True), num_retries=10)) cls.bts = DPay( node=nodelist.get_nodes(normal=True, appbase=False), nobroadcast=True, bundle=False, unsigned=True, # Overwrite wallet to use this list of wifs only keys={"active": wif}, num_retries=10 ) cls.appbase = DPay( node=nodelist.get_nodes(normal=False, appbase=True, dev=False), nobroadcast=True, bundle=False, unsigned=True, # Overwrite wallet to use this list of wifs only keys={"active": wif}, num_retries=10 ) cls.account = Account("dpaygobot", full=True, dpay_instance=cls.bts) cls.account_appbase = Account("dpaygobot", full=True, dpay_instance=cls.appbase) set_shared_dpay_instance(cls.bts)
def test_Transfer_broadcast(self): nodelist = NodeList() stm = DPay(node=nodelist.get_testnet(), keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(expiration=10, dpay_instance=stm) tx.appendOps( Transfer( **{ "from": "dpaygo", "to": "dpaygo1", "amount": Amount("1 BEX", dpay_instance=stm), "memo": "" })) tx.appendSigner("dpaygo", "active") tx.sign() tx.broadcast()
def test_appendWif(self): nodelist = NodeList() stm = DPay(node=nodelist.get_testnet(), nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(dpay_instance=stm) tx.appendOps( Transfer( **{ "from": "dpaygo", "to": "dpaygo1", "amount": Amount("1 BEX", dpay_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_appendSigner(self): nodelist = NodeList() stm = DPay(node=nodelist.get_testnet(), keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(dpay_instance=stm) tx.appendOps( Transfer( **{ "from": "dpaygo", "to": "dpaygo1", "amount": Amount("1 BEX", dpay_instance=stm), "memo": "" })) account = Account("dpaygo", dpay_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_verifyAuthorityException(self): nodelist = NodeList() stm = DPay(node=nodelist.get_testnet(), keys=[self.posting_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(dpay_instance=stm) tx.appendOps( Transfer( **{ "from": "dpaygo", "to": "dpaygo1", "amount": Amount("1 BEX", dpay_instance=stm), "memo": "" })) account = Account("dpaygo2", dpay_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_offline(self): bts = DPay(node=self.nodelist.get_nodes(appbase=False), offline=True, data_refresh_time_seconds=900, keys={"active": wif, "owner": wif, "memo": wif}) bts.refresh_data() self.assertTrue(bts.get_reserve_ratio(use_stored_data=False) is None) self.assertTrue(bts.get_reserve_ratio(use_stored_data=True) is None) 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')
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 = "holger80" else: witness = sys.argv[1] stm = DPay() witness = Witness(witness, dpay_instance=stm) witness_schedule = stm.get_witness_schedule() config = stm.get_config() if "VIRTUAL_SCHEDULE_LAP_LENGTH2" in config: lap_length = int(config["VIRTUAL_SCHEDULE_LAP_LENGTH2"]) else: lap_length = int(config["DPAY_VIRTUAL_SCHEDULE_LAP_LENGTH2"]) witnesses = WitnessesRankedByVote(limit=250, dpay_instance=stm) vote_sum = witnesses.get_votes_sum() virtual_time_to_block_num = int( witness_schedule["num_scheduled_witnesses"]) / (lap_length / (vote_sum + 1)) while True:
from datetime import timedelta import time import io from dpaygo import DPay from dpaygo.account import Account from dpaygo.amount import Amount from dpaygo.utils import parse_time from dpay.account import Account as dpayAccount from dpay.post import Post as dpayPost from dpay import DPay as dpayDPay import logging log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": stm = DPay("wss://dpayd.dpays.io") dpaygo_acc = Account("jared", dpay_instance=stm) stm2 = dpayDPay(nodes=["wss://dpayd.dpays.io"]) dpay_acc = dpayAccount("jared", dpayd_instance=stm2) # profile print("dpaygo_acc.profile {}".format(dpaygo_acc.profile)) print("dpay_acc.profile {}".format(dpay_acc.profile)) # sp print("dpaygo_acc.sp {}".format(dpaygo_acc.sp)) print("dpay_acc.sp {}".format(dpay_acc.sp)) # rep print("dpaygo_acc.rep {}".format(dpaygo_acc.rep)) print("dpay_acc.rep {}".format(dpay_acc.rep)) # balances print("dpaygo_acc.balances {}".format(dpaygo_acc.balances))
def test_create_account(self, node_param): if node_param == "non_appbase": bts = DPay(node=self.nodelist.get_nodes(appbase=False), nobroadcast=True, unsigned=True, data_refresh_time_seconds=900, keys={"active": wif, "owner": wif, "memo": wif}, num_retries=10) elif node_param == "appbase": bts = DPay(node=self.nodelist.get_nodes(normal=False, appbase=True), nobroadcast=True, unsigned=True, data_refresh_time_seconds=900, keys={"active": wif, "owner": wif, "memo": wif}, num_retries=10) 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=["test1"], storekeys=False, delegation_fee_dpay="0 BEX" ) 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( "test1", [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( "test1", [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")
from apscheduler.schedulers.background import BackgroundScheduler stm = DPay( node=["https://" + os.environ['dpaynode']], known_chains={ "DPAY": { 'chain_assets': [{ "asset": "BBD", "symbol": "BBD", "precision": 3, "id": 0 }, { "asset": "BEX", "symbol": "BEX", "precision": 3, "id": 1 }, { "asset": "VESTS", "symbol": "VESTS", "precision": 6, "id": 2 }], 'chain_id': '38f14b346eb697ba04ae0f5adcfaa0a437ed3711197704aa256a14cb9b4a8f26', 'min_version': '0.0.0', 'prefix': 'DWB' } }) mongo = MongoClient("mongodb://mongo")
def tearDownClass(cls): stm = DPay(node=cls.nodelist.get_nodes()) stm.config.recover_with_latest_backup()