mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 01:35:20 +00:00
move NotificationSession
This commit is contained in:
parent
234273809a
commit
5ef04a039b
3 changed files with 24 additions and 24 deletions
|
@ -32,6 +32,7 @@ import traceback
|
||||||
import aiorpcx
|
import aiorpcx
|
||||||
import asyncio
|
import asyncio
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
|
from aiorpcx import ClientSession, Notification
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
@ -43,8 +44,29 @@ from . import util
|
||||||
from . import x509
|
from . import x509
|
||||||
from . import pem
|
from . import pem
|
||||||
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
||||||
from .util import NotificationSession
|
|
||||||
from . import blockchain
|
from . import blockchain
|
||||||
|
from .blockchain import deserialize_header
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationSession(ClientSession):
|
||||||
|
|
||||||
|
def __init__(self, scripthash, header, *args, **kwargs):
|
||||||
|
super(NotificationSession, self).__init__(*args, **kwargs)
|
||||||
|
self.scripthash = scripthash
|
||||||
|
self.header = header
|
||||||
|
|
||||||
|
@aiosafe
|
||||||
|
async def handle_request(self, request):
|
||||||
|
if isinstance(request, Notification):
|
||||||
|
if request.method == 'blockchain.scripthash.subscribe' and self.scripthash is not None:
|
||||||
|
args = request.args
|
||||||
|
await self.scripthash.put((args[0], args[1]))
|
||||||
|
elif request.method == 'blockchain.headers.subscribe' and self.header is not None:
|
||||||
|
deser = deserialize_header(bfh(request.args[0]['hex']), request.args[0]['height'])
|
||||||
|
await self.header.put(deser)
|
||||||
|
else:
|
||||||
|
assert False, request.method
|
||||||
|
|
||||||
|
|
||||||
class Interface(PrintError):
|
class Interface(PrintError):
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ import concurrent.futures
|
||||||
|
|
||||||
# from .bitcoin import Hash, hash_encode
|
# from .bitcoin import Hash, hash_encode
|
||||||
from .transaction import Transaction
|
from .transaction import Transaction
|
||||||
from .util import ThreadJob, bh2u, PrintError, aiosafe, bfh, NotificationSession
|
from .util import ThreadJob, bh2u, PrintError, aiosafe, bfh
|
||||||
from .bitcoin import address_to_scripthash
|
from .bitcoin import address_to_scripthash
|
||||||
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ from locale import localeconv
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
from aiorpcx import ClientSession, Notification
|
|
||||||
import urllib.request, urllib.parse, urllib.error
|
import urllib.request, urllib.parse, urllib.error
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
|
@ -948,24 +947,3 @@ VerifiedTxInfo = NamedTuple("VerifiedTxInfo", [("height", int),
|
||||||
("timestamp", int),
|
("timestamp", int),
|
||||||
("txpos", int),
|
("txpos", int),
|
||||||
("header_hash", str)])
|
("header_hash", str)])
|
||||||
|
|
||||||
from .blockchain import deserialize_header
|
|
||||||
|
|
||||||
class NotificationSession(ClientSession):
|
|
||||||
|
|
||||||
def __init__(self, scripthash, header, *args, **kwargs):
|
|
||||||
super(NotificationSession, self).__init__(*args, **kwargs)
|
|
||||||
self.scripthash = scripthash
|
|
||||||
self.header = header
|
|
||||||
|
|
||||||
@aiosafe
|
|
||||||
async def handle_request(self, request):
|
|
||||||
if isinstance(request, Notification):
|
|
||||||
if request.method == 'blockchain.scripthash.subscribe' and self.scripthash is not None:
|
|
||||||
args = request.args
|
|
||||||
await self.scripthash.put((args[0], args[1]))
|
|
||||||
elif request.method == 'blockchain.headers.subscribe' and self.header is not None:
|
|
||||||
deser = deserialize_header(bfh(request.args[0]['hex']), request.args[0]['height'])
|
|
||||||
await self.header.put(deser)
|
|
||||||
else:
|
|
||||||
assert False, request.method
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue