def test_is_bip69_with_properly_sorted_inputs_and_outputs(self): BIP_69_TX_JSON = """ { "vin": [ { "txid": "28e0fdd185542f2c6ea19030b0796051e7772b6026dd5ddccd7a2f93b73e6fc2", "vout": 0 }, { "txid": "643e5f4e66373a57251fb173151e838ccd27d279aca882997e005016bb53d5aa", "vout": 0 } ], "vout": [ { "value": 4.00057456, "n": 0, "scriptPubKey": { "hex": "76a9144a5fba237213a062f6f57978f796390bdcf8d01588ac" } }, { "value": 400, "n": 1, "scriptPubKey": { "hex": "76a9145be32612930b8323add2212a4ec03c1562084f8488ac" } } ] } """ txn = json.loads(BIP_69_TX_JSON) self.assertTrue(bip69.is_bip69(txn))
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 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_is_bip69_with_properly_sorted_inputs_and_outputs(self): """Test a synthesized transaction that is BIP-69 compliant.""" self.assertTrue(bip69.is_bip69(self.bip69_synth))
def test_is_bip69_0a6a357e(self): """Test a transaction that isn't bip-69 compliant""" self.assertFalse(bip69.is_bip69(self.tx_json_0a6a357e))
def test_is_bip69_0a6a357e(self): tx_0a6a357e = json.loads(TX_0a6a357e) self.assertFalse(bip69.is_bip69(tx_0a6a357e))