def load(cls):
        with open(cls.PATH, "r") as rf:
            wallet_json = json.load(rf)
            wallet_xpub = ExtPubKey(wallet_json["wallet_xpub"])
            master_fingerprint = x(wallet_json["master_fingerprint"])
            base_keypath = HDKeyPath(wallet_json["base_keypath"])
            current_block = Block.from_json(wallet_json["current_block"])
            raw_external_addresses = wallet_json["external_addresses"]
            raw_change_addresses = wallet_json["change_addresses"]

            external_addresses = [
                WalletAddress(
                    wallet_xpub, base_keypath, child_number, False,
                    address["was_recovered"], address["is_fresh"],
                    [Utxo.from_json(utxo) for utxo in address["utxos"]],
                    address.get("label"))
                for child_number, address in enumerate(raw_external_addresses)
            ]

            change_addresses = [
                WalletAddress(
                    wallet_xpub, base_keypath, child_number, True,
                    address["was_recovered"], address["is_fresh"],
                    [Utxo.from_json(utxo) for utxo in address["utxos"]])
                for child_number, address in enumerate(raw_change_addresses)
            ]

            return (wallet_xpub, master_fingerprint, base_keypath,
                    current_block, external_addresses, change_addresses)
Exemple #2
0
 def from_json(cls, json: dict):
     return cls(
         Block.from_json(json["block"]),
         TxIn(
             OutPoint(
                 lx(json["prevout"]["hash"]),
                 json["prevout"]["n"]
             )
         ),
         TxOut(
             json["value"],
             lx(json["script_pubkey"])
         )
     )