def add_history_record(
    username=None,
    action="unknown",
    address=None,
    comment_or_message=None,
    recipient_username=None,
    recipient_address=None,
    amount=None,
    hash=None,
    comment_id=None,
    notes=None,
    reddit_time=None,
    comment_text=None,
):
    if action is None:
        action = "unknown"
    if reddit_time is None:
        reddit_time = datetime.utcnow()
    history = History(username=username,
                      action=action,
                      address=address,
                      comment_or_message=comment_or_message,
                      recipient_username=recipient_username,
                      recipient_address=recipient_address,
                      amount=amount,
                      hash=hash,
                      comment_id=comment_id,
                      notes=notes,
                      reddit_time=reddit_time,
                      comment_text=comment_text)

    if history.save() < 1:
        LOGGER.error(f"Failed saving history item {username}")

    return history.id
def add_new_account(username):
    address, pk = generate_account()
    if address is None:
        LOGGER.error("Failed to create account!")
        return None
    acct = Account(username=username,
                   private_key=pk,
                   address=address,
                   silence=False,
                   active=False,
                   opt_in=True)
    acct.save(force_insert=True)
    return {
        "username": username,
        "address": address,
        "private_key": pk,
        "silence": False,
        "balance": 0,
        "account_exists": True,
    }