2019-09-29 20:39:03 +00:00
|
|
|
"""
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
view and interact with onionr sites
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
from typing import Union
|
|
|
|
|
2019-09-28 05:37:24 +00:00
|
|
|
import onionrexceptions
|
|
|
|
from onionrutils import mnemonickeys
|
|
|
|
from onionrutils import stringvalidators
|
2019-09-29 20:39:03 +00:00
|
|
|
from coredb import blockmetadb
|
|
|
|
from onionrblocks.onionrblockapi import Block
|
2019-09-28 05:37:24 +00:00
|
|
|
|
2019-09-29 20:39:03 +00:00
|
|
|
def find_site(user_id: str)->Union[str, None]:
|
|
|
|
"""Returns block hash string for latest block for a site by a given user id"""
|
2019-09-28 05:37:24 +00:00
|
|
|
if '-' in user_id: user_id = mnemonickeys.get_base32(user_id)
|
|
|
|
if not stringvalidators.validate_pub_key(user_id): raise onionrexceptions.InvalidPubkey
|
2019-09-29 20:39:03 +00:00
|
|
|
found_site = None
|
|
|
|
sites = blockmetadb.get_blocks_by_type('zsite')
|
2019-09-28 05:37:24 +00:00
|
|
|
|
2019-09-29 20:39:03 +00:00
|
|
|
for site in sites:
|
|
|
|
site = Block(site)
|
|
|
|
if site.isSigner(user_id) and site.verifySig():
|
|
|
|
found_site = site.hash
|
|
|
|
return found_site
|