async def fetch_puzzle_solution(self, peer, height: uint32, coin: Coin) -> CoinSpend: solution_response = await peer.request_puzzle_solution( wallet_protocol.RequestPuzzleSolution(coin.name(), height) ) if solution_response is None or not isinstance(solution_response, wallet_protocol.RespondPuzzleSolution): raise ValueError(f"Was not able to obtain solution {solution_response}") return CoinSpend(coin, solution_response.response.puzzle, solution_response.response.solution)
async def coin_added(self, coin: Coin, _: uint32): """Notification from wallet state manager that wallet has been received.""" self.log.info(f"DID wallet has been notified that coin was added: {coin.name()}:{coin}") inner_puzzle = await self.inner_puzzle_for_did_puzzle(coin.puzzle_hash) if self.did_info.temp_coin is not None: self.wallet_state_manager.state_changed("did_coin_added", self.wallet_info.id) new_info = DIDInfo( self.did_info.origin_coin, self.did_info.backup_ids, self.did_info.num_of_backup_ids_needed, self.did_info.parent_info, inner_puzzle, None, None, None, False, ) await self.save_info(new_info, True) future_parent = LineageProof( coin.parent_coin_info, inner_puzzle.get_tree_hash(), coin.amount, ) await self.add_parent(coin.name(), future_parent, True) parent = self.get_parent_for_coin(coin) if parent is None: parent_state: CoinState = ( await self.wallet_state_manager.wallet_node.get_coin_state([coin.parent_coin_info]) )[0] node = self.wallet_state_manager.wallet_node.get_full_node_peer() assert parent_state.spent_height is not None puzzle_solution_request = wallet_protocol.RequestPuzzleSolution( coin.parent_coin_info, parent_state.spent_height ) response = await node.request_puzzle_solution(puzzle_solution_request) req_puz_sol = response.response assert req_puz_sol.puzzle is not None parent_innerpuz = did_wallet_puzzles.get_innerpuzzle_from_puzzle(req_puz_sol.puzzle) assert parent_innerpuz is not None parent_info = LineageProof( parent_state.coin.parent_coin_info, parent_innerpuz.get_tree_hash(), parent_state.coin.amount, ) await self.add_parent(coin.parent_coin_info, parent_info, False)
async def _action_messages(self) -> List[Message]: if self.wallet_state_manager is None or self.backup_initialized is False: return [] actions: List[WalletAction] = await self.wallet_state_manager.action_store.get_all_pending_actions() result: List[Message] = [] for action in actions: data = json.loads(action.data) action_data = data["data"]["action_data"] if action.name == "request_puzzle_solution": coin_name = bytes32(hexstr_to_bytes(action_data["coin_name"])) height = uint32(action_data["height"]) msg = make_msg( ProtocolMessageTypes.request_puzzle_solution, wallet_protocol.RequestPuzzleSolution(coin_name, height), ) result.append(msg) return result
async def load_backup(self, filename: str): try: f = open(filename, "r") details = f.readline().split(":") f.close() origin = Coin(bytes.fromhex(details[0]), bytes.fromhex(details[1]), uint64(int(details[2]))) backup_ids = [] for d in details[3].split(","): backup_ids.append(bytes.fromhex(d)) num_of_backup_ids_needed = uint64(int(details[5])) if num_of_backup_ids_needed > len(backup_ids): raise Exception innerpuz: Program = Program.from_bytes(bytes.fromhex(details[4])) did_info: DIDInfo = DIDInfo( origin, backup_ids, num_of_backup_ids_needed, self.did_info.parent_info, innerpuz, None, None, None, False, ) await self.save_info(did_info, False) await self.wallet_state_manager.update_wallet_puzzle_hashes( self.wallet_info.id) full_puz = did_wallet_puzzles.create_fullpuz( innerpuz, origin.name()) full_puzzle_hash = full_puz.get_tree_hash() ( sub_height, header_hash, ) = await self.wallet_state_manager.search_blockrecords_for_puzzlehash( full_puzzle_hash) assert sub_height is not None assert header_hash is not None full_nodes = self.wallet_state_manager.server.connection_by_type[ NodeType.FULL_NODE] additions: Union[RespondAdditions, RejectAdditionsRequest, None] = None for id, node in full_nodes.items(): request = wallet_protocol.RequestAdditions( sub_height, header_hash, None) additions = await node.request_additions(request) if additions is not None: break if isinstance(additions, RejectAdditionsRequest): continue assert additions is not None assert isinstance(additions, RespondAdditions) # All additions in this block here: new_puzhash = await self.get_new_inner_hash() new_pubkey = bytes( (await self.wallet_state_manager.get_unused_derivation_record( self.wallet_info.id)).pubkey) all_parents: bytes32 = set() for puzzle_list_coin in additions.coins: puzzle_hash, coins = puzzle_list_coin for coin in coins: all_parents.add(coin.parent_coin_info) parent_info = None for puzzle_list_coin in additions.coins: puzzle_hash, coins = puzzle_list_coin if puzzle_hash == full_puzzle_hash: # our coin for coin in coins: future_parent = LineageProof( coin.parent_coin_info, innerpuz.get_tree_hash(), coin.amount, ) await self.add_parent(coin.name(), future_parent, False) if coin.name() not in all_parents: did_info = DIDInfo( origin, backup_ids, num_of_backup_ids_needed, self.did_info.parent_info, innerpuz, coin, new_puzhash, new_pubkey, False, ) await self.save_info(did_info, False) removal_request = wallet_protocol.RequestRemovals( sub_height, header_hash, None) removals_response = await node.request_removals( removal_request) for coin_tuple in removals_response.coins: if coin_tuple[0] == coin.parent_coin_info: puzzle_solution_request = wallet_protocol.RequestPuzzleSolution( coin.parent_coin_info, sub_height) response = await node.request_puzzle_solution( puzzle_solution_request) req_puz_sol = response.response assert req_puz_sol.puzzle is not None parent_innerpuz = did_wallet_puzzles.get_innerpuzzle_from_puzzle( req_puz_sol.puzzle) assert parent_innerpuz is not None parent_info = LineageProof( coin_tuple[1].parent_coin_info, parent_innerpuz.get_tree_hash(), coin_tuple[1].amount, ) await self.add_parent( coin.parent_coin_info, parent_info, False) break assert parent_info is not None return None except Exception as e: raise e
async def load_backup(self, filename: str): try: f = open(filename, "r") details = f.readline().split(":") f.close() origin = Coin( bytes32.fromhex(details[0]), bytes32.fromhex(details[1]), uint64(int(details[2])), ) backup_ids = [] for d in details[3].split(","): backup_ids.append(bytes.fromhex(d)) num_of_backup_ids_needed = uint64(int(details[5])) if num_of_backup_ids_needed > len(backup_ids): raise Exception innerpuz: Program = Program.from_bytes(bytes.fromhex(details[4])) did_info: DIDInfo = DIDInfo( origin, backup_ids, num_of_backup_ids_needed, self.did_info.parent_info, innerpuz, None, None, None, False, ) await self.save_info(did_info, False) await self.wallet_state_manager.update_wallet_puzzle_hashes(self.wallet_info.id) # full_puz = did_wallet_puzzles.create_fullpuz(innerpuz, origin.name()) # All additions in this block here: new_puzhash = await self.get_new_inner_hash() new_pubkey = bytes( (await self.wallet_state_manager.get_unused_derivation_record(self.wallet_info.id)).pubkey ) parent_info = None node = self.wallet_state_manager.wallet_node.get_full_node_peer() children = await self.wallet_state_manager.wallet_node.fetch_children(node, origin.name()) while True: if len(children) == 0: break children_state: CoinState = children[0] coin = children_state.coin name = coin.name() children = await self.wallet_state_manager.wallet_node.fetch_children(node, name) future_parent = LineageProof( coin.parent_coin_info, innerpuz.get_tree_hash(), coin.amount, ) await self.add_parent(coin.name(), future_parent, False) if children_state.spent_height != children_state.created_height: did_info = DIDInfo( origin, backup_ids, num_of_backup_ids_needed, self.did_info.parent_info, innerpuz, coin, new_puzhash, new_pubkey, False, ) await self.save_info(did_info, False) assert children_state.created_height puzzle_solution_request = wallet_protocol.RequestPuzzleSolution( coin.parent_coin_info, children_state.created_height ) parent_state: CoinState = ( await self.wallet_state_manager.wallet_node.get_coin_state([coin.parent_coin_info]) )[0] response = await node.request_puzzle_solution(puzzle_solution_request) req_puz_sol = response.response assert req_puz_sol.puzzle is not None parent_innerpuz = did_wallet_puzzles.get_innerpuzzle_from_puzzle(req_puz_sol.puzzle) assert parent_innerpuz is not None parent_info = LineageProof( parent_state.coin.parent_coin_info, parent_innerpuz.get_tree_hash(), parent_state.coin.amount, ) await self.add_parent(coin.parent_coin_info, parent_info, False) assert parent_info is not None return None except Exception as e: raise e
vdf_info, vdf_proof, ) request_peers = full_node_protocol.RequestPeers() timestamped_peer_info = TimestampedPeerInfo("127.0.0.1", uint16(8444), uint64(10796)) respond_peers = full_node_protocol.RespondPeers([timestamped_peer_info]) ## WALLET PROTOCOL request_puzzle_solution = wallet_protocol.RequestPuzzleSolution( bytes32( bytes.fromhex( "6edddb46bd154f50566b49c95812e0f1131a0a7162630349fc8d1d696e463e47") ), uint32(3905474497), ) program = Program.from_serialized_program( SerializedProgram.from_bytes( bytes.fromhex( "ff01ffff33ffa0f8912302fb33b8188046662785704afc3dd945074e4b45499a7173946e044695ff8203e880ffff33ffa03eaa52e850322dbc281c6b922e9d8819c7b4120ee054c4aa79db50be516a2bcaff8207d08080" )), ) puzzle_solution_response = wallet_protocol.PuzzleSolutionResponse( bytes32( bytes.fromhex( "45c4451fdeef92aa0706def2448adfaed8e4a1c0b08a6d303c57de661509c442") ),