def _load_master_wallet(self): py_master_wallets = self._py_manager.GetAllMasterWallets() if len(py_master_wallets) == 0: ctprint("no py_master_wallet loaded in local") for py_master_wallet in py_master_wallets: master_wallet = MasterWallet(py_master_wallet) self._master_wallets_dict[master_wallet.wallet_id] = master_wallet
def t_create_and_sync(root_path, wid, lang, opt_psw, pay_psw, s_addr): cid = 'ELA' clear_spv_local_data_and_logfile(root_path, wid) manager = Manager(root_path) manager.create_hd_wallet_mainchain(lang, wid, opt_psw, pay_psw, s_addr) sw_ela = manager.master_wallets_d[wid].sub_wallets_d[cid] ctprint(sw_ela.get_addresses()) manager.wait_master_wallets_sync()
def _print_member_var(self): for i, (k, v) in enumerate(self.__dict__.items()): if i < len(self.__dict__.items()) - 1: ctprint(k, end=':', t=False) ctprint(f"<{v}>", end='\n') else: ctprint(k, end='', t=False) ctprint(f"<{v}>")
def __init__(self, py_master_wallet: spv.PyMasterWallet): self._py_master_wallet = py_master_wallet self._wallet_id = self._py_master_wallet.GetID() self._sub_wallets_dict = {} self._load_sub_wallet() sub_wallets_number = len(self._sub_wallets_dict) ctprint(f"sub_wallets_number: {sub_wallets_number}") if sub_wallets_number == 0: new_py_sub_wallet = self._py_master_wallet.CreateSubWallet( chainID='ELA', feePerKb=10000) new_sub_wallet = SubWallet(new_py_sub_wallet, self._wallet_id) self._sub_wallets_dict[new_sub_wallet.chain_id] = new_sub_wallet
def wait_chains_sync(self, cycle_time=10): cycle = 0 if self._h_estimate == self._h_estimate_init: self.wait_sync_progress_cb(2) while self._is_updated is False: ti = self._time_init_sync tn = int(time.time()) _t = tn - ti hci = self._h_current_init hei = self._h_estimate_init _hi = hei - hci he = self._h_estimate hc = self._h_current _h = he - hc _he = he - hei _hc = hc - hci va_hc = _hc / _t l_h = _hi - _hc l_t = l_h / va_hc l_he_t = _he / va_hc l_t_ = _h / va_hc s2hms = ( lambda sec: f"{int(sec/60/60)}:{int(sec/60%60)}:{int(sec%60)}({int(sec)}s)" ) if hc < hei: h_all = f"{_hi}+{_he}" info_r = f"{s2hms(l_t)}(+{int(l_he_t)}s) left." else: h_all = f"{_hi+_he}" info_r = f"about to complete... {l_t_}s left." info_h = f"sync stat: [{self.wallet_id}:{self.chain_id}] {cycle}({cycle_time}s): {_hc}/{h_all} completed " info_v = f"in {s2hms(_t)}s (v_avg:{int(va_hc)}blocks/s)" ctprint(f"{info_h} {info_v} {info_r}") time.sleep(cycle_time) cycle += 1 ctprint(f'{self.wallet_id} now is updated')
def send_tx(self, from_addr, to_addr, amount, memo, remark, use_voted_utxo, pay_psw, fee): tx_c = self._py_subwallet.CreateTransaction(from_addr, to_addr, amount, memo, remark, use_voted_utxo) ctprint(tx_c) _fee = self._py_subwallet.CalculateTransactionFee(tx_c, 10000) ctprint(fee) tx_fc = self._py_subwallet.UpdateTransactionFee(tx_c, _fee, from_addr) ctprint(tx_fc) tx_sfc = self._py_subwallet.SignTransaction(tx_fc, pay_psw) # tx_sc = self._py_subwallet.SignTransaction(tx_c, pay_psw) tx_res = self._py_subwallet.PublishTransaction(tx_sfc) ctprint(tx_res) cb_ = (self._call_back.count_on_tx_status_changed, self._call_back.count_on_tx_published, self._call_back.count_on_tx_deleted) cycle = 0 while self._call_back.count_on_tx_status_changed == 0: ctprint(f"{cycle} {cb_}", end='\r') time.sleep(1) cycle += 1
def wait_sync_progress_cb(self, count): t_begin = time.time() t_max = 360 t = 0 while t < t_max: ctprint(f"wait sync cb count {t}", end='\r') if self._call_back.count_on_block_sync_progress >= count: t_end = time.time() ctprint( f"[SYNC] C.B. no.{count} executed in {t_end - t_begin} sec" ) ctprint( f"waiting block_sync_progress, {self._count_update_sync_process}" ) break time.sleep(1) t += 1 else: raise Exception(f"connecting_to_node timeout: {t_max}s")
def export_wallet_with_keystore(self, wid, backup_psw, pay_psw, with_prv_key): pymw = self.master_wallets_d[wid]._py_master_wallet ks = self._py_manager.ExportWalletWithKeystore(pymw, backup_psw, pay_psw, with_prv_key) ctprint(ks)
def _print_cb(cb_name, cb_info, cb_count, order=None): info = f" => {cb_info}" if not cb_info else cb_info text_to_print = f"{cb_count} [{order}-{cb_name}] {info}" return ctprint(text_to_print, t=False)