Ejemplo n.º 1
0
    # build and send the payment

    tx_list = mobilecoind.get_unspent_tx_output_list(
        sender_monitor_id, args.sender_subaddress).output_list
    receiver = mobilecoind.parse_address_code(recipient_address_code).receiver
    outlays = [{'value': value_to_send_picoMOB, 'receiver': receiver}]
    tx_proposal = mobilecoind.generate_tx(sender_monitor_id,
                                          args.sender_subaddress, tx_list,
                                          outlays).tx_proposal
    sender_tx_receipt = mobilecoind.submit_tx(tx_proposal).sender_tx_receipt
    # Wait for the transaction to clear
    tx_status = mobilecoin.TxStatus.Unknown
    while tx_status == mobilecoin.TxStatus.Unknown:
        time.sleep(TX_RECEIPT_CHECK_INTERVAL_SECONDS)
        tx_status = mobilecoind.get_tx_status_as_sender(
            sender_tx_receipt).status
        print("Transaction status: {}".format(
            mobilecoin.parse_tx_status(tx_status)))

    # print summary
    print("\n")
    print("    {:<18}{}".format("Sender:", args.sender))
    print("    {:<18}{}".format("Recipient:", args.recipient))
    print("    {:<18}{} picoMOB".format("Value:", value_to_send_picoMOB))
    print("    {:<18}{}".format(
        " ", mobilecoin.display_as_MOB(value_to_send_picoMOB)))
    print("\n")
    print("    {:<18}{}".format("Final Status:",
                                mobilecoin.parse_tx_status(tx_status)))
    print("\n")
Ejemplo n.º 2
0
def allocate_MOB(mailchimp_member_record, amount_picoMOB):
    """generates a new master key, allocates funds, stores data at Mailchimp and triggers the welcome email"""

    new_user_email = mailchimp_member_record["email_address"]
    new_user_hash = mailchimp_member_record["id"]

    # Wait for mobilecoind to sync ledger
    block_count = wait_for_monitor(sender_monitor_id)

    # abort if sender's balance is too low
    sender_balance_picoMOB = mobilecoind.get_balance(sender_monitor_id).balance
    if sender_balance_picoMOB < (amount_picoMOB + mobilecoin.MINIMUM_FEE):
        print("# sender's balance is too low ({})... aborting!".format(
            mobilecoin.display_as_MOB(sender_balance_picoMOB)))
        sys.exit()

    # create and fund a new MobileCoin TestNet account
    recipient_entropy = mobilecoind.generate_entropy().entropy
    recipient_account_key = mobilecoind.get_account_key(
        recipient_entropy).account_key
    print("# generated entropy {} for email {}".format(recipient_entropy.hex(),
                                                       new_user_email))

    # no need to start the recipient from the origin block since we know we just created this account
    recipient_monitor_id = mobilecoind.add_monitor(
        recipient_account_key, first_block=block_count).monitor_id
    recipient_public_address = mobilecoind.get_public_address(
        recipient_monitor_id).public_address
    print("# adding monitor {} for {} (first block = {})".format(
        recipient_monitor_id.hex(), new_user_email, block_count))

    # Construct and send the token allocation transaction
    tx_list = mobilecoind.get_unspent_tx_output_list(
        sender_monitor_id).output_list
    outlays = [{'value': amount_picoMOB, 'receiver': recipient_public_address}]

    tx_proposal = mobilecoind.generate_tx(sender_monitor_id,
                                          mobilecoin.DEFAULT_SUBADDRESS_INDEX,
                                          tx_list, outlays).tx_proposal

    sender_tx_receipt = mobilecoind.submit_tx(tx_proposal).sender_tx_receipt

    # Wait for the transaction to clear
    tx_status = mobilecoin.TxStatus.Unknown
    while tx_status == mobilecoin.TxStatus.Unknown:
        time.sleep(TX_RECEIPT_CHECK_INTERVAL_SECONDS)
        tx_status = mobilecoind.get_tx_status_as_sender(
            sender_tx_receipt).status
        print("# transaction status is {}".format(
            mobilecoin.parse_tx_status(tx_status)))

    if tx_status != mobilecoin.TxStatus.Verified:
        print("ERROR... Transaction failed with status {}".format(tx_status))
        mobilecoind.remove_monitor(recipient_monitor_id)
        print("# removed monitor {} for {}".format(recipient_monitor_id.hex(),
                                                   new_user_email))
        return 0  # no email was sent

    # Check that balances are as expected
    wait_for_monitor(sender_monitor_id)
    sender_balance = mobilecoind.get_balance(sender_monitor_id).balance

    wait_for_monitor(recipient_monitor_id)
    recipient_balance = mobilecoind.get_balance(recipient_monitor_id).balance

    print(
        "# recipient balance = {} picoMOB ({}), sender balance = {} picoMOB ({})"
        .format(recipient_balance,
                mobilecoin.display_as_MOB(recipient_balance), sender_balance,
                mobilecoin.display_as_MOB(sender_balance)))

    # If the recipient's balance is not as expected, complain and do not trigger the email in Mailchimp
    if recipient_balance != amount_picoMOB:
        print(
            "ERROR... recipient balance is not correct! Entropy {} has only {}. Expected {}."
            .format(recipient_entropy.hex(),
                    mobilecoin.display_as_MOB(recipient_balance),
                    mobilecoin.display_as_MOB(amount_picoMOB)))
        email_sent = 0

    else:
        # set the entropy value at MailChimp
        data = {"merge_fields": {"ENTROPY": recipient_entropy.hex()}}
        response = mailchimp.lists.members.update(
            list_id, subscriber_hash=new_user_hash, data=data)

        # adding "send_key_now" tag triggers the welcome email automation!
        data = {
            "tags": [{
                "name": "has_entropy",
                "status": "active"
            }, {
                "name": "send_key_now",
                "status": "active"
            }]
        }
        mailchimp.lists.members.tags.update(list_id,
                                            subscriber_hash=new_user_hash,
                                            data=data)

        print("# setting welcome email trigger for {}!".format(new_user_email))
        email_sent = 1

    # remove recipient monitor
    mobilecoind.remove_monitor(recipient_monitor_id)
    print("# removed monitor {} for {}".format(recipient_monitor_id.hex(),
                                               new_user_email))

    return email_sent
Ejemplo n.º 3
0
                    mobilecoin.display_as_MOB(mobilecoin.MINIMUM_FEE)
                )
            )
            sys.exit(0)
    else:
        value_to_send_picoMOB = args.value

    # build and send the payment

    tx_list = mobilecoind.get_unspent_tx_output_list(sender_monitor_id, args.sender_subaddress).output_list
    receiver = mobilecoind.parse_address_code(recipient_address_code).receiver
    outlays = [{'value': value_to_send_picoMOB, 'receiver': receiver}]
    tx_proposal = mobilecoind.generate_tx(sender_monitor_id, args.sender_subaddress, tx_list, outlays).tx_proposal
    submit_response = mobilecoind.submit_tx(tx_proposal)
    # Wait for the transaction to clear
    tx_status = mobilecoin.TxStatus.Unknown
    while tx_status == mobilecoin.TxStatus.Unknown:
        time.sleep(TX_RECEIPT_CHECK_INTERVAL_SECONDS)
        tx_status = mobilecoind.get_tx_status_as_sender(submit_response).status
        print("Transaction status: {}".format(mobilecoin.parse_tx_status(tx_status)))

    # print summary
    print("\n")
    print("    {:<18}{}".format("Sender:", args.sender))
    print("    {:<18}{}".format("Recipient:", args.recipient))
    print("    {:<18}{} picoMOB".format("Value:", value_to_send_picoMOB))
    print("    {:<18}{}".format(" ", mobilecoin.display_as_MOB(value_to_send_picoMOB)))
    print("\n")
    print("    {:<18}{}".format("Final Status:", mobilecoin.parse_tx_status(tx_status)))
    print("\n")