Пример #1
0
def main():
    """Get parameter and print information about tx."""
    txid = None
    if WEB_MODE:
        print "Content-Type: application/json;charset=utf-8\n"
        get_params = cgi.FieldStorage()
        txid = get_params.getvalue('txid')
    else:
        try:
            txid = sys.argv[1]
        except Exception:
            pass

    if not is_txid(txid):
        print_error_msg_and_stop(INVALID_ERR_MSG)

    try:
        rpc_json = http.get_rpc_tx_json(txid)
        if bip69.is_bip69(rpc_json):
            print "{'compatible': 'true'}"
            sys.exit()
        else:
            print "{'compatible': 'false'}"
            sys.exit()
    except Exception:
        print_error_msg_and_stop(GENERIC_ERR_MSG)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
def main():
    """Get parameter and print information about tx."""
    txid = None
    if WEB_MODE:
        print "Content-Type: application/json;charset=utf-8\n"
        get_params = cgi.FieldStorage()
        txid = get_params.getvalue('txid')
    else:
        try:
            txid = sys.argv[1]
        except Exception:
            pass

    if not is_txid(txid):
        print_error_msg_and_stop(INVALID_ERR_MSG)

    try:
        rpc_json = http.get_rpc_tx_json(txid)
        if bip69.is_bip69(rpc_json):
            print "{'compatible': 'true'}"
            sys.exit()
        else:
            print "{'compatible': 'false'}"
            sys.exit()
    except Exception:
        print_error_msg_and_stop(GENERIC_ERR_MSG)
 def test_get_rpc_tx_json(self):
     '''Make sure that data for tx 15796981... is properly formatted.'''
     txid = (
         '15796981d90b9ecbce09a9e8a7b4f447566f2f859b808f4e940fb3b6ac17d3'
         'd5')
     rpc_json = http.get_rpc_tx_json(txid)
     self.assertIn('txid', rpc_json)
     self.assertEqual(rpc_json['txid'], txid)
     self.assertIn('vin', rpc_json)
     self.assertEqual(len(rpc_json['vin']), 4)
     self.assertEqual(
         rpc_json['vin'][0]['txid'],
         ('916d81523a14bb9690f112afe1447893abd8ba4180af855ef4b1'
          '7f336af3ba33'))
     self.assertEqual(rpc_json['vin'][0]['vout'], 0)
     self.assertEqual(
         rpc_json['vin'][1]['txid'],
         ('35ca713f844b6041840ffd89836dd19a3a6add27b2ca45a49c89'
          '7d75991d04f3'))
     self.assertEqual(rpc_json['vin'][1]['vout'], 0)
     self.assertEqual(
         rpc_json['vin'][2]['txid'],
         ('87e73af7a2084d28a803de8817cfccd15cbd3573d21f70adef6d'
          '825a5a702565'))
     self.assertEqual(rpc_json['vin'][2]['vout'], 0)
     self.assertEqual(
         rpc_json['vin'][3]['txid'],
         ('00ec11a92c6b9c1aa4d9cf11c0b655014ba886d1abed3b14a5f3'
          'b185e2e842ac'))
     self.assertEqual(rpc_json['vin'][3]['vout'], 4)
     self.assertIn('vout', rpc_json)
     self.assertEqual(len(rpc_json['vout']), 4)
     self.assertEqual(rpc_json['vout'][0]['value'], 0.02500000)
     self.assertEqual(rpc_json['vout'][0]['scriptPubKey']['hex'],
                      '76a914e364c1eeded620aaa98681e63f59bab28d7aa29f88ac')
     self.assertEqual(rpc_json['vout'][1]['value'], 0.23100000)
     self.assertEqual(rpc_json['vout'][1]['scriptPubKey']['hex'],
                      '76a914ab65580854ae75de97c1e51ad034a1885942054d88ac')
     self.assertEqual(rpc_json['vout'][2]['value'], 0.51000000)
     self.assertEqual(rpc_json['vout'][2]['scriptPubKey']['hex'],
                      '76a9141226fb5ca7bed350ea7d3651b104e2981177675b88ac')
     self.assertEqual(rpc_json['vout'][3]['value'], 0.63502445)
     self.assertEqual(rpc_json['vout'][3]['scriptPubKey']['hex'],
                      '76a9149c2280c4b6bc685ea756ee6dc1d56e34aea2ecae88ac')
 def test_get_rpc_tx_json(self):
     '''Make sure that data for tx 15796981... is properly formatted.'''
     txid = ('15796981d90b9ecbce09a9e8a7b4f447566f2f859b808f4e940fb3b6ac17d3'
             'd5')
     rpc_json = http.get_rpc_tx_json(txid)
     self.assertIn('txid', rpc_json)
     self.assertEqual(rpc_json['txid'], txid)
     self.assertIn('vin', rpc_json)
     self.assertEqual(len(rpc_json['vin']), 4)
     self.assertEqual(rpc_json['vin'][0]['txid'],
                      ('916d81523a14bb9690f112afe1447893abd8ba4180af855ef4b1'
                       '7f336af3ba33'))
     self.assertEqual(rpc_json['vin'][0]['vout'], 0)
     self.assertEqual(rpc_json['vin'][1]['txid'],
                      ('35ca713f844b6041840ffd89836dd19a3a6add27b2ca45a49c89'
                       '7d75991d04f3'))
     self.assertEqual(rpc_json['vin'][1]['vout'], 0)
     self.assertEqual(rpc_json['vin'][2]['txid'],
                      ('87e73af7a2084d28a803de8817cfccd15cbd3573d21f70adef6d'
                       '825a5a702565'))
     self.assertEqual(rpc_json['vin'][2]['vout'], 0)
     self.assertEqual(rpc_json['vin'][3]['txid'],
                      ('00ec11a92c6b9c1aa4d9cf11c0b655014ba886d1abed3b14a5f3'
                       'b185e2e842ac'))
     self.assertEqual(rpc_json['vin'][3]['vout'], 4)
     self.assertIn('vout', rpc_json)
     self.assertEqual(len(rpc_json['vout']), 4)
     self.assertEqual(rpc_json['vout'][0]['value'], 0.02500000)
     self.assertEqual(rpc_json['vout'][0]['scriptPubKey']['hex'],
                      '76a914e364c1eeded620aaa98681e63f59bab28d7aa29f88ac')
     self.assertEqual(rpc_json['vout'][1]['value'], 0.23100000)
     self.assertEqual(rpc_json['vout'][1]['scriptPubKey']['hex'],
                      '76a914ab65580854ae75de97c1e51ad034a1885942054d88ac')
     self.assertEqual(rpc_json['vout'][2]['value'], 0.51000000)
     self.assertEqual(rpc_json['vout'][2]['scriptPubKey']['hex'],
                      '76a9141226fb5ca7bed350ea7d3651b104e2981177675b88ac')
     self.assertEqual(rpc_json['vout'][3]['value'], 0.63502445)
     self.assertEqual(rpc_json['vout'][3]['scriptPubKey']['hex'],
                      '76a9149c2280c4b6bc685ea756ee6dc1d56e34aea2ecae88ac')