Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: linuxqq on November 17, 2020, 11:48:38 AM



Title: btc rpc how to get the output address
Post by: linuxqq on November 17, 2020, 11:48:38 AM
I am learning the transfer structure of Bitcoin's blockchain. I have encountered a problem and I hope to get help. First of all, thank you. I want to analyze the UTXO transfer in and out of a block, but the following json does not tell Which address did I transfer to, and how do I know which address the expense was transferred to? Why didn't I see vout['scriptPubKey']['addresses'],In the following message'value': Decimal('49.98000000'), how can I know where the 49 BTC went?


{'txid': 'a64be218809b61ac67ddc7f6c7f9fbebfe420cf75fe0318ebc727f060df48b37',
 'hash': 'a64be218809b61ac67ddc7f6c7f9fbebfe420cf75fe0318ebc727f060df48b37', 'version': 1, 'size': 276, 'vsize': 276,
 'weight': 1104, 'locktime': 0, 'vin': [
    {'txid': '131f68261e28a80c3300b048c4c51f3ca4745653ba7ad6b20cc9188322818f25', 'vout': 1, 'scriptSig': {
        'asm': '3045022100ef78daeb60d6332fa6f91ee93d95486d8601b5f2c1d1dc77633801dc6c0eb41902201 5b19e34de00ae729e20b97de8ac58ea8bb9227ba91a33bfaa26b7480e8a0005[ALL]',
        'hex': '483045022100ef78daeb60d6332fa6f91ee93d95486d8601b5f2c1d1dc77633801dc6c0eb419022 015b19e34de00ae729e20b97de8ac58ea8bb9227ba91a33bfaa26b7480e8a000501'},
     'sequence': 4294967295}], 'vout': [{'value': Decimal('0.01000000'), 'n': 0, 'scriptPubKey': {
    'asm': '041d1ffff1175ce4628ed11b4074956a3f0facc95ab388e47b95daa02891f6e0b9642d4ae2b68c0 787d2c95288ec42045a087c262d803b6fa14ecedb2a632f3df1 OP_CHECKSIG',
    'hex': '41041d1ffff1175ce4628ed11b4074956a3f0facc95ab388e47b95daa02891f6e0b9642d4ae2b68 c0787d2c95288ec42045a087c262d803b6fa14ecedb2a632f3df1ac',
    'type': 'pubkey'}}, {'value': Decimal('49.98000000'), 'n': 1, 'scriptPubKey': {
    'asm': '04f9804cfb86fb17441a6562b07c4ee8f012bdb2da5be022032e4b87100350ccc7c0f4d47078b06 c9d22b0ec10bdce4c590e0d01aed618987a6caa8c94d74ee6dc OP_CHECKSIG',
    'hex': '4104f9804cfb86fb17441a6562b07c4ee8f012bdb2da5be022032e4b87100350ccc7c0f4d47078b 06c9d22b0ec10bdce4c590e0d01aed618987a6caa8c94d74ee6dcac',
    'type': 'pubkey'}}],
 'hex': '0100000001258f81228318c90cb2d67aba535674a43c1fc5c448b000330ca8281e26681f1301000 00049483045022100ef78daeb60d6332fa6f91ee93d95486d8601b5f2c1d1dc77633801dc6c0eb4 19022015b19e34de00ae729e20b97de8ac58ea8bb9227ba91a33bfaa26b7480e8a000501fffffff f0240420f00000000004341041d1ffff1175ce4628ed11b4074956a3f0facc95ab388e47b95daa0 2891f6e0b9642d4ae2b68c0787d2c95288ec42045a087c262d803b6fa14ecedb2a632f3df1ac806 de72901000000434104f9804cfb86fb17441a6562b07c4ee8f012bdb2da5be022032e4b87100350 ccc7c0f4d47078b06c9d22b0ec10bdce4c590e0d01aed618987a6caa8c94d74ee6dcac00000000',
 'blockhash': '0000000049a63b4dda3a43450c19d085d6c28bfb4cbb2e0576815d7f31919c5d', 'confirmations': 654530,
 'time': 1233636459, 'blocktime': 1233636459}


Title: Re: btc rpc how to get the output address
Post by: mocacinno on November 17, 2020, 12:27:32 PM
This might be an interesting read for you:
https://learnmeabitcoin.com/technical/p2pk


Title: Re: btc rpc how to get the output address
Post by: linuxqq on November 17, 2020, 12:43:22 PM
This might be an interesting read for you:
https://learnmeabitcoin.com/technical/p2pk

Thank you for your reply. The example in the document you sent has "addresses": [
                     "1Q2TWHE3GMdB6BZKafqwxXtWAWgFt5Jvm3"
                 ], I want to know why the structure I see does not have a wallet address, so I donít know which wallet to transfer to


Title: Re: btc rpc how to get the output address
Post by: mocacinno on November 17, 2020, 12:56:39 PM
It doesn't have a wallet address because it's a "Pay to Pubkey" script.

You're used to see "pay to pubkey hash" scripts... The hash of the pubkey IS the address ;)

In this case, it's just the pubkey... There is no "address"... If you were the owner of this wallet, you could spend the funds by providing a valid signature which can be verified against the pubkey that was funded. That's about it :)

You're just looking at very old blocks, p2pk scripts are very rare nowadays.


Title: Re: btc rpc how to get the output address
Post by: odolvlobo on November 19, 2020, 07:08:25 AM
It doesn't have a wallet address because it's a "Pay to Pubkey" script.

You're used to see "pay to pubkey hash" scripts... The hash of the pubkey IS the address ;)

In this case, it's just the pubkey... There is no "address"... If you were the owner of this wallet, you could spend the funds by providing a valid signature which can be verified against the pubkey that was funded. That's about it :)

You're just looking at very old blocks, p2pk scripts are very rare nowadays.

If you want an address, I suppose you could construct an address from the public key.


Title: Re: btc rpc how to get the output address
Post by: naufragus on November 21, 2020, 04:35:37 PM
If you are using Linux shell and run my script (bitcoin.tx.sh), which is a bitcoin-cli wrapper:

Code:
user@archhost ~ % bitcoin.tx.sh a64be218809b61ac67ddc7f6c7f9fbebfe420cf75fe0318ebc727f060df48b37
txs: 1/1

--------
Transaction information
TxId____: a64be218809b61ac67ddc7f6c7f9fbebfe420cf75fe0318ebc727f060df48b37
Hash____: a64be218809b61ac67ddc7f6c7f9fbebfe420cf75fe0318ebc727f060df48b37
BlkHash_: 0000000049a63b4dda3a43450c19d085d6c28bfb4cbb2e0576815d7f31919c5d
Time____: 1233636459    2009-02-03T04:47:39Z
BlkTime_: 1233636459    2009-02-03T04:47:39Z
LockTime: 0
Version_: 1
Vsize___: 276
Size____: 276
Weight__: 1104
Confirma: 650779

Vins
  TxIndex: 131f68261e28a80c3300b048c4c51f3ca4745653ba7ad6b20cc9188322818f25
  Sequenc: 4294967295
  VoutNum: 1
  Addresses
  Number_: 1    Value__: 49.99
    type: pubkey
    1AbHNFdKJeVL8FRZyRZoiTzG9VCmzLrtvm


Vouts
  Number_: 0    Value__: 0.01
  Addresses
    type: pubkey
    1CbAopr7sNMKjsJa8dAS6P5sM788kmMooo

  Number_: 1    Value__: 49.98
  Addresses
    type: pubkey
    1AbHNFdKJeVL8FRZyRZoiTzG9VCmzLrtvm


VinSum__: 49.99000000
VoutSum_: 49.99000000
TxFee___: 0

>>>final transaction parsing at: /home/user/00.transactions.parsed.txt
>>>took 1 seconds  (0 minutes)

The script uses grondilu's bitcoin-bash-tools to make the address from the pub key..
Script from my githubh repo: https://github.com/mountaineerbr/scripts/blob/master/bitcoin.tx.sh


The next script wraps grondilu's bitcoin bash functions. Here I
get the ASM (assembly) code, pack, double-sha256 and then
convert it to address with byte number 00.

Code:
user@archhost /tmp % bitcoin.hx.sh 041d1ffff1175ce4628ed11b4074956a3f0facc95ab388e47b95daa02891f6e0b9642d4ae2b68c0787d2c95288ec42045a087c262d803b6fa14ecedb2a632f3df1
1CbAopr7sNMKjsJa8dAS6P5sM788kmMooo

user@archhost /tmp % bitcoin.hx.sh 04f9804cfb86fb17441a6562b07c4ee8f012bdb2da5be022032e4b87100350ccc7c0f4d47078b06c9d22b0ec10bdce4c590e0d01aed618987a6caa8c94d74ee6dc
1AbHNFdKJeVL8FRZyRZoiTzG9VCmzLrtvm
https://github.com/mountaineerbr/scripts/blob/master/bitcoin.hx.sh