Example #1
0
class TestElectrum(unittest.TestCase):
    def setUp(self):
        self.server_url = "electrum.cafebitcoin.com"
        self.ei = ElectrumInterface(self.server_url, 50001)
        self.bcs = EnhancedBlockchainState(self.server_url, 50001)
        self.txhash = 'b1c68049c1349399fb867266fa146a854c16cd8a18a01d3cd7921ab9d5af1a8b'
        self.height = 277287
        self.raw_tx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4803273b04062f503253482f049fe1bd5208ee5f364f06648bae2e522cfabe6d6de0a3e574e400f64403ea10de4ff3bc0dcb42d49549e273a9faa4eac33b04734804000000000000000000000001cde08d95000000001976a91480ad90d403581fa3bf46086a91b2d9d4125db6c188ac00000000'
        self.address = '1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj'

    def test_connect(self):
        self.assertRaises(ConnectionError, ElectrumInterface, 'cnn.com', 50001)

    def test_get_utxo(self):
        self.assertEqual(self.ei.get_utxo(self.address), [])

    def test_get_version(self):
        self.assertTrue(float(self.ei.get_version()) >= 0.8)

    def test_get_raw_transaction(self):
        self.assertEqual(self.ei.get_raw_transaction(self.txhash, self.height),
                         self.raw_tx)

        self.assertEqual(self.bcs.get_raw_transaction(self.txhash),
                         self.raw_tx)

    def test_get_height(self):
        self.assertEqual(
            self.bcs.get_tx_block_height(self.txhash)[0], self.height)

    def test_get_tx(self):
        self.assertEqual(self.bcs.get_tx(self.txhash).hash, self.txhash)
Example #2
0
class UTXOFetcher(object):
    """Object which can fetch UTXO's. The main sources are:
    blockchain - blockchain.info can provide utxos through JSON
    testnet    - an open-source block explorer using JSON
    electrum   - stratum-protocol servers
    """
    def __init__(self, params):
        """Create a fetcher object given configuration in <params>
        """
        use = params.get('interface', 'blockchain.info')
        if use == 'blockchain.info':
            self.interface = BlockchainInfoInterface()
        elif use == 'testnet':
            self.interface = AbeInterface()
        elif use == 'electrum':
            electrum_server = params.get(
                'electrum_server', DEFAULT_ELECTRUM_SERVER)
            electrum_port = params.get(
                'electrum_port', DEFAULT_ELECTRUM_PORT)
            self.interface = ElectrumInterface(electrum_server, electrum_port)
        else:
            raise Exception('unknown service for UTXOFetcher')

    def get_for_address(self, address):
        """Returns a UTXO object list for a given address <address>.
        """
        objs = []
        for data in self.interface.get_utxo(address):
            objs.append(UTXO(*data))
        return objs
Example #3
0
class TestElectrum(unittest.TestCase):

    def setUp(self):
        self.server_url = "electrum.cafebitcoin.com"
        self.ei = ElectrumInterface(self.server_url, 50001)
        self.bcs = EnhancedBlockchainState(self.server_url, 50001)
        self.txhash = 'b1c68049c1349399fb867266fa146a854c16cd8a18a01d3cd7921ab9d5af1a8b'
        self.height = 277287
        self.raw_tx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4803273b04062f503253482f049fe1bd5208ee5f364f06648bae2e522cfabe6d6de0a3e574e400f64403ea10de4ff3bc0dcb42d49549e273a9faa4eac33b04734804000000000000000000000001cde08d95000000001976a91480ad90d403581fa3bf46086a91b2d9d4125db6c188ac00000000'
        self.address = '1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj'

    def test_connect(self):
        self.assertRaises(ConnectionError, ElectrumInterface, 'cnn.com', 50001)

    def test_get_utxo(self):
        self.assertEqual(self.ei.get_utxo(self.address), [])

    def test_get_version(self):
        self.assertTrue(float(self.ei.get_version()) >= 0.8)

    def test_get_raw_transaction(self):
        self.assertEqual(self.ei.get_raw_transaction(self.txhash, self.height),
                         self.raw_tx)

        self.assertEqual(self.bcs.get_raw_transaction(self.txhash), self.raw_tx)

    def test_get_height(self):
        self.assertEqual(self.bcs.get_tx_block_height(self.txhash)[0], self.height)

    def test_get_tx(self):
        self.assertEqual(self.bcs.get_tx(self.txhash).hash, self.txhash)
Example #4
0
class UTXOFetcher(object):
    """Object which can fetch UTXO's. The main sources are:
    blockchain - blockchain.info can provide utxos through JSON
    testnet    - an open-source block explorer using JSON
    electrum   - stratum-protocol servers
    """
    def __init__(self, params):
        """Create a fetcher object given configuration in <params>
        """
        use = params.get('interface', 'blockchain.info')
        if use == 'blockchain.info':
            self.interface = BlockchainInfoInterface()
        elif use == 'testnet':
            self.interface = AbeInterface()
        elif use == 'electrum':
            electrum_server = params.get('electrum_server',
                                         DEFAULT_ELECTRUM_SERVER)
            electrum_port = params.get('electrum_port', DEFAULT_ELECTRUM_PORT)
            self.interface = ElectrumInterface(electrum_server, electrum_port)
        else:
            raise Exception('unknown service for UTXOFetcher')

    def get_for_address(self, address):
        """Returns a UTXO object list for a given address <address>.
        """
        objs = []
        for data in self.interface.get_utxo(address):
            objs.append(UTXO(*data))
        return objs
Example #5
0
class TestElectrum(unittest.TestCase):
    def setUp(self):
        self.server_url = "electrum.pdmc.net"
        self.ei = ElectrumInterface(self.server_url, 50001)
        self.bcs = EnhancedBlockchainState(self.server_url, 50001)
        self.txhash = 'b1c68049c1349399fb867266fa146a854c16cd8a18a01d3cd7921ab9d5af1a8b'
        self.height = 277287
        self.raw_tx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4803273b04062f503253482f049fe1bd5208ee5f364f06648bae2e522cfabe6d6de0a3e574e400f64403ea10de4ff3bc0dcb42d49549e273a9faa4eac33b04734804000000000000000000000001cde08d95000000001976a91480ad90d403581fa3bf46086a91b2d9d4125db6c188ac00000000'
        self.address = '1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj'

    def test_connect(self):
        self.assertRaises(ConnectionError, ElectrumInterface, 'cnn.com', 50001)

    def test_get_utxo(self):
        self.assertEqual(self.ei.get_utxo(self.address), [])

    def test_get_version(self):
        self.assertTrue(float(self.ei.get_version()) >= 0.8)

    def test_get_height(self):
        self.assertTrue(self.ei.get_height() > 296217)

    def test_get_header(self):
        result = self.bcs.get_header(self.height)
        self.assertEqual(
            result['merkle_root'],
            'abe428044058494733596dc9477bb4f55a90e5144c122cacb71fa99d85c10d2c')

    def test_get_merkle(self):
        result = self.bcs.get_merkle(self.txhash)
        self.assertEqual(
            result['merkle'][0],
            '6a6daeb0dd244abe80ee740ec8752d18fcdd60247304fd7e2ede371eade2f756')
        self.assertEqual(
            result['merkle'][-1],
            '0a00d7c8fadc81c033c3c8604c4a151186bf733f10948d785a748def401ce3f7')
        self.assertEqual(result['pos'], 0)
        self.assertEqual(result['block_height'], self.height)

    def test_get_raw_transaction(self):
        self.assertEqual(self.ei.get_raw_transaction(self.txhash, self.height),
                         self.raw_tx)

        self.assertEqual(self.bcs.get_raw_transaction(self.txhash),
                         self.raw_tx)

    def test_get_block_height(self):
        self.assertEqual(
            self.bcs.get_tx_block_height(self.txhash)[0], self.height)

    def test_get_tx(self):
        self.assertEqual(self.bcs.get_tx(self.txhash).hash, self.txhash)
Example #6
0
class TestElectrum(unittest.TestCase):

    def setUp(self):
        self.server_url = "electrum.pdmc.net"
        self.ei = ElectrumInterface(self.server_url, 50001)
        self.bcs = EnhancedBlockchainState(self.server_url, 50001)
        self.txhash = 'b1c68049c1349399fb867266fa146a854c16cd8a18a01d3cd7921ab9d5af1a8b'
        self.height = 277287
        self.raw_tx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4803273b04062f503253482f049fe1bd5208ee5f364f06648bae2e522cfabe6d6de0a3e574e400f64403ea10de4ff3bc0dcb42d49549e273a9faa4eac33b04734804000000000000000000000001cde08d95000000001976a91480ad90d403581fa3bf46086a91b2d9d4125db6c188ac00000000'
        self.address = '1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj'

    def test_connect(self):
        self.assertRaises(ConnectionError, ElectrumInterface, 'cnn.com', 50001)

    def test_get_utxo(self):
        self.assertEqual(self.ei.get_utxo(self.address), [])

    def test_get_version(self):
        self.assertTrue(Decimal(self.ei.get_version()) >= 0.8)

    def test_get_height(self):
        self.assertTrue(self.ei.get_height() > 296217)

    def test_get_header(self):
        result = self.bcs.get_header(self.height)
        self.assertEqual(
            result['merkle_root'],
            'abe428044058494733596dc9477bb4f55a90e5144c122cacb71fa99d85c10d2c')

    def test_get_merkle(self):
        result = self.bcs.get_merkle(self.txhash)
        self.assertEqual(
            result['merkle'][0],
            '6a6daeb0dd244abe80ee740ec8752d18fcdd60247304fd7e2ede371eade2f756')
        self.assertEqual(
            result['merkle'][-1],
            '0a00d7c8fadc81c033c3c8604c4a151186bf733f10948d785a748def401ce3f7')
        self.assertEqual(result['pos'], 0)
        self.assertEqual(result['block_height'], self.height)

    def test_get_raw_transaction(self):
        self.assertEqual(self.ei.get_raw_transaction(self.txhash, self.height),
                         self.raw_tx)

        self.assertEqual(self.bcs.get_raw_transaction(self.txhash), self.raw_tx)

    def test_get_block_height(self):
        self.assertEqual(self.bcs.get_tx_block_height(self.txhash)[0], self.height)

    def test_get_tx(self):
        self.assertEqual(self.bcs.get_tx(self.txhash).hash, self.txhash)
class UTXOFetcher(object):
    """Object which can fetch UTXO's. The main sources are:
    blockchain - blockchain.info can provide utxos through JSON
    testnet    - an open-source block explorer using JSON
    electrum   - stratum-protocol servers
    """
    def __init__(self, model, config):
        """Create a fetcher object given configuration in <params>
        """
        self.model = model
        self.coin_manager = model.get_coin_manager()
        params = config.get('utxo_fetcher', {})
        if model.testnet:
            use = 'testnet'
        else:
            use = params.get('interface', 'blockchain.info')
        if use == 'blockchain.info':
            self.interface = BlockchainInfoInterface(self.coin_manager)
        elif use == 'testnet':
            self.interface = AbeInterface()
        elif use == 'electrum':
            electrum_server = params.get(
                'electrum_server', DEFAULT_ELECTRUM_SERVER)
            electrum_port = params.get(
                'electrum_port', DEFAULT_ELECTRUM_PORT)
            self.interface = ElectrumInterface(electrum_server, electrum_port)
        else:
            raise Exception('unknown service for UTXOFetcher')

    def add_utxo(self, address, data):
        self.coin_manager.apply_tx(data[0])
        #self.coin_manager.add_coin(address, *data)

    def scan_address(self, address):
        try:
            for data in self.interface.get_utxo(address):
                self.add_utxo(address, data)
        except Exception as e:
            if "%s" % e != "No JSON object could be decoded":
                print e
                raise

    def scan_all_addresses(self):
        wam = self.model.get_address_manager()
        for address_rec in wam.get_all_addresses():
            self.scan_address(address_rec.get_address())