Beispiel #1
0
async def f():
    try:
        sh = bitcoin.address_to_scripthash(addr)
        hist = await network.get_history_for_scripthash(sh)
        print_msg(json_encode(hist))
    finally:
        stopping_fut.set_result(1)
Beispiel #2
0
 def prompt_auth(self, msg):
     import getpass
     print_msg(msg)
     response = getpass.getpass('')
     if len(response) == 0:
         return None
     return response
Beispiel #3
0
 def prompt_auth(self, msg):
     import getpass
     print_msg(msg)
     response = getpass.getpass('')
     if len(response) == 0:
         return None
     return response
Beispiel #4
0
async def f():
    try:
        await network.interface.session.subscribe('blockchain.headers.subscribe', [], header_queue)
        # 3. wait for results
        while network.is_connected():
            header = await header_queue.get()
            print_msg(json_encode(header))
    finally:
        stopping_fut.set_result(1)
Beispiel #5
0
 def get_pin(self, msg):
     t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
     print_msg(msg)
     print_msg("a b c\nd e f\ng h i\n-----")
     o = raw_input()
     try:
         return ''.join(map(lambda x: t[x], o))
     except KeyError as e:
         raise Exception("Character {} not in matrix!".format(e)) from e
Beispiel #6
0
    def runCommand(self):
        command = self.getCommand()
        self.addToHistory(command)

        command = self.getConstruct(command)

        if command:
            tmp_stdout = sys.stdout

            class stdoutProxy():
                def __init__(self, write_func):
                    self.write_func = write_func
                    self.skip = False

                def flush(self):
                    pass

                def write(self, text):
                    if not self.skip:
                        stripped_text = text.rstrip('\n')
                        self.write_func(stripped_text)
                        QtCore.QCoreApplication.processEvents()
                    self.skip = not self.skip

            if type(self.namespace.get(command)) == type(lambda: None):
                self.appendPlainText(
                    "'{}' is a function. Type '{}()' to use it in the Python console."
                    .format(command, command))
                self.newPrompt()
                return

            sys.stdout = stdoutProxy(self.appendPlainText)
            try:
                try:
                    # eval is generally considered bad practice. use it wisely!
                    result = eval(command, self.namespace, self.namespace)
                    if result is not None:
                        if self.is_json:
                            util.print_msg(util.json_encode(result))
                        else:
                            self.appendPlainText(repr(result))
                except SyntaxError:
                    # exec is generally considered bad practice. use it wisely!
                    exec(command, self.namespace, self.namespace)
            except SystemExit:
                self.close()
            except BaseException:
                traceback_lines = traceback.format_exc().split('\n')
                # Remove traceback mentioning this file, and a linebreak
                for i in (3, 2, 1, -1):
                    traceback_lines.pop(i)
                self.appendPlainText('\n'.join(traceback_lines))
            sys.stdout = tmp_stdout
        self.newPrompt()
        self.set_json(False)
Beispiel #7
0
    def runCommand(self):
        command = self.getCommand()
        self.addToHistory(command)

        command = self.getConstruct(command)

        if command:
            tmp_stdout = sys.stdout

            class stdoutProxy():
                def __init__(self, write_func):
                    self.write_func = write_func
                    self.skip = False

                def flush(self):
                    pass

                def write(self, text):
                    if not self.skip:
                        stripped_text = text.rstrip('\n')
                        self.write_func(stripped_text)
                        QtCore.QCoreApplication.processEvents()
                    self.skip = not self.skip

            if type(self.namespace.get(command)) == type(lambda:None):
                self.appendPlainText("'{}' is a function. Type '{}()' to use it in the Python console."
                                     .format(command, command))
                self.newPrompt()
                return

            sys.stdout = stdoutProxy(self.appendPlainText)
            try:
                try:
                    # eval is generally considered bad practice. use it wisely!
                    result = eval(command, self.namespace, self.namespace)
                    if result != None:
                        if self.is_json:
                            util.print_msg(util.json_encode(result))
                        else:
                            self.appendPlainText(repr(result))
                except SyntaxError:
                    # exec is generally considered bad practice. use it wisely!
                    exec(command, self.namespace, self.namespace)
            except SystemExit:
                self.close()
            except BaseException:
                traceback_lines = traceback.format_exc().split('\n')
                # Remove traceback mentioning this file, and a linebreak
                for i in (3,2,1,-1):
                    traceback_lines.pop(i)
                self.appendPlainText('\n'.join(traceback_lines))
            sys.stdout = tmp_stdout
        self.newPrompt()
        self.set_json(False)
Beispiel #8
0
    def _send(self, parent, blob):
        def sender_thread():
            with self._audio_interface() as interface:
                src = BytesIO(blob)
                dst = interface.player()
                amodem.main.send(config=self.modem_config, src=src, dst=dst)

        print_msg('Sending:', repr(blob))
        blob = zlib.compress(blob.encode('ascii'))

        kbps = self.modem_config.modem_bps / 1e3
        msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps)
        WaitingDialog(parent, msg, sender_thread)
Beispiel #9
0
    def _send(self, parent, blob):
        def sender_thread():
            with self._audio_interface() as interface:
                src = BytesIO(blob)
                dst = interface.player()
                amodem.main.send(config=self.modem_config, src=src, dst=dst)

        print_msg('Sending:', repr(blob))
        blob = zlib.compress(blob.encode('ascii'))

        kbps = self.modem_config.modem_bps / 1e3
        msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps)
        WaitingDialog(parent, msg, sender_thread)
Beispiel #10
0
 def get_pin(self, msg):
     t = {
         'a': '7',
         'b': '8',
         'c': '9',
         'd': '4',
         'e': '5',
         'f': '6',
         'g': '1',
         'h': '2',
         'i': '3'
     }
     print_msg(msg)
     print_msg("a b c\nd e f\ng h i\n-----")
     o = raw_input()
     return ''.join(map(lambda x: t[x], o))
    def _send(self, parent, blob):
        def sender_thread():
            try:
                with self._audio_interface() as interface:
                    src = BytesIO(blob)
                    dst = interface.player()
                    amodem.main.send(config=self.modem_config, src=src, dst=dst)
            except Exception:
                traceback.print_exc()

        print_msg('Sending:', repr(blob))
        blob = zlib.compress(blob)

        kbps = self.modem_config.modem_bps / 1e3
        msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps)
        return WaitingDialog(parent=parent, message=msg, run_task=sender_thread)
Beispiel #12
0
 def get_pin(self, msg):
     t = {
         'a': '7',
         'b': '8',
         'c': '9',
         'd': '4',
         'e': '5',
         'f': '6',
         'g': '1',
         'h': '2',
         'i': '3'
     }
     print_msg(msg)
     print_msg("a b c\nd e f\ng h i\n-----")
     o = raw_input()
     try:
         return ''.join(map(lambda x: t[x], o))
     except KeyError as e:
         raise Exception("Character {} not in matrix!".format(e)) from e
Beispiel #13
0
    def _send(self, parent, blob):
        def sender_thread():
            try:
                with self._audio_interface() as interface:
                    src = BytesIO(blob)
                    dst = interface.player()
                    amodem.main.send(config=self.modem_config,
                                     src=src,
                                     dst=dst)
            except Exception:
                traceback.print_exc()

        print_msg('Sending:', repr(blob))
        blob = zlib.compress(blob)

        kbps = self.modem_config.modem_bps / 1e3
        msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps)
        return WaitingDialog(parent=parent,
                             message=msg,
                             run_task=sender_thread)
Beispiel #14
0
 def get_passphrase(self, msg):
     import getpass
     print_msg(msg)
     return getpass.getpass('')
Beispiel #15
0
 def get_pin(self, msg):
     t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
     print_msg(msg)
     print_msg("a b c\nd e f\ng h i\n-----")
     o = raw_input()
     return ''.join(map(lambda x: t[x], o))
 def on_success(blob):
     if blob:
         blob = zlib.decompress(blob)
         print_msg('Received:', repr(blob))
         parent.setText(blob)
Beispiel #17
0
#!/usr/bin/env python3

# A simple script that connects to a server and displays block headers

import time
from .. import SimpleConfig, Network
from electrum_dash.util import print_msg, json_encode

# start network
c = SimpleConfig()
network = Network(c)
network.start()

# wait until connected
while network.is_connecting():
    time.sleep(0.1)

if not network.is_connected():
    print_msg("daemon is not connected")
    sys.exit(1)

# 2. send the subscription
callback = lambda response: print_msg(json_encode(response.get('result')))
network.send([('server.version',["block_headers script", "1.2"])], callback)
network.subscribe_to_headers(callback)

# 3. wait for results
while network.is_connected():
    time.sleep(1)
Beispiel #18
0
 def get_passphrase(self, msg, confirm):
     import getpass
     print_msg(msg)
     return getpass.getpass('')
Beispiel #19
0
 def yes_no_question(self, msg):
     print_msg(msg)
     return raw_input() in 'yY'
Beispiel #20
0
 def on_finished(blob):
     if blob:
         blob = zlib.decompress(blob).decode('ascii')
         print_msg('Received:', repr(blob))
         parent.setText(blob)
Beispiel #21
0
 def show_error(self, msg, blocking=False):
     print_msg(msg)
Beispiel #22
0
 def show_error(self, msg, blocking=False):
     print_msg(msg)
Beispiel #23
0
#!/usr/bin/env python3

import sys
from .. import Network
from electrum_dash.util import json_encode, print_msg
from electrum_dash import bitcoin

try:
    addr = sys.argv[1]
except Exception:
    print("usage: get_history <dash_address>")
    sys.exit(1)

n = Network()
n.start()
_hash = bitcoin.address_to_scripthash(addr)
h = n.get_history_for_scripthash(_hash)
print_msg(json_encode(h))
Beispiel #24
0
 def on_finished(blob):
     if blob:
         blob = zlib.decompress(blob).decode('ascii')
         print_msg('Received:', repr(blob))
         parent.setText(blob)
Beispiel #25
0
 async def _on_address_status(self, addr, status):
     print_msg(f"addr {addr}, status {status}")
Beispiel #26
0
 def show_error(self, msg):
     print_msg(msg)
Beispiel #27
0
 def show_message(self, msg):
     print_msg(msg)
Beispiel #28
0
 def show_message(self, msg, on_cancel=None):
     print_msg(msg)
Beispiel #29
0
from electrum_dash.network import Network
from electrum_dash.util import print_msg, json_encode, create_and_start_event_loop, log_exceptions
from electrum_dash.simple_config import SimpleConfig

config = SimpleConfig()

# start network
loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()

# wait until connected
while not network.is_connected():
    time.sleep(1)
    print_msg("waiting for network to get connected...")

header_queue = asyncio.Queue()

@log_exceptions
async def f():
    try:
        await network.interface.session.subscribe('blockchain.headers.subscribe', [], header_queue)
        # 3. wait for results
        while network.is_connected():
            header = await header_queue.get()
            print_msg(json_encode(header))
    finally:
        stopping_fut.set_result(1)

# 2. send the subscription
Beispiel #30
0
 def yes_no_question(self, msg):
     print_msg(msg)
     return raw_input() in 'yY'
Beispiel #31
0
 def show_message(self, msg, on_cancel=None):
     print_msg(msg)
Beispiel #32
0
 def on_success(blob):
     if blob:
         blob = zlib.decompress(blob)
         print_msg('Received:', repr(blob))
         parent.setText(blob)
Beispiel #33
0
 def show_message(self, msg):
     print_msg(msg)
#!/usr/bin/env python3

# A simple script that connects to a server and displays block headers

import time
from .. import SimpleConfig, Network
from electrum_dash.util import print_msg, json_encode

# start network
c = SimpleConfig()
network = Network(c)
network.start()

# wait until connected
while network.is_connecting():
    time.sleep(0.1)

if not network.is_connected():
    print_msg("daemon is not connected")
    sys.exit(1)

# 2. send the subscription
callback = lambda response: print_msg(json_encode(response.get('result')))
network.send([('server.version', ["block_headers script", "1.2"])], callback)
network.subscribe_to_headers(callback)

# 3. wait for results
while network.is_connected():
    time.sleep(1)
Beispiel #35
0
def debug_msg(*args):
    if DEBUG:
        print_msg(*args)        
Beispiel #36
0
def debug_msg(*args):
    if DEBUG:
        print_msg(*args)