containsParameter('peer')) { throw new MissingRpcArgumentException('peer'); } try { $address = PeerAddress::fromAddress($rpcRequest->getParameter('peer')); } catch(InvalidArgumentException $e) { throw new InvalidRpcArgumentException('peer', 'Invalid peer address'); } if(!$rpcRequest->containsParameter('relationship')) { throw new MissingRpcArgumentException('relationship'); } $relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship'))); if($relationship === null) { throw new InvalidRpcArgumentException('relationship', 'Invalid relationship type'); } try { // Check if the contact already exists $peer = $request->getPeer(); if(!ContactManager::isContact($peer, $address)) { return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist'); } // Create the contact ContactManager::updateContactRelationship($peer, $address, $relationship); } catch (DatabaseOperationException $e) { throw new StandardRpcException('Failed to update contact relationship', StandardError::INTERNAL_SERVER_ERROR, $e); } // Return success return $rpcRequest->produceResponse(true); } }