예제 #1
0
    def __init__(self, network: Network, config) -> None:
        super().__init__(flags=Qt.WindowSystemMenuHint | Qt.WindowTitleHint
                         | Qt.WindowCloseButtonHint)
        self.setWindowTitle(_('Network'))
        self.setMinimumSize(500, 200)
        self.resize(560, 400)
        self._nlayout = NetworkChoiceLayout(network, config)

        buttons_layout = Buttons(CloseButton(self))
        buttons_layout.add_left_button(
            HelpDialogButton(self, "misc", "network-dialog"))

        vbox = QVBoxLayout(self)
        vbox.setSizeConstraint(QVBoxLayout.SetFixedSize)
        vbox.addLayout(self._nlayout.layout())
        vbox.addLayout(buttons_layout)

        self.network_updated_signal.connect(self.on_update)
        network.register_callback(self.on_network, ['updated', 'sessions'])
예제 #2
0
def run_non_RPC(config):
    cmdname = config.get('cmd')

    storage = WalletStorage(config.get_wallet_path())
    if storage.file_exists():
        sys.exit("Error: Remove the existing wallet first!")

    def password_dialog():
        return prompt_password(
            "Password (hit return if you do not wish to encrypt your wallet):")

    if cmdname == 'restore':
        text = config.get('text').strip()
        passphrase = config.get('passphrase', '')
        password = password_dialog() if keystore.is_private(text) else None
        if keystore.is_address_list(text):
            wallet = ImportedAddressWallet.from_text(storage, text)
        elif keystore.is_private_key_list(text):
            wallet = ImportedPrivkeyWallet.from_text(storage, text, password)
        else:
            if keystore.is_seed(text):
                k = keystore.from_seed(text, passphrase, False)
            elif keystore.is_master_key(text):
                k = keystore.from_master_key(text)
            else:
                sys.exit("Error: Seed or key not recognized")
            if password:
                k.update_password(None, password)
            storage.put('keystore', k.dump())
            storage.put('wallet_type', 'standard')
            storage.put('use_encryption', bool(password))
            storage.write()
            wallet = Wallet(storage)
        if not config.get('offline'):
            network = Network(config)
            network.start()
            wallet.start_threads(network)
            print("Recovering wallet...")
            wallet.synchronize()
            wallet.wait_until_synchronized()
            msg = ("Recovery successful" if wallet.is_found() else
                   "Found no history for this wallet")
        else:
            msg = ("This wallet was restored offline. "
                   "It may contain more addresses than displayed.")
        print(msg)

    elif cmdname == 'create':
        password = password_dialog()
        passphrase = config.get('passphrase', '')
        seed_type = 'standard'
        seed = Mnemonic('en').make_seed(seed_type)
        k = keystore.from_seed(seed, passphrase, False)
        storage.put('keystore', k.dump())
        storage.put('wallet_type', 'standard')
        wallet = Wallet(storage)
        wallet.update_password(None, password, True)
        wallet.synchronize()
        print("Your wallet generation seed is:\n\"%s\"" % seed)
        print("Please keep it in a safe place; if you lose it, "
              "you will not be able to restore your wallet.")

    wallet.storage.write()
    print("Wallet saved in '%s'" % wallet.storage.path)
    sys.exit(0)
예제 #3
0
#!/usr/bin/env python3

import sys

from electrumsv.network import Network
from electrumsv.util import json_encode
from electrumsv.bitcoin import address_from_string

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

n = Network()
n.start()
sh = address_from_string(addr).to_scripthash_hex()
h = n.synchronous_get(('blockchain.scripthash.get_history', [sh]))
print(json_encode(h))
예제 #4
0
파일: main.py 프로젝트: Zwilla/electrumsv
def run_non_RPC(config):
    cmdname = config.get('cmd')

    storage = WalletStorage(config.get_wallet_path())
    if storage.file_exists():
        sys.exit("Error: Remove the existing wallet first!")

    def password_dialog():
        return prompt_password(
            "Password (hit return if you do not wish to encrypt your wallet):")

    if cmdname == 'restore':
        text = config.get('text').strip()
        passphrase = config.get('passphrase', '')
        password = password_dialog() if keystore.is_private(text) else None

        parent_wallet = ParentWallet.as_legacy_wallet_container(storage)
        if keystore.is_address_list(text):
            legacy_wallet = ImportedAddressWallet.from_text(
                parent_wallet, text)
        elif keystore.is_private_key_list(text):
            legacy_wallet = ImportedPrivkeyWallet.from_text(
                parent_wallet, text)
        else:
            if keystore.is_seed(text):
                k = keystore.from_seed(text, passphrase, False)
            elif keystore.is_master_key(text):
                k = keystore.from_master_key(text)
            else:
                sys.exit("Error: Seed or key not recognized")

            keystore_usage = parent_wallet.add_keystore(k.dump())
            Standard_Wallet.create_within_parent(
                parent_wallet, keystore_usage=[keystore_usage])

        if password:
            parent_wallet.update_password(None, password)

        if not config.get('offline'):
            network = Network()
            network.add_wallet(parent_wallet)
            print("Recovering wallet...")
            parent_wallet.synchronize()
            msg = ("Recovery successful" if parent_wallet.has_usage() else
                   "Found no history for this wallet")
        else:
            msg = ("This wallet was restored offline. "
                   "It may contain more addresses than displayed.")
        print(msg)

    elif cmdname == 'create':
        password = password_dialog()
        passphrase = config.get('passphrase', '')
        seed_type = 'standard'
        seed = Mnemonic('en').make_seed(seed_type)
        k = keystore.from_seed(seed, passphrase, False)

        parent_wallet = ParentWallet.as_legacy_wallet_container(storage)
        keystore_usage = parent_wallet.add_keystore(k.dump())
        Standard_Wallet.create_within_parent(parent_wallet,
                                             keystore_usage=[keystore_usage])

        parent_wallet.update_password(None, password)
        parent_wallet.synchronize()
        print("Your wallet generation seed is:\n\"%s\"" % seed)
        print("Please keep it in a safe place; if you lose it, "
              "you will not be able to restore your wallet.")

    parent_wallet.save_storage()
    print("Wallet saved in '%s'" % parent_wallet.get_storage_path())
    sys.exit(0)
예제 #5
0
#!/usr/bin/env python

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

import sys
import time

from electrumsv.simple_config import SimpleConfig
from electrumsv.network import Network
from electrumsv.util import 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("daemon is not connected")
    sys.exit(1)

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

# 3. wait for results
while network.is_connected():
예제 #6
0
import sys
import time
from electrumsv.simple_config import SimpleConfig
from electrumsv.network import Network
from electrumsv.util import json_encode
from electrumsv.address import Address

try:
    addr = Address.from_string(sys.argv[1])
except Exception:
    print("usage: watch_address <bitcoin_address>")
    sys.exit(1)

# 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("daemon is not connected")
    sys.exit(1)

# 2. send the subscription
sh = addr.to_scripthash_hex()
callback = lambda response: print(json_encode(response.get('result')))
network.send([('blockchain.scripthash.subscribe', [sh])], callback)