From 455b4043b8ec9aef89c956b73495b69dd26f88d5 Mon Sep 17 00:00:00 2001
From: Lex Berezhny <lex@damoti.com>
Date: Tue, 4 Aug 2020 11:33:39 -0400
Subject: [PATCH 1/3] new resolve

---
 lbry/extras/daemon/daemon.py |  2 ++
 lbry/wallet/ledger.py        |  5 ++++-
 lbry/wallet/network.py       | 12 ++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py
index 2796719e2..4d7fcc3f6 100644
--- a/lbry/extras/daemon/daemon.py
+++ b/lbry/extras/daemon/daemon.py
@@ -986,10 +986,12 @@ class Daemon(metaclass=JSONRPCServerType):
                     [--include_sent_supports]
                     [--include_sent_tips]
                     [--include_received_tips]
+                    [--new_sdk_server=<new_sdk_server>]
 
         Options:
             --urls=<urls>              : (str, list) one or more urls to resolve
             --wallet_id=<wallet_id>    : (str) wallet to check for claim purchase reciepts
+           --new_sdk_server=<new_sdk_server> : (str) use the new SDK server (EXPERIMENTAL)
            --include_purchase_receipt  : (bool) lookup and include a receipt if this wallet
                                                 has purchased the claim being resolved
             --include_is_my_output     : (bool) lookup and include a boolean indicating
diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py
index 50d68b2ac..3cae9b845 100644
--- a/lbry/wallet/ledger.py
+++ b/lbry/wallet/ledger.py
@@ -923,7 +923,10 @@ class Ledger(metaclass=LedgerRegistry):
         return txos, blocked, outputs.offset, outputs.total
 
     async def resolve(self, accounts, urls, **kwargs):
-        resolve = partial(self.network.retriable_call, self.network.resolve)
+        if 'new_sdk_server' in kwargs:
+            resolve = partial(self.network.new_resolve, kwargs.pop('new_sdk_server'))
+        else:
+            resolve = partial(self.network.retriable_call, self.network.resolve)
         urls_copy = list(urls)
         txos = []
         while urls_copy:
diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py
index 262f46579..29f630c10 100644
--- a/lbry/wallet/network.py
+++ b/lbry/wallet/network.py
@@ -5,6 +5,8 @@ from time import perf_counter
 from operator import itemgetter
 from typing import Dict, Optional, Tuple
 
+import aiohttp
+
 from lbry import __version__
 from lbry.error import IncompatibleWalletServerError
 from lbry.wallet.rpc import RPCSession as BaseClientSession, Connector, RPCError, ProtocolError
@@ -181,6 +183,8 @@ class Network:
             'blockchain.address.subscribe': self._on_status_controller,
         }
 
+        self.aiohttp_session: Optional[aiohttp.ClientSession] = None
+
     @property
     def config(self):
         return self.ledger.config
@@ -207,6 +211,7 @@ class Network:
 
     async def start(self):
         self.running = True
+        self.aiohttp_session = aiohttp.ClientSession()
         self._switch_task = asyncio.ensure_future(self.switch_forever())
         # this may become unnecessary when there are no more bugs found,
         # but for now it helps understanding log reports
@@ -217,6 +222,7 @@ class Network:
     async def stop(self):
         if self.running:
             self.running = False
+            await self.aiohttp_session.close()
             self._switch_task.cancel()
             self.session_pool.stop()
 
@@ -316,6 +322,12 @@ class Network:
     def claim_search(self, **kwargs):
         return self.rpc('blockchain.claimtrie.search', kwargs)
 
+    async def new_resolve(self, server, urls):
+        message = {"method": "resolve", "params": {"urls": urls, "protobuf": True}}
+        async with self.aiohttp_session.post(server, json=message) as r:
+            result = await r.json()
+            return result['result']
+
 
 class SessionPool:
 

From 9c5f940b00f108923fcb98c66eddaf02bebebf91 Mon Sep 17 00:00:00 2001
From: Lex Berezhny <lex@damoti.com>
Date: Tue, 4 Aug 2020 12:11:02 -0400
Subject: [PATCH 2/3] claim search forwarding to new sdk

---
 lbry/extras/daemon/daemon.py |  2 ++
 lbry/wallet/ledger.py        | 14 +++++++++-----
 lbry/wallet/network.py       |  7 +++++++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py
index 4d7fcc3f6..55f72afea 100644
--- a/lbry/extras/daemon/daemon.py
+++ b/lbry/extras/daemon/daemon.py
@@ -2329,6 +2329,7 @@ class Daemon(metaclass=JSONRPCServerType):
                          [--not_locations=<not_locations>...]
                          [--order_by=<order_by>...] [--page=<page>] [--page_size=<page_size>]
                          [--wallet_id=<wallet_id>] [--include_purchase_receipt] [--include_is_my_output]
+                         [--new_sdk_server=<new_sdk_server>]
 
         Options:
             --name=<name>                   : (str) claim name (normalized)
@@ -2434,6 +2435,7 @@ class Daemon(metaclass=JSONRPCServerType):
                                                      has purchased the claim
             --include_is_my_output          : (bool) lookup and include a boolean indicating
                                                      if claim being resolved is yours
+           --new_sdk_server=<new_sdk_server> : (str) use the new SDK server (EXPERIMENTAL)
 
         Returns: {Paginated[Output]}
         """
diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py
index 3cae9b845..d1a5b69c3 100644
--- a/lbry/wallet/ledger.py
+++ b/lbry/wallet/ledger.py
@@ -922,9 +922,9 @@ class Ledger(metaclass=LedgerRegistry):
                         txo.received_tips = tips
         return txos, blocked, outputs.offset, outputs.total
 
-    async def resolve(self, accounts, urls, **kwargs):
-        if 'new_sdk_server' in kwargs:
-            resolve = partial(self.network.new_resolve, kwargs.pop('new_sdk_server'))
+    async def resolve(self, accounts, urls, new_sdk_server=None, **kwargs):
+        if new_sdk_server:
+            resolve = partial(self.network.new_resolve, new_sdk_server)
         else:
             resolve = partial(self.network.retriable_call, self.network.resolve)
         urls_copy = list(urls)
@@ -946,9 +946,13 @@ class Ledger(metaclass=LedgerRegistry):
 
     async def claim_search(
             self, accounts, include_purchase_receipt=False, include_is_my_output=False,
-            **kwargs) -> Tuple[List[Output], dict, int, int]:
+            new_sdk_server=None, **kwargs) -> Tuple[List[Output], dict, int, int]:
+        if new_sdk_server:
+            claim_search = partial(self.network.new_claim_search, new_sdk_server)
+        else:
+            claim_search = self.network.claim_search
         return await self._inflate_outputs(
-            self.network.claim_search(**kwargs), accounts,
+            claim_search(**kwargs), accounts,
             include_purchase_receipt=include_purchase_receipt,
             include_is_my_output=include_is_my_output
         )
diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py
index 29f630c10..76d079895 100644
--- a/lbry/wallet/network.py
+++ b/lbry/wallet/network.py
@@ -328,6 +328,13 @@ class Network:
             result = await r.json()
             return result['result']
 
+    async def new_claim_search(self, server, **kwargs):
+        kwargs['protobuf'] = True
+        message = {"method": "claim_search", "params": kwargs}
+        async with self.aiohttp_session.post(server, json=message) as r:
+            result = await r.json()
+            return result['result']
+
 
 class SessionPool:
 

From 91194bf4229106f65c57909f38fc860f3b35b7b4 Mon Sep 17 00:00:00 2001
From: Lex Berezhny <lex@damoti.com>
Date: Tue, 4 Aug 2020 14:12:40 -0400
Subject: [PATCH 3/3] doc fix

---
 lbry/extras/daemon/daemon.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py
index 55f72afea..9fcf5d5a2 100644
--- a/lbry/extras/daemon/daemon.py
+++ b/lbry/extras/daemon/daemon.py
@@ -991,7 +991,7 @@ class Daemon(metaclass=JSONRPCServerType):
         Options:
             --urls=<urls>              : (str, list) one or more urls to resolve
             --wallet_id=<wallet_id>    : (str) wallet to check for claim purchase reciepts
-           --new_sdk_server=<new_sdk_server> : (str) use the new SDK server (EXPERIMENTAL)
+           --new_sdk_server=<new_sdk_server> : (str) URL of the new SDK server (EXPERIMENTAL)
            --include_purchase_receipt  : (bool) lookup and include a receipt if this wallet
                                                 has purchased the claim being resolved
             --include_is_my_output     : (bool) lookup and include a boolean indicating
@@ -2435,7 +2435,7 @@ class Daemon(metaclass=JSONRPCServerType):
                                                      has purchased the claim
             --include_is_my_output          : (bool) lookup and include a boolean indicating
                                                      if claim being resolved is yours
-           --new_sdk_server=<new_sdk_server> : (str) use the new SDK server (EXPERIMENTAL)
+           --new_sdk_server=<new_sdk_server> : (str) URL of the new SDK server (EXPERIMENTAL)
 
         Returns: {Paginated[Output]}
         """