def __init__(self, **kwargs):
        '''Get app settings from options'''
        self.make_commit = kwargs.pop('make_commit')
        self.password = kwargs.pop('password')
        self.signing_key = kwargs.pop('signing_key')
        self.testnet = kwargs.pop('testnet')
        self.wallet_path = kwargs.pop('wallet')

        script_config = read_config()
        if script_config:
            self.make_commit = (self.make_commit
                                or script_config.get('make_commit', False))
            self.signing_key = (self.signing_key
                                or script_config.get('signing_key', False))
            self.testnet = (self.testnet
                            or script_config.get('testnet', False))
            self.wallet_path = (self.wallet_path
                                or script_config.get('wallet', False))
        if self.wallet_path:
            self.wallet_path = os.path.expanduser(self.wallet_path)
        self.config_options = {'cwd': os.getcwd()}
        self.config_options['password'] = self.password
        self.config_options['testnet'] = self.testnet
        self.config_options['wallet_path'] = self.wallet_path
        self.config = SimpleConfig(self.config_options)
        if self.config.get('testnet'):
            constants.set_testnet()
        self.storage = WalletStorage(self.config.get_wallet_path())
Пример #2
0
 def test_valid_psbt_008(self):
     # Case: PSBT with `PSBT_GLOBAL_XPUB`.
     constants.set_mainnet()
     try:
         tx1 = tx_from_any(
             bytes.fromhex(
                 '70736274ff01009d0100000002710ea76ab45c5cb6438e607e59cc037626981805ae9e0dfd9089012abb0be5350100000000ffffffff190994d6a8b3c8c82ccbcfb2fba4106aa06639b872a8d447465c0d42588d6d670000000000ffffffff0200e1f505000000001976a914b6bc2c0ee5655a843d79afedd0ccc3f7dd64340988ac605af405000000001600141188ef8e4ce0449eaac8fb141cbf5a1176e6a088000000004f010488b21e039e530cac800000003dbc8a5c9769f031b17e77fea1518603221a18fd18f2b9a54c6c8c1ac75cbc3502f230584b155d1c7f1cd45120a653c48d650b431b67c5b2c13f27d7142037c1691027569c503100008000000080000000800001011f00e1f5050000000016001433b982f91b28f160c920b4ab95e58ce50dda3a4a220203309680f33c7de38ea6a47cd4ecd66f1f5a49747c6ffb8808ed09039243e3ad5c47304402202d704ced830c56a909344bd742b6852dccd103e963bae92d38e75254d2bb424502202d86c437195df46c0ceda084f2a291c3da2d64070f76bf9b90b195e7ef28f77201220603309680f33c7de38ea6a47cd4ecd66f1f5a49747c6ffb8808ed09039243e3ad5c1827569c5031000080000000800000008000000000010000000001011f00e1f50500000000160014388fb944307eb77ef45197d0b0b245e079f011de220202c777161f73d0b7c72b9ee7bde650293d13f095bc7656ad1f525da5fd2e10b11047304402204cb1fb5f869c942e0e26100576125439179ae88dca8a9dc3ba08f7953988faa60220521f49ca791c27d70e273c9b14616985909361e25be274ea200d7e08827e514d01220602c777161f73d0b7c72b9ee7bde650293d13f095bc7656ad1f525da5fd2e10b1101827569c5031000080000000800000008000000000000000000000220202d20ca502ee289686d21815bd43a80637b0698e1fbcdbe4caed445f6c1a0a90ef1827569c50310000800000008000000080000000000400000000'
             ))
         tx2 = tx_from_any(
             'cHNidP8BAJ0BAAAAAnEOp2q0XFy2Q45gflnMA3YmmBgFrp4N/ZCJASq7C+U1AQAAAAD/////GQmU1qizyMgsy8+y+6QQaqBmObhyqNRHRlwNQliNbWcAAAAAAP////8CAOH1BQAAAAAZdqkUtrwsDuVlWoQ9ea/t0MzD991kNAmIrGBa9AUAAAAAFgAUEYjvjkzgRJ6qyPsUHL9aEXbmoIgAAAAATwEEiLIeA55TDKyAAAAAPbyKXJdp8DGxfnf+oVGGAyIaGP0Y8rmlTGyMGsdcvDUC8jBYSxVdHH8c1FEgplPEjWULQxtnxbLBPyfXFCA3wWkQJ1acUDEAAIAAAACAAAAAgAABAR8A4fUFAAAAABYAFDO5gvkbKPFgySC0q5XljOUN2jpKIgIDMJaA8zx9446mpHzU7NZvH1pJdHxv+4gI7QkDkkPjrVxHMEQCIC1wTO2DDFapCTRL10K2hS3M0QPpY7rpLTjnUlTSu0JFAiAthsQ3GV30bAztoITyopHD2i1kBw92v5uQsZXn7yj3cgEiBgMwloDzPH3jjqakfNTs1m8fWkl0fG/7iAjtCQOSQ+OtXBgnVpxQMQAAgAAAAIAAAACAAAAAAAEAAAAAAQEfAOH1BQAAAAAWABQ4j7lEMH63fvRRl9CwskXgefAR3iICAsd3Fh9z0LfHK57nveZQKT0T8JW8dlatH1Jdpf0uELEQRzBEAiBMsftfhpyULg4mEAV2ElQ5F5rojcqKncO6CPeVOYj6pgIgUh9JynkcJ9cOJzybFGFphZCTYeJb4nTqIA1+CIJ+UU0BIgYCx3cWH3PQt8crnue95lApPRPwlbx2Vq0fUl2l/S4QsRAYJ1acUDEAAIAAAACAAAAAgAAAAAAAAAAAAAAiAgLSDKUC7iiWhtIYFb1DqAY3sGmOH7zb5MrtRF9sGgqQ7xgnVpxQMQAAgAAAAIAAAACAAAAAAAQAAAAA'
         )
         for tx in (tx1, tx2):
             self.assertEqual(1, len(tx.xpubs))
     finally:
         constants.set_testnet()
Пример #3
0
def main(**kwargs):
    input_file = kwargs.pop('input_file')
    output_file = kwargs.pop('output_file', None)
    inplace = kwargs.pop('inplace', False)
    dry_run = kwargs.pop('dry_run', False)
    testnet = kwargs.pop('testnet', False)

    if testnet:
        constants.set_testnet()
        DASH_ADDRTYPE_P2PKH = 140
        DASH_ADDRTYPE_P2SH = 19
        DASH_WIF_PREFIX = 239
    else:
        DASH_ADDRTYPE_P2PKH = 76
        DASH_ADDRTYPE_P2SH = 16
        DASH_WIF_PREFIX = 204

    net = constants.net

    if inplace:
        output_file = input_file

    olines = []
    total_sub = 0
    for ln, l in enumerate(open(input_file, 'r').read().splitlines()):
        pos = 0
        ol = ''

        while pos < len(l):
            m = ADDR_PATTERN.search(l, pos)
            if not m:
                ol += l[pos:]
                break

            ol += l[pos:m.start()]
            val = m.group()

            try:
                addrtype, h = dash_b58_address_to_hash160(val)
            except:
                h = None

            if h and addrtype == DASH_ADDRTYPE_P2PKH:
                new_val = hash160_to_b58_address(h, net.ADDRTYPE_P2PKH)
                total_sub += 1
            elif h and addrtype == DASH_ADDRTYPE_P2SH:
                new_val = hash160_to_b58_address(h, net.ADDRTYPE_P2SH)
                total_sub += 1
            else:
                new_val = None

            if not new_val:
                try:
                    txin_type, privkey, compressed = \
                        deserialize_dash_privkey(val, DASH_WIF_PREFIX)
                except Exception as e:
                    privkey = None

                if privkey:
                    new_val = serialize_privkey(privkey,
                                                compressed,
                                                txin_type,
                                                internal_use=True)

            if dry_run and new_val:
                print('line %s, col %s: %s => %s' %
                      (ln, m.start(), val, new_val))

            ol += new_val if new_val else val
            pos = m.end()

        olines.append(ol)

    out = '\n'.join(olines)
    if not output_file:
        print(out)
    elif not dry_run:
        with open(output_file, 'w') as wfd:
            wfd.write('%s\n' % out)
    else:
        print('Total sub count:', total_sub)
Пример #4
0
import asyncio

from electrum_zcash.simple_config import SimpleConfig
from electrum_zcash import constants
from electrum_zcash.daemon import Daemon
from electrum_zcash.storage import WalletStorage
from electrum_zcash.wallet import Wallet, create_new_wallet
from electrum_zcash.wallet_db import WalletDB
from electrum_zcash.commands import Commands
from electrum_zcash.util import create_and_start_event_loop, log_exceptions

loop, stopping_fut, loop_thread = create_and_start_event_loop()

config = SimpleConfig({"testnet":
                       True})  # to use ~/.electrum-zcash/testnet as datadir
constants.set_testnet()  # to set testnet magic bytes
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
assert network.asyncio_loop.is_running()

# get wallet on disk
wallet_dir = os.path.dirname(config.get_wallet_path())
wallet_path = os.path.join(wallet_dir, "test_wallet")
if not os.path.exists(wallet_path):
    create_new_wallet(path=wallet_path, config=config)

# open wallet
wallet = daemon.load_wallet(wallet_path, password=None, manual_upgrades=False)
wallet.start_network(network)

# you can use ~CLI commands by accessing command_runner
Пример #5
0
 def setUpClass(cls):
     super().setUpClass()
     constants.set_testnet()