def percent_compliant_per_block(block_height, rpc_conn=None):
    """Returns % of transactions in block that are compliant, as float.

    Args:
        block_height (int): Height of block requested.
        rpc_conn (Optional[`bitoind_rpc.RPCConnection`]): A connection class
            to the bitcoind RPC interface for local fetching of blockchain data.
    """
    assert isinstance(block_height, int)
    assert block_height >= 0

    txids = None
    if rpc_conn is not None:
        txids = rpc_conn.get_tx_ids_at_height(block_height)
    else:
        txids = http.get_block_txids(block_height)
    num_compliant = 0
    for txid in txids:
        rpc_tx_json = None
        if rpc_conn is not None:
            rpc_tx_json = rpc_conn.get_decoded_tx(txid)
        else:
            rpc_tx_json = http.get_rpc_tx_json(txid)
        if bip69.is_bip69(rpc_tx_json):
            num_compliant = num_compliant + 1
    return float(num_compliant) / len(txids)
def percent_compliant_per_block(block_height, rpc_conn=None):
    """Returns % of transactions in block that are compliant, as float.

    Args:
        block_height (int): Height of block requested.
        rpc_conn (Optional[`bitoind_rpc.RPCConnection`]): A connection class
            to the bitcoind RPC interface for local fetching of blockchain data.
    """
    assert isinstance(block_height, int)
    assert block_height >= 0

    txids = None
    if rpc_conn is not None:
        txids = rpc_conn.get_tx_ids_at_height(block_height)
    else:
        txids = http.get_block_txids(block_height)
    num_compliant = 0
    for txid in txids:
        rpc_tx_json = None
        if rpc_conn is not None:
            rpc_tx_json = rpc_conn.get_decoded_tx(txid)
        else:
            rpc_tx_json = http.get_rpc_tx_json(txid)
        if bip69.is_bip69(rpc_tx_json):
            num_compliant = num_compliant + 1
    return float(num_compliant) / len(txids)
 def test_get_block_txids(self):
     """Verify that a block height is correctly fetched."""
     block_height = 187
     txids = http.get_block_txids(block_height)
     self.assertEqual(len(txids), 2)
     self.assertIn(('70587f1780ccd2ebbace28a7b33d83d19f4362f10ff7a4ad88f8c41'
                    '3883f94b7'), txids)
     self.assertIn(('4385fcf8b14497d0659adccfe06ae7e38e0b5dc95ff8a13d7c62035'
                    '994a0cd79'), txids)
 def test_get_block_txids(self):
     """Verify that a block height is correctly fetched."""
     block_height = 187
     txids = http.get_block_txids(block_height)
     self.assertEqual(len(txids), 2)
     self.assertIn(
         ('70587f1780ccd2ebbace28a7b33d83d19f4362f10ff7a4ad88f8c41'
          '3883f94b7'), txids)
     self.assertIn(
         ('4385fcf8b14497d0659adccfe06ae7e38e0b5dc95ff8a13d7c62035'
          '994a0cd79'), txids)