Skip to content

Commit

Permalink
Tip filtering support. There is still a lot to be done with solidifyi…
Browse files Browse the repository at this point in the history
…ng the server model but we are getting closer.
  • Loading branch information
rt121212121 committed Apr 11, 2022
1 parent 41506d5 commit 45c0bd0
Show file tree
Hide file tree
Showing 17 changed files with 689 additions and 868 deletions.
35 changes: 6 additions & 29 deletions electrumsv/blockchain_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

from .app_state import app_state
from .constants import (ACCOUNT_SCRIPT_TYPES, AccountType, CHANGE_SUBPATH, DerivationType,
DerivationPath, RECEIVING_SUBPATH, ScriptType)
DerivationPath, RECEIVING_SUBPATH, ScriptType, ServerCapability)
from .exceptions import UnsupportedAccountTypeError
from .i18n import _
from .logs import logs
Expand Down Expand Up @@ -187,29 +187,10 @@ async def search_entries(self, entries: List[SearchEntry]) -> None:
means that the connection was closed mid-transmission.
Raises `ServerConnectionError` if the remote computer cannot be connected to.
"""

# TODO(1.4.0) Networking. Discuss this with Roger - the fact that we want to pin to the
# main server for the wallet for consistent chain state.

# all_candidates = self._account._wallet.get_servers_for_account(
# self._account, NetworkServerType.GENERAL)
# restoration_candidates = select_servers(ServerCapability.RESTORATION, all_candidates)
# if not len(restoration_candidates):
# raise PushDataSearchError(_("No servers available."))

# # TODO(1.4.0) Networking. Standardised server selection / endpoint url resolution.
# candidate = random.choice(restoration_candidates)
# assert candidate.api_server is not None

# url = f"{candidate.api_server.url}api/v1/restoration/search"

main_server = self._account.get_wallet().main_server
if not main_server:
raise PushDataSearchError(_("No servers available."))

url = main_server._state.server.url
url = url if url.endswith("/") else url +"/"
url = f"{url}api/v1/restoration/search"
state = self._account.get_wallet().get_server_state_for_capability(
ServerCapability.TIP_FILTER)
if state is None:
raise PushDataSearchError(_("Not currently connected to a designated indexing server."))

# These are the pushdata hashes that have been passed along.
entry_mapping: Dict[bytes, SearchEntry] = { entry.item_hash: entry for entry in entries }
Expand All @@ -218,11 +199,7 @@ async def search_entries(self, entries: List[SearchEntry]) -> None:
entry.item_hash.hex() for entry in entries
]
}
credential_id = main_server._state.credential_id
assert credential_id is not None
master_token = app_state.credentials.get_indefinite_credential(credential_id)
async for payload_bytes in post_restoration_filter_request_binary(url, request_data,
master_token):
async for payload_bytes in post_restoration_filter_request_binary(state, request_data):
filter_result = unpack_binary_restoration_entry(payload_bytes)
search_entry = entry_mapping[filter_result.push_data_hash]
self.record_match_for_entry(filter_result, search_entry)
Expand Down
4 changes: 0 additions & 4 deletions electrumsv/data/api_servers_regtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"OUTPUT_SPENDS",
"TIP_FILTER"
],
"api_key": "t80Dp_dIk1kqkHK3P9R5cpDf67JfmNixNscexEYG0_xaCbYXKGNm4V_2HKr68ES5bytZ8F19IS0XbJlq41accQ==",
"api_key_required": true,
"last_try": 0.0,
"last_good": 0.0,
Expand All @@ -37,7 +36,6 @@
"TRANSACTION_REQUEST",
"OUTPUT_SPENDS"
],
"enabled_for_all_wallets": true,
"api_key_supported": false,
"last_try": 0.0,
"last_good": 0.0,
Expand All @@ -55,7 +53,6 @@
"TRANSACTION_REQUEST",
"OUTPUT_SPENDS"
],
"enabled_for_all_wallets": true,
"api_key_supported": false,
"last_try": 0.0,
"last_good": 0.0,
Expand All @@ -73,7 +70,6 @@
"TRANSACTION_REQUEST",
"OUTPUT_SPENDS"
],
"enabled_for_all_wallets": true,
"api_key_supported": false,
"last_try": 0.0,
"last_good": 0.0,
Expand Down
4 changes: 2 additions & 2 deletions electrumsv/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin):
notify_transactions_signal = pyqtSignal()
new_fx_quotes_signal = pyqtSignal()
new_fx_history_signal = pyqtSignal()
network_signal = pyqtSignal(str, object)
network_signal = pyqtSignal(object, object)
history_updated_signal = pyqtSignal()
network_status_signal = pyqtSignal()
account_created_signal = pyqtSignal(int, object)
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def _update_network_status(self) -> None:
text += f' {response_count:,d}/{request_count:,d}'
else:
if self._wallet.main_server is not None:
server_chain_tip = self._wallet.main_server.tip
server_chain_tip = self._wallet.main_server.tip_header
server_height = server_chain_tip.height if server_chain_tip else 0
server_lag = self.network.get_local_height() - server_height
if server_height == 0:
Expand Down

0 comments on commit 45c0bd0

Please sign in to comment.