bitcoin core – In Python RPC calls, how is the vout address derived for a P2PK transaction?


How is the vout address derived for a P2PK transaction? I'm using the Python API provided with Bitcoin source code, in the directory bitcoin/test/functional. j & # 39; uses regtest.

I wrote a unit test. It creates a transaction, writes the CTransaction object to the log file, then adds a CTxOut object to the vout array and writes the CTransaction object back to the log. The second log entry shows that the array element vout includes an array of addresses containing a single value, 'muXtVbAXxTdAdaS9HQLnexRvsfgVteZcv8'. How was this value derived?

Here is the relevant piece of code:

    addr1 = w0_rpc.getnewaddress()
    self.log.info(f"n    DEBUG addr1={addr1}")
    a1 = w0_rpc.getaddressinfo(addr1)
    pubkey1 = hex_str_to_bytes(a1('pubkey'))
    self.log.info(f"n    DEBUG pubkey1={pubkey1}")
    p2pk1 = CScript((pubkey1, OP_CHECKSIG))
    self.log.info(f"n    DEBUG bytes_to_hex_str(p2pk1)={bytes_to_hex_str(p2pk1)}")
    tx1 = CTransaction()
    tx1.vin.append(CTxIn(COutPoint(int(txid0, 16), v), b""))
    s = pprint.pformat(w0_rpc.decoderawtransaction(ToHex(tx1)))
    self.log.info(f"n    DEBUG tx={s}")
    tx1.vout.append(CTxOut(int(9 * COIN), p2pk1))
    s = pprint.pformat(w0_rpc.decoderawtransaction(ToHex(tx1)))
    self.log.info(f"n    DEBUG tx={s}")

You will find below the log output of this code. You can see at the end that the array contains an element that includes an array of addresses containing a single value, 'muXtVbAXxTdAdaS9HQLnexRvsfgVteZcv8'. I did not explicitly provide this value, at least not knowingly. It seems to me that the value has been derived somewhere under the hood. Where did it happen? How was the value calculated?

    DEBUG addr1=2NGYQt1CxwSCdGbj8mpxMtLaTZtxHsmbqWM
2019-10-10T12:13:06.176000Z TestFramework (INFO): 
    DEBUG pubkey1=b'x02#x9cxabCVRLxc1xd1o8}x0ex85Z myQ-&x06xb2xc2xea xfaxf0(xd3ex98'
2019-10-10T12:13:06.176000Z TestFramework (INFO): 
    DEBUG bytes_to_hex_str(p2pk1)=2102239cab4356524cc1d16f387d0e855a206d79512d2606b2c2ea20faf028d36598ac
2019-10-10T12:13:06.177000Z TestFramework (INFO): 
    DEBUG tx={'hash': '0abb1fa572d89323429fc231fcede74af58f77469a3b383ee856db60ecee41a4',
 'locktime': 0,
 'size': 51,
 'txid': '0abb1fa572d89323429fc231fcede74af58f77469a3b383ee856db60ecee41a4',
 'version': 1,
 'vin': ({'scriptSig': {'asm': '', 'hex': ''},
          'sequence': 0,
          'txid': '9d177bb43b76dcbbf52fad079c4fd98986b32034d91ea12bcb4e67d32dc20f9b',
          'vout': 0}),
 'vout': (),
 'vsize': 51,
 'weight': 204}
2019-10-10T12:13:06.179000Z TestFramework (INFO): 
    DEBUG tx={'hash': 'd86153fc539e699289dc8f7f4e20d10f6378fa4f10dad131f5c8b2d4bc7e5c76',
 'locktime': 0,
 'size': 95,
 'txid': 'd86153fc539e699289dc8f7f4e20d10f6378fa4f10dad131f5c8b2d4bc7e5c76',
 'version': 1,
 'vin': ({'scriptSig': {'asm': '', 'hex': ''},
          'sequence': 0,
          'txid': '9d177bb43b76dcbbf52fad079c4fd98986b32034d91ea12bcb4e67d32dc20f9b',
          'vout': 0}),
 'vout': ({'n': 0,
           'scriptPubKey': {'addresses': ('muXtVbAXxTdAdaS9HQLnexRvsfgVteZcv8'),
                            'asm': '02239cab4356524cc1d16f387d0e855a206d79512d2606b2c2ea20faf028d36598 '
                                   'OP_CHECKSIG',
                            'hex': '2102239cab4356524cc1d16f387d0e855a206d79512d2606b2c2ea20faf028d36598ac',
                            'reqSigs': 1,
                            'type': 'pubkey'},
           'value': Decimal('9.00000000')}),
 'vsize': 95,
 'weight': 380}