Bitcoin Forum
April 25, 2024, 08:22:22 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to parse Address in transaction with SegWit script  (Read 275 times)
jaruvido (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
November 15, 2018, 01:22:56 PM
 #1


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  ?
1714033342
Hero Member
*
Offline Offline

Posts: 1714033342

View Profile Personal Message (Offline)

Ignore
1714033342
Reply with quote  #2

1714033342
Report to moderator
1714033342
Hero Member
*
Offline Offline

Posts: 1714033342

View Profile Personal Message (Offline)

Ignore
1714033342
Reply with quote  #2

1714033342
Report to moderator
1714033342
Hero Member
*
Offline Offline

Posts: 1714033342

View Profile Personal Message (Offline)

Ignore
1714033342
Reply with quote  #2

1714033342
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714033342
Hero Member
*
Offline Offline

Posts: 1714033342

View Profile Personal Message (Offline)

Ignore
1714033342
Reply with quote  #2

1714033342
Report to moderator
1714033342
Hero Member
*
Offline Offline

Posts: 1714033342

View Profile Personal Message (Offline)

Ignore
1714033342
Reply with quote  #2

1714033342
Report to moderator
1714033342
Hero Member
*
Offline Offline

Posts: 1714033342

View Profile Personal Message (Offline)

Ignore
1714033342
Reply with quote  #2

1714033342
Report to moderator
aleksej996
Sr. Member
****
Offline Offline

Activity: 490
Merit: 389


Do not trust the government


View Profile
November 15, 2018, 03:10:37 PM
 #2

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).
HeRetiK
Legendary
*
Online Online

Activity: 2912
Merit: 2080


Cashback 15%


View Profile
November 15, 2018, 03:27:04 PM
 #3

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

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
jaruvido (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
November 16, 2018, 08:59:31 AM
 #4

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?

aleksej996
Sr. Member
****
Offline Offline

Activity: 490
Merit: 389


Do not trust the government


View Profile
November 17, 2018, 09:04:54 PM
 #5

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.
pooya87
Legendary
*
Offline Offline

Activity: 3430
Merit: 10498



View Profile
November 18, 2018, 05:48:04 AM
Last edit: November 18, 2018, 06:02:55 AM by pooya87
Merited by suchmoon (4), ABCbits (1), bones261 (1), bob123 (1)
 #6

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
jaruvido (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
November 19, 2018, 08:29:07 PM
 #7


yeaaah!!

Thank You!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!