Ejemplo n.º 1
0
 def getInputs(self, addr):
     inputs = []
     request = 'http://blockchain.info/unspent?active=%s' % addr
     for unspent in getDataFromChainblock(request)['unspent_outputs']:
         inputs.append(
             (addr, unspent['value'], self.reverse_hash(unspent['tx_hash']),
              unspent['tx_output_n'], unspent['script'], [(None, None)]))
     return inputs
Ejemplo n.º 2
0
    def importFromBlockchainInfoWallet(self, passKey, guid, key,
                                       skey, doubleKey=''):
        '''Import wallet from BlockChain.info MyWallet services'''

        # Test if password match at least for the first key
        if doubleKey:
            self.testDoublePK(doubleKey)

        req = 'https://blockchain.info/wallet/' \
              + '%s?format=json&resend_code=false' % (guid)

        # opener = urllib2.build_opener()
        # fh = opener.open(req)
        # encryptedWallet = json.loads(fh.read())['payload']
        encryptedWallet = getDataFromChainblock(req)['payload']

        try:
            data = self.decrypt(key,
                                encryptedWallet.decode('base64', 'strict'))
        except:
            raise WrongPassword('Unknow login')

        try:
            data = json.loads(data)
        except:
            raise WrongPassword('Incorrect password')

        if 'double_encryption' in data:
            isDoubleEncrypted = bool(data['double_encryption'])
        else:
            isDoubleEncrypted = False

        if 'sharedKey' in data:
            sharedKey = data['sharedKey']
        else:
            sharedKey = 'BitPurse'

        for address in data['keys']:
            if not self.isMine(address['addr']):
                address['sharedKey'] = sharedKey
                address['doubleEncrypted'] = isDoubleEncrypted
                if 'tag' not in address:
                    address['tag'] = 0

                if isDoubleEncrypted:
                    address['priv'] = self.decryptPK(address['priv'],
                                                     skey, sharedKey)
                    address['doubleEncrypted'] = False
                    if doubleKey:
                        address['priv'] = self.encryptPK(address['priv'],
                                                         doubleKey,
                                                         address['sharedKey'])
                        address['doubleEncrypted'] = True

                self.addresses.append(Address(jsondict=address))

        print 'Importing Blockchain.info MyWallet'
        self.store(passKey)
Ejemplo n.º 3
0
    def importFromBlockchainInfoWallet(self, passKey, guid, key,
                                       skey, doubleKey=''):
        '''Import wallet from BlockChain.info MyWallet services'''

        # Test if password match at least for the first key
        if doubleKey:
            self.testDoublePK(doubleKey)

        req = 'https://blockchain.info/wallet/' \
              + '%s?format=json&resend_code=false' % (guid)

        # opener = urllib2.build_opener()
        # fh = opener.open(req)
        # encryptedWallet = json.loads(fh.read())['payload']
        encryptedWallet = getDataFromChainblock(req)['payload']

        try:
            data = self.decrypt(key,
                                encryptedWallet.decode('base64', 'strict'))
        except:
            raise WrongPassword('Unknow login')

        try:
            data = json.loads(data)
        except:
            raise WrongPassword('Incorrect password')

        if 'double_encryption' in data:
            isDoubleEncrypted = bool(data['double_encryption'])
        else:
            isDoubleEncrypted = False

        if 'sharedKey' in data:
            sharedKey = data['sharedKey']
        else:
            sharedKey = 'BitPurse'

        for address in data['keys']:
            if not self.isMine(address['addr']):
                address['sharedKey'] = sharedKey
                address['doubleEncrypted'] = isDoubleEncrypted
                if 'tag' not in address:
                    address['tag'] = 0

                if isDoubleEncrypted:
                    address['priv'] = self.decryptPK(address['priv'],
                                                     skey, sharedKey)
                    address['doubleEncrypted'] = False
                    if doubleKey:
                        address['priv'] = self.encryptPK(address['priv'],
                                                         doubleKey,
                                                         address['sharedKey'])
                        address['doubleEncrypted'] = True

                self.addresses.append(Address(jsondict=address))

        print 'Importing Blockchain.info MyWallet'
        self.store(passKey)
Ejemplo n.º 4
0
 def getInputs(self, addr):
     inputs = []
     request = 'http://blockchain.info/unspent?address=%s' % addr
     for unspent in getDataFromChainblock(request)['unspent_outputs']:
         inputs.append((addr,
                        unspent['value'],
                        self.reverse_hash(unspent['tx_hash']),
                        unspent['tx_output_n'],
                        unspent['script'],
                        [(None,
                        None)]))
     return inputs
Ejemplo n.º 5
0
 def _updateFiat(self,):
     req = 'https://blockchain.info/ticker'
     data = getDataFromChainblock(req)
     self._fiatRate = data[self.settings.fiatCurrency]['15m']
     self._fiatSymbol = data[self.settings.fiatCurrency]['symbol']
Ejemplo n.º 6
0
    def load_txs_from_blockchain(self,):
        req = ('https://blockchain.info/multiaddr'
               + '?format=json&filter=0&offset=0'
               + '&active=%s&archived=%s'
               % ('|'.join(self.getActiveAddrAddresses()),
               '|'.join(self.getArchivedAddrAddresses())))

        data = getDataFromChainblock(req)

        try:
            self.balance = data['wallet']['final_balance']
        except KeyError:
            print 'Final balance not in the json data'

        try:
            for address in data['addresses']:
                try:
                    for addr in self.addresses:
                        if address['address'] == addr.addr:
                            addr.balance = address['final_balance']
                except KeyError, err:
                    print err
        except KeyError:
            print 'None address in json data'

        try:
            for tx in data['txs']:
                try:
                    txAddresses = {}
                    txDst = []
                    confirmations = 0
                    if 'block_height' in tx:
                        confirmations = \
                            data['info']['latest_block']['height'] \
                            - tx['block_height'] + 1
                    for txout in tx['out']:
                        if self.isMine(txout['addr']):
                            if not txout['addr'] in txAddresses:
                                txAddresses[txout['addr']] = 0
                            txAddresses[txout['addr']] += txout['value']
                        if not txout['addr'] in txDst:
                            txDst.append(txout['addr'])
                    for txin in tx['inputs']:
                        if self.isMine(txin['prev_out']['addr']):
                            if not txin['prev_out']['addr'] in txAddresses:
                                txAddresses[txin['prev_out']['addr']] = 0
                            txAddresses[txin['prev_out']['addr']] -= \
                                txin['prev_out']['value']
                        if not txin['prev_out']['addr'] in txDst:
                            txDst.append(txin['prev_out']['addr'])

                    for txAddress in txAddresses:
                        self.addTransactionHistForAddress(
                            txAddress,
                            TransactionHist(
                                tx['hash'],
                                tx['time'],
                                '\n'.join(list(set(txDst)
                                .difference([txAddress, ]))),
                                txAddresses[txAddress], confirmations))

                except KeyError, err:
                    print err
        except KeyError:
            print 'None tx in json data'
Ejemplo n.º 7
0
 def _updateFiat(self,):
     req = 'https://blockchain.info/ticker'
     data = getDataFromChainblock(req)
     self._fiatRate = data[self.settings.fiatCurrency]['15m']
     self._fiatSymbol = data[self.settings.fiatCurrency]['symbol']
Ejemplo n.º 8
0
    def load_txs_from_blockchain(self,):
        req = ('https://blockchain.info/multiaddr'
               + '?format=json&filter=0&offset=0'
               + '&active=%s&archived=%s'
               % ('|'.join(self.getActiveAddrAddresses()),
                  '|'.join(self.getArchivedAddrAddresses())))

        data = getDataFromChainblock(req)
        try:
            self.balance = data['wallet']['final_balance']
        except KeyError:
            print 'Final balance not in the json data'

        try:
            for address in data['addresses']:
                try:
                    for addr in self.addresses:
                        if address['address'] == addr.addr:
                            addr.balance = address['final_balance']
                except KeyError, err:
                    print err
        except KeyError:
            print 'None address in json data'

        try:
            for tx in data['txs']:
                try:
                    txAddresses = {}
                    txDst = []
                    confirmations = 0
                    if 'block_height' in tx:
                        confirmations = \
                            data['info']['latest_block']['height'] \
                            - tx['block_height'] + 1
                    for txout in tx['out']:
                        if self.isMine(txout['addr']):
                            if not txout['addr'] in txAddresses:
                                txAddresses[txout['addr']] = 0
                            txAddresses[txout['addr']] += txout['value']
                        if not txout['addr'] in txDst:
                            txDst.append(txout['addr'])
                    for txin in tx['inputs']:
                        if self.isMine(txin['prev_out']['addr']):
                            if not txin['prev_out']['addr'] in txAddresses:
                                txAddresses[txin['prev_out']['addr']] = 0
                            txAddresses[txin['prev_out']['addr']] -= \
                                txin['prev_out']['value']
                        if not txin['prev_out']['addr'] in txDst:
                            txDst.append(txin['prev_out']['addr'])

                    for txAddress in txAddresses:
                        self.addTransactionHistForAddress(
                            txAddress,
                            TransactionHist(
                                tx['hash'],
                                tx['time'],
                                '\n'.join(list(set(txDst)
                                               .difference([txAddress, ]))),
                                txAddresses[txAddress], confirmations))

                except KeyError, err:
                    print err
        except KeyError:
            print 'None tx in json data'