Exemplo n.º 1
0
 async def get_input(
     self,
     title="Enter a name for this seed",
     note="Naming your seeds allows you to store multiple.\n"
     "Give each seed a unique name!",
     suggestion="",
 ):
     scr = InputScreen(title, note, suggestion, min_length=1, strip=True)
     await self.show(scr)
     return scr.get_value()
Exemplo n.º 2
0
 async def menu(self, show_screen):
     buttons = [(None, "Your wallets")]
     buttons += [(w, w.name) for w in self.wallets]
     menuitem = await show_screen(Menu(buttons, last=(255, None)))
     if menuitem == 255:
         # we are done
         return False
     else:
         w = menuitem
         # pass wallet and network
         scr = WalletScreen(w, self.network, idx=w.unused_recv)
         cmd = await show_screen(scr)
         if cmd == DELETE:
             scr = Prompt(
                 "Delete wallet?", "You are deleting wallet \"%s\".\n"
                 "Are you sure you want to do it?" % w.name)
             conf = await show_screen(scr)
             if conf:
                 self.delete_wallet(w)
         elif cmd == EDIT:
             scr = InputScreen(title="Enter new wallet name",
                               note="",
                               suggestion=w.name)
             name = await show_screen(scr)
             if name is not None and name != w.name and name != "":
                 w.name = name
                 w.save(self.keystore)
         return True
Exemplo n.º 3
0
 async def menu(self, show_screen):
     buttons = [(None, "Your wallets")]
     buttons += [(w, w.name) for w in self.wallets if not w.is_watchonly]
     if len(buttons) != (len(self.wallets) + 1):
         buttons += [(None, "Watch only wallets")]
         buttons += [(w, w.name) for w in self.wallets if w.is_watchonly]
     menuitem = await show_screen(Menu(buttons, last=(255, None)))
     if menuitem == 255:
         # we are done
         return False
     else:
         w = menuitem
         # pass wallet and network
         self.show_loader(title="Loading wallet...")
         cmd = await w.show(self.network, show_screen)
         if cmd == DELETE:
             scr = Prompt(
                 "Delete wallet?",
                 'You are deleting wallet "%s".\n'
                 "Are you sure you want to do it?" % w.name,
             )
             conf = await show_screen(scr)
             if conf:
                 self.delete_wallet(w)
         elif cmd == EDIT:
             scr = InputScreen(title="Enter new wallet name",
                               note="",
                               suggestion=w.name)
             name = await show_screen(scr)
             if name is not None and name != w.name and name != "":
                 w.name = name
                 w.save(self.keystore)
         return True
Exemplo n.º 4
0
 async def create_wallet(self, derivation, xpub, prefix, version, show_screen):
     """Shows a wallet creation menu and passes descriptor to the wallets app"""
     net = NETWORKS[self.network]
     descriptors = OrderedDict({
         "zpub": ("wpkh(%s%s/{0,1}/*)" % (prefix, xpub), "Native Segwit"),
         "ypub": ("sh(wpkh(%s%s/{0,1}/*))" % (prefix, xpub), "Nested Segwit"),
         "legacy": ("pkh(%s%s/{0,1}/*)" % (prefix, xpub), "Legacy"),
         # multisig is not supported yet - requires cosigners app
     })
     if version == net["ypub"]:
         buttons = [
             (None, "Recommended"),
             descriptors.pop("ypub"),
             (None, "Other"),
         ]
     elif version == net["zpub"]:
         buttons = [
             (None, "Recommended"),
             descriptors.pop("zpub"),
             (None, "Other"),
         ]
     else:
         buttons = []
     buttons += [descriptors[k] for k in descriptors]
     menuitem = await show_screen(Menu(buttons, last=(255, None),
                                  title="Select wallet type to create"))
     if menuitem == 255:
         return
     else:
         # get wallet names from the wallets app
         s, _ = await self.communicate(BytesIO(b"listwallets"), app="wallets")
         names = json.load(s)
         if menuitem.startswith("pkh("):
             name_suggestion = "Legacy %d" % self.account
         elif menuitem.startswith("wpkh("):
             name_suggestion = "Native %d" % self.account
         elif menuitem.startswith("sh(wpkh("):
             name_suggestion = "Nested %d" % self.account
         else:
             name_suggestion = "Wallet %d" % self.account
         nn = name_suggestion
         i = 1
         # make sure we don't suggest existing name
         while name_suggestion in names:
             name_suggestion = "%s (%d)" % (nn, i)
             i += 1
         name = await show_screen(InputScreen(title="Name your wallet",
                 note="",
                 suggestion=name_suggestion,
                 min_length=1, strip=True
         ))
         if not name:
             return
         # send the wallets app addwallet command with descriptor
         data = "addwallet %s&%s" % (name, menuitem)
         stream = BytesIO(data.encode())
         await self.communicate(stream, app="wallets")