class WalletController(QObject):
    onError = Signal(unicode)
    onConnected = Signal(bool)
    onTxSent = Signal(bool)
    onBusy = Signal()
    onDoubleEncrypted = Signal()
    onBalance = Signal()
    onFiatBalance = Signal()
    onWalletUnlocked = Signal()
    onCurrentBalance = Signal()
    onCurrentFiatBalance = Signal()
    onCurrentLabel = Signal()
    onCurrentAddress = Signal()
    onCurrentDoubleEncrypted = Signal()
    onCurrentPassKey = Signal()
    onCurrentWatchOnly = Signal()

    def __init__(self,):
        QObject.__init__(self,)
        self.thread = None
        self._balance = '<b>0.00</b>000000'
        self._fiatSymbol = u'€'
        self._fiatRate = 0
        self._fiatBalance = u'0 €'
        self._wallet = Wallet()
        self._wallet.onNewTransaction.connect(self.notifyNewTx)
        self._walletUnlocked = False
        self.settings = Settings()
        self.addressesModel = AddressesModel()
        self.transactionsModel = TransactionsModel()
        self.timer = QTimer(self)
        self.timer.setInterval(900000)  # 15 min update
        self.timer.timeout.connect(self.update)
        self.timer.start()

        if self.settings.storePassKey:
            self._currentPassKey = self.settings.passKey
            try:
                self.unlockWallet(self._currentPassKey)
            except:
                self.onError.emit('Stored pass phrase is invalid')
        else:
            self._currentPassKey = None
        self._currentAddressIndex = 0

    def on_event_data_received(self,*args):
        print 'BitPurse received DATA:', args
    
    
#    def notifyCallback(self):
#        print 'ohai! received something :)'
#        self.service.remove_items()
        
    def notifyNewTx(self, address, datas, amount):
        from eventfeed import EventFeedService, EventFeedItem
        service = EventFeedService('BitPurse',
                                   'BitPurse',
                                   self.on_event_data_received)
        item = EventFeedItem('/usr/share/icons/hicolor/80x80/apps/bitpurse.png',
                             'BitPurse')
        item.set_body('New transaction on address %s : %f BTC'
                      % (address, amount / float(10**8)))
        #item.set_custom_action(self.notifyCallback)
        service.add_item(item)
        
    @Slot(unicode)
    def newAddr(self, doubleKey):
        try:
            self._wallet.createAddr(doubleKey)
            self.storeWallet()
            self.update()
        except (WrongPassword, DataError), err:
            self.onError.emit(unicode(err))
Exemple #2
0
class WalletController(QObject):
    onError = Signal(unicode)
    onConnected = Signal(bool)
    onTxSent = Signal(bool)
    onBusy = Signal()
    onDoubleEncrypted = Signal()
    onBalance = Signal()
    onFiatBalance = Signal()
    onWalletUnlocked = Signal()
    onCurrentBalance = Signal()
    onCurrentFiatBalance = Signal()
    onCurrentLabel = Signal()
    onCurrentAddress = Signal()
    onCurrentDoubleEncrypted = Signal()
    onCurrentPassKey = Signal()
    onCurrentWatchOnly = Signal()

    def __init__(self,):
        QObject.__init__(self,)
        self.thread = None
        self._balance = '<b>0.00</b>000000'
        self._fiatSymbol = u'€'
        self._fiatRate = 0
        self._fiatBalance = u'0 €'
        self._wallet = Wallet()
        self._wallet.onNewTransaction.connect(self.notifyNewTx)
        self._walletUnlocked = False
        self.settings = Settings()
        self.addressesModel = AddressesModel()
        self.transactionsModel = TransactionsModel()
        self.timer = QTimer(self)
        self.timer.setInterval(900000)  # 15 min update
        self.timer.timeout.connect(self.update)
        self.timer.start()

        if self.settings.storePassKey:
            self._currentPassKey = self.settings.passKey
            try:
                self.unlockWallet(self._currentPassKey)
            except:
                self.onError.emit('Stored pass phrase is invalid')
        else:
            self._currentPassKey = None
        self._currentAddressIndex = 0

    def on_event_data_received(self, *args):
        print 'BitPurse received DATA:', args

    def notifyNewTx(self, address, datas, amount):
        from eventfeed import EventFeedService, EventFeedItem
        service = EventFeedService('BitPurse',
                                   'BitPurse',
                                   self.on_event_data_received)
        item = EventFeedItem(
            '/usr/share/icons/hicolor/80x80/apps/bitpurse.png',
            'BitPurse')
        item.set_body('New transaction on address %s : %f BTC'
                      % (address, amount / float(10 ** 8)))
        # item.set_custom_action(self.notifyCallback)
        service.add_item(item)

    @Slot(unicode)
    def newAddr(self, doubleKey):
        try:
            self._wallet.createAddr(doubleKey)
            self.storeWallet()
            self.update()
        except (WrongPassword, DataError), err:
            self.onError.emit(unicode(err))