Ejemplo n.º 1
0
 def _start_wizard_to_select_or_create_wallet(
         self, path) -> Optional[Abstract_Wallet]:
     wizard = InstallWizard(self.config, self.app, self.plugins)
     try:
         path, storage = wizard.select_storage(path, self.daemon.get_wallet)
         # storage is None if file does not exist
         if storage is None:
             wizard.path = path  # needed by trustedcoin plugin
             wizard.run('new')
             storage = wizard.create_storage(path)
         else:
             wizard.run_upgrades(storage)
     except (UserCancelled, GoBack):
         return
     except WalletAlreadyOpenInMemory as e:
         return e.wallet
     finally:
         wizard.terminate()
     # return if wallet creation is not complete
     if storage is None or storage.get_action():
         return
     wallet = Wallet(storage)
     wallet.start_threads(self.daemon.network)
     self.daemon.add_wallet(wallet)
     return wallet
Ejemplo n.º 2
0
    def genContractWallet(self, nickname=None):
        path = os.path.join(self.topDir, 'wallets')
        if not os.path.isdir(path):
            os.mkdir(path)
        if nickname:
            for i, c in enumerate(self.contracts):
                if c["nickname"] == nickname:
                    print_msg("{} contract exists.".format(nickname))
                    return self.getContractWallet(i), c
        #print(type(self.contracts))
        #this next loop generates a wallet name that isn't in use yet.
        if self.contracts == []:
            walletFile = os.path.join(self.topDir, 'wallets',
                                      'contract0.wallet')
        else:
            walletNames = []
            for c in self.contracts:
                #print(c)
                walletNames.append(c['walletFile'])
            for i in range(len(walletNames) + 1):
                walletFile = os.path.join(self.topDir, 'wallets',
                                          'contract' + str(i) + '.wallet')
                if walletFile not in walletNames:
                    break
        storage = WalletStorage(walletFile)
        seed_type = 'standard'
        seed = Mnemonic('en').make_seed(seed_type)
        k = keystore.from_seed(seed, '', False)
        storage.put('keystore', k.dump())
        storage.put('wallet_type', 'standard')
        wallet = Wallet(storage)
        wallet.set_schnorr_enabled(False)
        wallet.update_password(None, '', True)
        wallet.synchronize()
        print_msg("Your wallet generation seed is:\n\"%s\"" % seed)
        print_msg(
            "Please keep it in a safe place; if you lose it, you will not be able to restore your wallet."
        )

        wallet.storage.write()
        print_msg("Wallet saved in '%s'" % wallet.storage.path)

        my_addr = wallet.get_unused_address()
        my_addr_index = wallet.receiving_addresses.index(my_addr)
        #my_addr_index is always going to be 0 if the wallet is unused, so maybe previous line unnecessary
        my_pubkey = wallet.derive_pubkeys(False, my_addr_index)
        my_x_pubkey = self.get_x_pubkey(my_addr_index, wallet)
        self.contracts.append({
            'walletFile': wallet.storage.path,
            "my_addr": my_addr.to_ui_string(),
            "my_pubkey": my_pubkey,
            "my_x_pubkey": my_x_pubkey,
            "nickname": nickname,
            "label": ""
        })
        #print(self.contracts)
        self.updateContracts()
        self.multiWallets.append(None)
        return wallet, self.contracts[-1]
Ejemplo n.º 3
0
    def test(self):
        stor = WalletStorage(
            '/home/ilia/.electron-cash/wallets/test/default_wallet')
        wal = Wallet(stor)
        wal.set_schnorr_enabled(False)
        stor2 = WalletStorage(
            '/home/ilia/.electron-cash/wallets/test/test_wallet')
        wal2 = Wallet(stor2)
        wal2.set_schnorr_enabled(False)
        c = commands.Commands(None, wal, None)
        c2 = commands.Commands(None, wal2, None)

        ao = "qq6cqr5sxgzrnrdfl62hrfy88pfhe89egqyld9nnj7"
        ai = "pqjdgep0cmscpvrk3n7euqqlqfmwk2770uagtjgcl5"

        outp = [{"type": 0, "address": ao, "value": 39500, "prevout_n": 0}]

        inp = [{
            "address":
            ai,
            "num_sig":
            2,
            "sequence":
            4294967294,
            "signatures": [None, None],
            "value":
            40000,
            "type":
            "p2sh",
            "redeemScript":
            "522103ad9164b6e6d94602f25823196f3a35d9b9afb7622223c7d5ee7bc8f17e7ca0bb2102a6ef7ee97b10e0d5866cf972c9fa8f0b0954d13d5a49423d3941fc0a71021eef52ae",
            "prevout_hash":
            "7451d7d947716f1fe3ed973c9a2cbebb5952c22fa0a4685b8331d2ffc37e23ce",
            "x_pubkeys": [
                "ff0488b21e000000000000000000833b2b39ca3b1aedcc76ebc2dd54f2201e3f8ceb7fa16fbe4341249e24c0a8af03b55587668eac88a678b564e7bf7368b6ae32d04fa1d7dc252a596a7925779a0200000100",
                "ff0488b21e000000000000000000fd897a1c33cf038d108419d73559aba5ba26a8c1b7952ae6ff65be21a78be1a102f4eb32dc585e2585967369b6618771c1dce8dc928d996042bef2c80782ac408300000000"
            ],
            "pubkeys": [
                "03ad9164b6e6d94602f25823196f3a35d9b9afb7622223c7d5ee7bc8f17e7ca0bb",
                "02a6ef7ee97b10e0d5866cf972c9fa8f0b0954d13d5a49423d3941fc0a71021eef"
            ],
            "prevout_n":
            0
        }]

        y = {"version": 1, "lockTime": 0, "outputs": outp, "inputs": inp}
        tx = c.serialize(y)
        #print(tx)
        w = c.deserialize(c.serialize(y))
        #print(w['inputs'][0]['address'])
        #print(c.deserialize(tx))
        tx2 = c.signtransaction(tx)
        #print(c.deserialize(tx2))
        tx3 = c2.signtransaction(tx2)
        print(c.deserialize(tx3))
        print(self.get_tx_size(tx3))
        print(self.get_tx_size(tx2))
        print(self.get_tx_size(tx))
Ejemplo n.º 4
0
    def load_wallet(self, name, password=None):
        """Load a wallet"""
        self._assert_daemon_running()
        path = self._wallet_path(name)
        wallet = self.daemon.get_wallet(path)
        if not wallet:
            storage = WalletStorage(path)
            if not storage.file_exists():
                raise FileNotFoundError(path)
            if storage.is_encrypted():
                if not password:
                    raise util.InvalidPassword()
                storage.decrypt(password)

            wallet = Wallet(storage)
            wallet.start_threads(self.network)
            self.daemon.add_wallet(wallet)
Ejemplo n.º 5
0
 def getAddressWallet(self, idx):
     contract = self.contracts[idx]
     if "address" in contract.keys():
         storage = WalletStorage(contract['addrWalletFile'])
         if storage.file_exists():
             wallet = Wallet(storage)
             return wallet
     else:
         return None
    def create(self, name, password=None, seed=None):
        """Create or restore a new wallet"""
        path = self._wallet_path(name)
        if exists(path):
            raise FileExistsError(path)
        storage = WalletStorage(path)

        if seed is None:
            seed = self.make_seed()
            print("Your wallet generation seed is:\n\"%s\"" % seed)
        storage.put('keystore', keystore.from_seed(seed, "", False).dump())
        storage.put('wallet_type', 'standard')
        wallet = Wallet(storage)

        if password is None:
            password = main.prompt_password(
                "Password (hit return if you do not wish to encrypt your wallet):"
            )
        wallet.update_password(None, password, True)
        storage.write()
Ejemplo n.º 7
0
# Get network
config = SimpleConfig({})
password = args.password
wallet_path = args.wallet
storage = WalletStorage(wallet_path)
if not storage.file_exists():
    basic_logger.send("Error: Wallet file not found.")
    sys.exit(0)
if storage.is_encrypted():
    storage.decrypt(password)
if args.testnet:
    NetworkConstants.set_testnet()
    config = SimpleConfig({'server': "bch0.kister.net:51002:s"})
network = Network(config)
network.start()
wallet = Wallet(storage)
wallet.start_threads(network)
coin = Coin(network)
# # setup server
port = args.port
host = args.server
stat_port = args.stat_port
ssl = args.ssl
fee = args.fee
secured = ("s" if ssl else "")
stat_endpoint = "http{}://{}:{}/stats".format(secured, host, stat_port)

schedule.every(args.period).minutes.do(job)

while True:
    schedule.run_pending()
Ejemplo n.º 8
0
 def getContractWallet(self, idx):
     storage = WalletStorage(self.contracts[idx]['walletFile'])
     if storage.file_exists():
         wallet = Wallet(storage)
         return wallet