Beispiel #1
0
def start(update, context):
    """
    Gives direction for use
    Displays information about the bot and available commands
    :param update:
    :param context:
    :return: None
    """
    dspensr = 'https://bank.testnet.algorand.network/'

    user = update.message.from_user
    reply = "Hi {}!\nI am DDV Escrow Bot.\n\n".format(user['first_name'])
    reply += "This is an Escrow contract to be initiated by the seller of an Algorand standard asset.\n\n" \
             "- It is expected that both parties already agreed to trade.\n- Seller invoke the escrow using the" \
             "secret key to the account where the ASA is deposited.\v - Seller also submits the account's public key " \
             "of the buyer from where the Algo will be sent\n\n - Thereafter the buyer created an escrow, the seller " \
             "may proceed to approving the\ntransaction using the authorization key to the account submitted by the " \
             "seller.\n\nTo test: \n   - /Get_test_account first or find a peer to act as the buyer.\n   " \
             "- Fund the account with testnet Algo from {}\n" \
             "- /Submit your address to our dispenser to get 200 Test DMT2.\n- Then try to trade with someone else" \
             "".format(dspensr)

    update.message.reply_text(reply,
                              reply_markup=reply_keyboard(
                                  update, context, category))
    context.user_data.clear()
    return ConversationHandler.conversation_timeout
Beispiel #2
0
def query_balance(update, context):
    """
    Check balance on an account's public key
    :param update:
    :param context:
    :return: Balance in account plus asset (s) balance
    """
    if 'public_key' in context.user_data:
        pk = context.user_data['public_key']
        update.message.reply_text(
            "Getting the balance on this address_sending ==>   {}.".format(pk))
        if len(pk) == 58:
            account_bal = client.account_info(pk)
            bal = account_bal['amount'] / 1000000
            update.message.reply_text("Balance on your account: {} Algo."
                                      "".format(bal),
                                      reply_markup=reply_keyboard(
                                          update, context, keyboard))
            for m in account_bal['assets']:
                update.message.reply_text(
                    "Asset balance: {} 'DMT2'. \nClick /Menu to go the main menu."
                    .format(m['amount']))
            context.user_data.clear()
        else:
            update.message.reply_text(
                "Wrong address_sending supplied.\nNo changes has been made.")
    else:
        update.message.reply_text("Something went wrong")
    return -1
Beispiel #3
0
def preview_info(update, context) -> int:
    global markup
    global user_d
    text = update.message.text
    userdata = context.user_data
    for a in user_d:
        category = user_d[a]
        if category == 'buyer_address' and len(text) == 58:
            user_d[category] = text

        elif category == 'asset_name':
            user_d[category] = text

        elif category == 'signing_key':
            user_d[category] = text

        elif category == 'amount_in_algo' and type(int(text)) == int:
            user_d[category] = int(text)

        elif category == 'quantity_in_ASA' and type(int(text)) == int:
            user_d[category] = int(text)

        userdata[category] = user_d[category]
    update.message.reply_text(
        "I got this from you:\n"
        f"{arg_to_str(user_d)}",
        reply_markup=reply_keyboard(update, context, sell_asset))
    user_d.clear()
    return SELECT
Beispiel #4
0
def get_args(update, context) -> int:
    """
    Entry point for taking arguments from user
    :param context:
    :param update:
    :return: The next line of action.
    """
    global markup
    text = update.message.text

    if text == 'Set_up_a_trade' or text == '/Set_up_a_trade':
        markup = reply_keyboard(update, context, sell_asset)
    elif text == 'Verify_transaction' or text == '/Verify_transaction':
        markup = reply_keyboard(update, context, verify_keyboard)
    elif text == 'Approve_trade' or text == '/Approve_trade':
        markup = reply_keyboard(update, context, approve_trade)
    elif text == 'Get_free_asset' or text == '/Get_free_asset':
        markup = reply_keyboard(update, context, dispense_keyboard)
        update.message.reply_text(
            "Reply 'None' to the Signing key if the designated account already\n "
            "has asset added to its balance")
    elif text == 'Import_Secret_key' or text == '/Import_Secret_key':
        markup = reply_keyboard(update, context, pk_keyboard)
    elif text == 'Check_balance' or text == '/Check_balance':
        markup = reply_keyboard(update, context, keyboard)
    else:
        markup = reply_keyboard(update, context, category)
        update.message.reply_text("No such category")
    update.message.reply_text("Select: \n", reply_markup=markup)
    return SELECT
Beispiel #5
0
def cancel(update, context):
    """
    Terminates a session and disengaged the bot.
    :param update:
    :param context:
    :return: int --> Ends the session
    """
    context.user_data.clear()
    update.message.reply_text(
        "Your message is not recognized!\nSession terminated.",
        reply_markup=reply_keyboard(update, context, category))
    return -2
Beispiel #6
0
def menu(update, context):
    message = "If you the buyer, ensure you /Verify_transaction\n" \
              "before signing it."

    message += "Alternatively, you can use:\n" \
               "- /Set_up_a_trade\n" \
               "- /Verify_transaction\n" \
               "- /Approve_trade\n" \
               "- /Get_test_ASA\n" \
               "- /Import_Secret_key\n" \
               "- /Check_balance\n\n" \
               "Select: "
    update.message.reply_text(message, reply_markup=reply_keyboard(update, context, category))

    return -2
Beispiel #7
0
def getPK(update, context):
    """
    Takes in 25 mnemonic and converts to private key
    :param context:
    :param update:
    :return: 25 mnemonic words
    # """
    if 'Mnemonic' in context.user_data:
        mn = context.user_data['Mnemonic']
        phrase = mnemonic.to_private_key(str(mn))
        update.message.reply_text(
            "Your Private Key:\n {}\n\nKeep your key from prying eyes.\n"
            "\n\nI do not hold or manage your keys.".format(phrase),
            reply_markup=reply_keyboard(update, context, pk_keyboard))
        update.message.reply_text('\nSession ended.')
        del context.user_data['Mnemonic']
    else:
        update.message.reply_text("Cannot find Mnemonic.")
    context.user_data.clear()
Beispiel #8
0
def popup(update, context, mark_up, obj):
    return update.message.reply_text(
        "I got this from you:\n"
        f"{arg_to_str(obj)}",
        reply_markup=reply_keyboard(update, context, mark_up))