Author

Topic: How to parse Address in transaction with SegWit script (Read 306 times)

newbie
Activity: 12
Merit: 0

yeaaah!!

Thank You!
legendary
Activity: 3472
Merit: 10611
the transaction you posted is a P2WSH nested in BIP16 P2SH (read more about it here). in such transactions there is a 32 byte hash inside ScriptSig which you have already posted:
Code:
00 20 71191892b7ed5764d72cc7232cf99d722b776240d78eb625c389d7f4d03db874
you perform Hash160 hash function (RIPEMD160 hash of SHA256 hash) on the whole script.
Code:
0bda3cc663d603bacf2df3a3bf756f9c8b68f1cd
then append version byte to the beginning of it
Code:
050bda3cc663d603bacf2df3a3bf756f9c8b68f1cd
finally perform Base58Check (base58 encoding with an appended 4 byte sha256 checksum) on the result
Code:
32mgo47LcUQjPfjYNzAYEsM5fqosiqpuVd

i posted results of each step in case you wanted to check your own calculations against them.
sr. member
Activity: 490
Merit: 389
Do not trust the government
I don't think that witness is used to generate the address, since older wallets shouldn't be able to download witness data, but would still be able to send to segwit addresses.

Also, you need to look at the output of the transaction that was referenced in that first input, I believe, since coins aren't spent from addresses, but from unspent transactions. Addresses are there just for humans.


And there is no other (direct) possibility to make an address?

I cannot turn this script
ScriptSig: PUSHDATA(34) [ 002071191892b7ed5764d72cc7232cf99d722b776240d78eb625c389d7f4d03db874 ]

into the address 32mgo47LcUQjPfjYNzAYEsM5fqosiqpuVd   without searching for the previous out-transaction?

Actually I have no idea.
As far as I remember in scriptsig for legacy transactions you have a public key of that address and a signature for that transaction. And you should be able to hash the public key and encode it to get an address.

However, addresses starting with 3 are P2SH, meaning that instead of a public key and signature, you have a whole script in scriptsig that needs to hash to the output value of that past transactions.
Now, segwit transactions look to legacy clients as anyone-can-spend transactions.
So, I guess, there would be no need to put a public key of the address into segwit as you don't need to provide proof of ownership there. And since segwit is designed to reduce fees and size of scriptsig, I assume they wouldn't put what is unnecessary there.

So actually, I don't know, although it is easier to look up parent transaction and I believe that is how block explorers do it, it still might be possible by hashing the script and encoding it to that address.
Still this means that you don't need a witness for this at all, since even legacy clients (that don't know about witness data) can tell if the address has spent coins or not.

You should be able to find some information online on how to hash and encode the scriptsig into a Bitcoin address.
Just keep in mind that this has nothing to do with segwit, you are simply looking for information on generating P2SH addresses.

Then again, I am not sure about any of this and I could be completely wrong, good luck!

EDIT: This might be the info you are looking for at https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
Code:
base58-encode: [one-byte version][20-byte hash][4-byte checksum]

"Version byte is 5 for a main-network address, 196 for a testnet address. The 20-byte hash is the hash of the script that will be used to redeem the coins. And the 4-byte checksum is the first four bytes of the double SHA256 hash of the version and hash."

Keep in mind that Bitcoin uses specific base58 encoding as well.
newbie
Activity: 12
Merit: 0
I don't think that witness is used to generate the address, since older wallets shouldn't be able to download witness data, but would still be able to send to segwit addresses.

Also, you need to look at the output of the transaction that was referenced in that first input, I believe, since coins aren't spent from addresses, but from unspent transactions. Addresses are there just for humans.


And there is no other (direct) possibility to make an address?

I cannot turn this script
ScriptSig: PUSHDATA(34) [ 002071191892b7ed5764d72cc7232cf99d722b776240d78eb625c389d7f4d03db874 ]

into the address 32mgo47LcUQjPfjYNzAYEsM5fqosiqpuVd   without searching for the previous out-transaction?

legendary
Activity: 3122
Merit: 2178
Playgram - The Telegram Casino
What you are looking for are BIP 13 and BIP 16:

https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki


Note that native SegWit addresses use a different standard, namely Bech32 (starting with bc1, see BIP 173). P2SH SegWit addresses are a more or less temporary solution to enable backwards compatibility.

https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
sr. member
Activity: 490
Merit: 389
Do not trust the government
I don't think that witness is used to generate the address, since older wallets shouldn't be able to download witness data, but would still be able to send to segwit addresses.

Also, you need to look at the output of the transaction that was referenced in that first input, I believe, since coins aren't spent from addresses, but from unspent transactions. Addresses are there just for humans.

The output of that transaction should contain the address you are looking for (I think).
newbie
Activity: 12
Merit: 0

Hi all

I have a some problem with understanding how get address from trabsaction with SegWit script

For example Tx= https://www.blockchain.com/en/btc/tx/72ca3ce16f3eaf008bb8961cb448b2b47bfd4041cec09f90415d70adfda3b142

First Input =

ScriptSig: PUSHDATA(34)[002071191892b7ed5764d72cc7232cf99d722b776240d78eb625c389d7f4d03db874]
Witness: 040047304402203649acfc3c0f5a93358402e17d0fe495b35f076de9a368385aeacfc9d5b748b80 2201b588dd66cf31796ab59373de189763ba14c40a744c95f600789d3c24edd18d1014730440220 5bebf834c28bb59376c4f5b0231d56bcc7b37351c838bc69e04c2de9ade53a0a022028667923002 6ab04350ec205e516d6cc52552846b3760a422a735621b6edba6a0169522103df40e0a39f91ce89 0382ea831870a7ff4a6e847c2a9591d8fb6f1388a64a0ad62103ed888901d2014acc967d0d88ecf acae36a0381012489d4354d167d81113f1f742103f662d4ffb3bbc11230482485b0505075822513 2de9ee281e09ed309892ce314253ae


Can you please describe the algorithm with this example how to get result In-address  32mgo47LcUQjPfjYNzAYEsM5fqosiqpuVd  ?
Jump to: