Exemplo n.º 1
0
def processUnsent():
    unsentTipFailureCount = len(unsentTipFailures)
    unsentTipSuccessCount = len(unsentTipSuccesses)
    if (unsentTipSuccessCount == 0 and unsentTipSuccessCount == 0): return

    tipbitUtilities.ConsolePrint(
        'Attempting to process unsent. [{} | {}]'.format(
            unsentTipFailureCount, unsentTipSuccessCount))

    while (len(unsentTipFailures) > 0):
        failure = unsentTipFailures[0]
        if (CommentReply_TipFailure(failure[0], failure[1], failure[2], False)
                is False):
            break
        tipbitWindow.AddEventString(
            'Successfully sent a previously blocked comment')
        unsentTipFailures.remove(failure)

    while len(unsentTipSuccesses) > 0:
        success = unsentTipSuccesses[0]
        if (CommentReply_TipSuccess(success[0], success[1], success[2],
                                    success[3], success[4], success[5], False)
                is False):
            break
        tipbitWindow.AddEventString(
            'Successfully sent a previously blocked comment')
        unsentTipSuccesses.remove(success)
Exemplo n.º 2
0
def UpdateBalancesAndSolvency():
    global primaryStorageBalance
    global primaryTipBalance

    walletBalances = tipbitUtilities.WalletBalancesList
    if len(walletBalances) == 0:
        tipbitUtilities.ConsolePrint(
            'GetWalletBalanceList() failed to return a list (solvency check)')
        return

    if (botSpecificData.PRIMARY_STORAGE_ADDRESS not in walletBalances):
        tipbitUtilities.ImportPrivateKey(
            botSpecificData.PRIMARY_STORAGE_PRIVATE_KEY,
            'PRIMARY STORAGE LEGACY'
            if botSpecificData.segwit else 'PRIMARY STORAGE', True)
        tipbitUtilities.GetNewSegwitAddress(
            'PRIMARY STORAGE'
            if botSpecificData.segwit else 'PRIMARY STORAGE SEGWIT',
            botSpecificData.PRIMARY_STORAGE_ADDRESS_LEGACY)

    primaryStorageBalance = tipbitUtilities.BTCToSatoshis(
        walletBalances[botSpecificData.PRIMARY_STORAGE_ADDRESS])

    primaryTipBalance = 0
    for user in userBalances:
        primaryTipBalance += userBalances[user]
Exemplo n.º 3
0
def CommentReply_TipSuccess(comment,
                            senderUsername,
                            targetUsername,
                            amountSatoshis,
                            amountUSD,
                            botInfoLink,
                            firstTry=True):
    amountMBTC = tipbitUtilities.SatoshisToMBTC(amountSatoshis)
    try:
        comment.reply(
            messageTemplates.SUCCESSFUL_TIP_TEXT.format(
                senderUsername, targetUsername, amountMBTC,
                (' Testnet Bitcoins' if botSpecificData.testnet else ''),
                "%.2f" % amountUSD, botInfoLink))
        return True
    except praw.exceptions.APIException as ex:
        if (firstTry is True):
            tipbitUtilities.ConsolePrint(
                'Saving off tip success comment due to exception: {}'.format(
                    ex.error_type))
            successComment = (comment, senderUsername, targetUsername,
                              amountSatoshis, amountUSD, botInfoLink)
            unsentTipSuccesses.append(successComment)
        return False
    except:
        tipbitWindow.AddEventString(
            'Unknown error occurred while commenting on a successful tip...')
        return False
Exemplo n.º 4
0
def main():
    try:
        tipbitUtilities.ConsolePrint('- Bot ID: {}'.format(reddit.user.me()))
    except:
        tipbitUtilities.ConsolePrint("Failed to access PRAW. Shutting down")
        exit()

    #  Claim the primary storage address
    print('Claiming Primary Storage Addresses')
    ClaimPrimaryStorageAddresses()

    #  Set up the GUI
    print('- Setting up GUI...')
    tipbitWindow.SetupGUI()

    #  Import user data and print the balances
    print('- Importing User Data...')
    ImportUserData()

    #  Gather a list of unused legacy and segwit addresses attached to this bitcoin wallet
    print('- Parsing existing addresses...')
    ParseExistingAddresses()

    #  Determine whether the connected node has the Primary Storage address controlled. If not, exit out
    if (CheckForPrimaryStorage() == False):
        print(
            'Connected node does not have control over the Primary Storage address! Shutting down...'
        )
        exit()

    #  Print out info about current balances
    print('')
    tipbitUtilities.PrintWalletBalancesList()
    print('')
    tipbitUtilities.PrintAccountBalancesList()
    print('')

    #  Initiate the main loop function
    print("- Initiating main loop")
    mainLoop()
Exemplo n.º 5
0
def SendBitcoin(senderKey, targetAddress, amount, estimatedFee,
                satoshisPerByte, transactionReason):
    amountMinusFee = amount - estimatedFee
    try:
        tipbitWindow.AddEventString(
            'Sending {} Satoshis'.format(amountMinusFee))
        tx = senderKey.send([(targetAddress, amountMinusFee, 'satoshi')],
                            satoshisPerByte,
                            botSpecificData.PRIMARY_STORAGE_ADDRESS)
        tipbitWindow.AddEventString('Transaction successful: {}'.format(tx))
        return tx
    except Exception as ex:
        amountMBTC = tipbitUtilities.SatoshisToMBTC(amount)
        estimatedFeeMBTC = tipbitUtilities.SatoshisToMBTC(estimatedFee)
        amountMinusFeeMBTC = tipbitUtilities.SatoshisToMBTC(satoshisPerByte)
        tipbitWindow.AddEventString(
            '{} transaction of {} mBTC failed ({} + {} fee)'.format(
                transactionReason, amountMBTC, amountMinusFeeMBTC,
                estimatedFeeMBTC))
        tipbitUtilities.ConsolePrint(
            "An exception of type {0} occurred.".format(type(ex).__name__))
        tipbitUtilities.ConsolePrint(ex.args)
        return ""
Exemplo n.º 6
0
def displayUnreadUnsentCount():
    global unreadMentionCount
    global unreadMessageCount
    global unsentCommentCount
    if ((len(unreadMentions) is not unreadMentionCount)
            or (len(unreadMessages) is not unreadMessageCount)
            or ((len(unsentTipFailures) + len(unsentTipSuccesses))
                is not unsentCommentCount)):
        tipbitUtilities.ConsolePrint(
            "Comments / Messages / Unsent: [{}, {}, {}]".format(
                len(unreadMentions), len(unreadMessages),
                (len(unsentTipFailures) + len(unsentTipSuccesses))))
    unreadMentionCount = len(unreadMentions)
    unreadMessageCount = len(unreadMessages)
    unsentCommentCount = len(unsentTipFailures) + len(unsentTipSuccesses)
Exemplo n.º 7
0
def gatherUnreads():
    global allUnread
    global markedRead
    allUnread = reddit.inbox.unread(limit=1)
    try:
        for item in allUnread:
            if (item in markedRead):
                tipbitWindow.AddEventString(
                    "reddit.inbox.unread is returning items after they're marked read... something is wrong"
                )
                continue
            try:
                if isinstance(item, Message):
                    unreadMessages.append(item)
                elif isinstance(item, Comment):
                    unreadMentions.append(item)
            except urllib3.exceptions.ReadTimeoutError:
                tipbitWindow.AddEventString(
                    'ReadTimeoutError on processing of unread messages and comments...'
                )
            except ssl.SSLError:
                tipbitWindow.AddEventString(
                    'SSL error on processing of unread messages and comments...'
                )
            except Exception as e:
                tipbitUtilities.ConsolePrint(e)
                tipbitWindow.AddEventString(
                    'Unknown exception on processing of unread messages and comments...'
                )
    except RequestException:
        tipbitWindow.AddEventString(
            'RequestException on processing unreads (likely a connection error)',
            False)
        return
    except ServerError:
        tipbitWindow.AddEventString(
            'PrawCore ServerError on processing unreads (likely a connection error)',
            False)
        return

    for item in unreadMessages:
        markedRead.append(item)
    for item in unreadMentions:
        markedRead.append(item)
    reddit.inbox.mark_read(unreadMessages)
    reddit.inbox.mark_read(unreadMentions)
Exemplo n.º 8
0
def CommentReply_TipFailure(comment,
                            commentTemplate,
                            targetUsername,
                            firstTry=True):
    try:
        comment.reply(commentTemplate.format(targetUsername))
        return True
    except praw.exceptions.APIException as ex:
        if (firstTry is True):
            tipbitUtilities.ConsolePrint(
                'Saving off tip failure comment due to exception: {}'.format(
                    ex.error_type))
            failureComment = (comment, commentTemplate, targetUsername)
            unsentTipFailures.append(failureComment)
        return False
    except:
        tipbitWindow.AddEventString(
            'Unknown error occurred while commenting on a successful tip...')
        return False