コード例 #1
0
def add_alias(author: Union[AccountId, str], account: Union[AccountId, str],
              signature: str, server: Server):
    """Alias author to account using an alias code (signature)"""
    if server.has_account(author):
        raise AccountCommandException(account)

    account = _get_account(account, server)

    if _is_signed_by(account, str(author), signature):
        server.add_account_alias(account, author)
    else:
        raise ValueCommandException(signature)
コード例 #2
0
def process_add_alias(author: AccountId, message: str, server: Server, **kwargs):
    """Processes a request to add `author` as an alias to an account."""
    if server.has_account(author):
        raise CommandException(
            'An account has already been associated with %s, so it cannot be an alias for another account.' % author.readable())

    split_msg = message.split()
    if len(split_msg) != 3:
        raise CommandException('Incorrect formatting. Expected `add-alias ALIASED_ACCOUNT ALIAS_REQUEST_CODE`.')

    _, aliased_account_name, signature = split_msg
    aliased_account = assert_is_account(aliased_account_name, server)

    if is_signed_by(aliased_account, str(author), signature):
        server.add_account_alias(aliased_account, author)
        return 'Alias set up successfully. %s and %s now refer to the same account.' % (
            aliased_account_name, author.readable())
    else:
        raise CommandException('Cannot set up alias because the signature is invalid.')