Airship\Cabin\Bridge\Landing\Admin::addNotary PHP Method

addNotary() protected method

Add a new notary
protected addNotary ( array $channels, array $post ) : boolean
$channels array
$post array
return boolean
    protected function addNotary(array $channels, array $post) : bool
    {
        $ch = $post['channel'];
        if (!isset($channels[$ch])) {
            return false;
        }
        $url = \trim($post['new_notary']);
        $notaryInfo = $this->notaryDiscovery($url);
        if (empty($notaryInfo)) {
            return false;
        }
        $found = false;
        foreach ($channels[$ch]['notaries'] as $i => $notary) {
            if (\in_array($url, $notary['urls'])) {
                if ($notary['public_key'] === $notaryInfo['public_key']) {
                    // Duplicate
                    return false;
                }
                $found = true;
                $channels[$ch]['notaries'][$i]['public_key'] = $notaryInfo['public_key'];
                break;
            }
        }
        if (!$found) {
            $channels[$ch]['notaries'][] = ['name' => $post['name'], 'urls' => [$notaryInfo['url']], 'public_key' => $notaryInfo['public_key']];
        }
        return \Airship\saveJSON(ROOT . '/config/channel_peers/' . $ch . '.json', $channels[$ch]['notaries']);
    }