Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions electrum/eth_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ def decrypt_message(self, pubkey: str, message, password) -> bytes:
index = self.get_address_index(addr)
return self.keystore.decrypt_message(index, message, password)

def clear_coin_price_cache(self):
pass # Only btc wallets need this

def is_billing_address(self, addr):
# overridden for TrustedCoin wallets
Expand Down
128 changes: 2 additions & 126 deletions electrum_gui/android/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
InvalidAddressURI,
InvalidBip39Seed,
InvalidPassword,
Ticker,
UnavaiableHdWallet,
UserCancel,
bfh,
Expand Down Expand Up @@ -99,18 +98,11 @@

log_info = logging.getLogger(__name__)

IS_ANDROID = True
if "iOS_DATA" in os.environ:
from .ioscallback import CallHandler

IS_ANDROID = False

PURPOSE_POS = 1
ACCOUNT_POS = 3
INDEX_POS = 5
BTC_BLOCK_INTERVAL_TIME = 10
DEFAULT_ADDR_TYPE = 49
ticker = None

PURPOSE_TO_ADDRESS_TYPE = {
44: 'p2pkh',
Expand Down Expand Up @@ -217,7 +209,7 @@ def _sol_retrieve_privkey_from_keypair(privkeys) -> bytes:
class AndroidCommands(commands.Commands):
_recovery_flag = True

def __init__(self, android_id=None, config=None, user_dir=None, callback=None, chain_type="mainnet"):
def __init__(self, android_id=None, config=None, user_dir=None, chain_type="mainnet"):
self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
self.config = config or simple_config.SimpleConfig({"auto_connect": True})
if user_dir is None:
Expand All @@ -239,7 +231,6 @@ def __init__(self, android_id=None, config=None, user_dir=None, callback=None, c
self.plugin = Plugins(self.config, "cmdline")
self.label_plugin = self.plugin.load_plugin("labels")
self.label_flag = self.config.get("use_labels", False)
self.callbackIntent = None
self.hd_wallet = None
self.check_pw_wallet = None
self.wallet = None
Expand All @@ -255,19 +246,6 @@ def __init__(self, android_id=None, config=None, user_dir=None, callback=None, c
self.android_id = android_id + ran_str
self.wallet_context = wallet_context.WalletContext(self.config, self.user_dir)
if self.network:
interests = [
"wallet_updated",
"network_updated",
"blockchain_updated",
"status",
"new_transaction",
"verified",
"set_server_status",
]
util.register_callback(self._on_network_event, interests)
util.register_callback(self._on_fee, ["fee"])
# self.network.register_callback(self.on_fee_histogram, ['fee_histogram'])
util.register_callback(self._on_quotes, ["on_quotes"])
util.register_callback(self._on_history, ["on_history"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_fee 和 on_history 还用到吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_fee应该是实际上没作用的,但是也不和回调相关,不过我可以一起去掉
on_history看起来在wallet.py里面还有逻辑,虽然具体那个get_detailed_history我们没用到。

self.fiat_unit = self.daemon.fx.ccy if self.daemon.fx.is_enabled() else ""
self.decimal_point = self.config.get("decimal_point", util.DECIMAL_POINT_DEFAULT)
Expand All @@ -288,15 +266,6 @@ def __init__(self, android_id=None, config=None, user_dir=None, callback=None, c
self.m = 0
self.n = 0
self.config.set_key("auto_connect", True, True)
global ticker
ticker = Ticker(5.0, self._update_status)
ticker.start()
if IS_ANDROID:
if callback is not None:
self._set_callback_fun(callback)
else:
self.my_handler = CallHandler.alloc().init()
self._set_callback_fun(self.my_handler)
self._start_daemon()
self._get_block_info()
the_begging.initialize()
Expand Down Expand Up @@ -330,81 +299,10 @@ def stop_loop(self):
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
self._loop_thread.join(timeout=1)

def _on_fee(self, event, *arg):
self.fee_status = self.config.get_fee_status()

def _on_quotes(self, d):
self._update_status()

def _on_history(self, d):
if self.wallet:
if isinstance(self.wallet, Wallet):
self.wallet.clear_coin_price_cache()

def _update_status(self):
if self.wallet is None:
return

coin = self.wallet.coin
address = self.wallet.get_addresses()[0]
out = {"chaincode": coin}

chain_affinity = _get_chain_affinity(coin)
if is_coin_migrated(coin):
main_balance_info, contracts_balance_info, sum_fiat = self._get_general_wallet_all_balance(self.wallet)
out.update(main_balance_info)
out["tokens"] = contracts_balance_info
out["sum_fiat"] = f"{self.daemon.fx.ccy_amount_str(sum_fiat, True)} {self.ccy}"
out["coin_asset"] = (
self._fill_balance_info_with_coin(sum_fiat, coin)
if sum_fiat != Decimal(0)
else main_balance_info["balance"]
)

out["name"] = self.wallet.identity
elif chain_affinity == "eth": # eth base
main_balance_info, contracts_balance_info, sum_fiat = self._get_eth_wallet_all_balance(self.wallet)
out.update(main_balance_info)
out["tokens"] = contracts_balance_info
out["sum_fiat"] = f"{self.daemon.fx.ccy_amount_str(sum_fiat, True)} {self.ccy}"
out["coin_asset"] = (
self._fill_balance_info_with_coin(sum_fiat, coin)
if sum_fiat != Decimal(0)
else main_balance_info["balance"]
)

out["name"] = self.wallet.identity
elif (
self.network
and self.network.is_connected()
and self.network.get_server_height() != 0
and self.wallet.up_to_date
and chain_affinity == "btc"
): # btc
c, u, x = self.wallet.get_balance()
balance = c + u
fiat = Decimal(balance) / COIN * price_manager.get_last_price(coin, self.ccy)
fiat_str = f"{self.daemon.fx.ccy_amount_str(fiat, True)} {self.ccy}"

# main balance info
out["coin"] = coin
out["address"] = address
out["icon"] = self._get_icon_by_token(coin)
out["balance"] = self.format_amount(balance)
out["fiat"] = fiat_str

out["tokens"] = []
out["sum_fiat"] = fiat_str
out["coin_asset"] = out["balance"]
out["name"] = self.wallet.identity

if u:
out["unconfirmed"] = self.format_amount(u, is_diff=True).strip()
if x:
out["unmatured"] = self.format_amount(x, is_diff=True).strip()

if "name" in out and self.callbackIntent is not None:
self.callbackIntent.onCallback("update_status=%s" % json.dumps(out, cls=json_encoders.DecimalEncoder))

@api.api_entry() # TODO: Currently not used
def get_remove_flag(self, tx_hash):
height = self.wallet.get_tx_height(tx_hash).height
Expand Down Expand Up @@ -441,21 +339,6 @@ def delete_tx(self, hash):
log_info.info("push_tx delete_tx error {}.".format(e))
pass

def _on_network_event(self, event, *args):
if event == "set_server_status" and self.callbackIntent is not None:
self.callbackIntent.onCallback("set_server_status=%s" % args[0])
elif event in ("network_updated",):
# TODO: Update the list of available servers
pass
elif event in (
"wallet_updated",
"blockchain_updated",
"status",
"new_transaction",
"verified",
):
self._update_status()

def _daemon_action(self):
self.daemon_running = True
self.daemon.run_daemon()
Expand All @@ -481,8 +364,6 @@ def stop(self):
self.daemon_running = False
self.stop_loop()
self.plugin.stop()
global ticker
ticker.cancel()
the_begging.terminate()

def _set_hd_wallet(self, wallet_obj):
Expand Down Expand Up @@ -589,9 +470,6 @@ def set_syn_server(self, flag):
):
self.label_plugin.load_wallet(self.wallet)

def _set_callback_fun(self, callbackIntent):
self.callbackIntent = callbackIntent

@api.api_entry() # TODO: Currently not used
def set_multi_wallet_info(self, name, m, n, is_customer=False):
try:
Expand Down Expand Up @@ -1347,7 +1225,6 @@ def set_currency(self, ccy):
if ccy != self.ccy:
self.daemon.fx.set_currency(ccy)
self.ccy = ccy
self._update_status()

@api.api_entry()
def get_exchange_currency(self, type, amount):
Expand Down Expand Up @@ -1386,7 +1263,6 @@ def _set_base_uint(self, base_unit):
self.base_unit = base_unit
self.decimal_point = util.base_unit_name_to_decimal_point(self.base_unit)
self.config.set_key("decimal_point", self.decimal_point, True)
self._update_status()

def format_amount_and_units(self, amount):
try:
Expand Down
15 changes: 0 additions & 15 deletions electrum_gui/android/custom_objc.py

This file was deleted.

9 changes: 0 additions & 9 deletions electrum_gui/android/ioscallback.py

This file was deleted.

4 changes: 0 additions & 4 deletions electrum_gui/android/migrating.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,6 @@ def sign_message(self, address: str, message: str, password: str = None, path: s
def verify_message(self, address, message, sig, path: str = None) -> bool:
return wallet_manager.verify_message(self.chain_code, address, message, sig, hardware_device_path=path)

def clear_coin_price_cache(self):
# bypass
pass

def is_watching_only(self) -> bool:
return WalletType.is_watchonly_wallet(self.general_wallet_type)

Expand Down
8 changes: 0 additions & 8 deletions electrum_gui/android/uikit_bindings/__init__.py

This file was deleted.

58 changes: 0 additions & 58 deletions electrum_gui/android/uikit_bindings/foundation.py

This file was deleted.

Loading