2
2
tl;dr How should one perform Hash160, using most basic tools?
====================================================
Hi,
I'm trying to figure out, how transactions work in bitcoin.
When I choose inputs for a new tx I want to make sure they belong to a specific address. However, existing txs do not specify previous outputs' addresses, but instead they contain address' hashes.
e.g.:
>> bx fetch-tx 11a1b7ac0a65bd50b7094c720aecd77cfd83d84b1707960fd00dd82a888aab5c --config /home/theo/Desktop/bx-testnet.cfg
{
hash 11a1b7ac0a65bd50b7094c720aecd77cfd83d84b1707960fd00dd82a888aab5c
inputs
{
input
{
address_hash f3b7278583827a049d6be894bf7f516178a0c8e6
previous_output
{
hash 4a3532061d43086299ae9b2409a456bb9638dff32e0858c4ccda27203fb2e4f6
index 1
}
script "[30440220146b8b5b014245a9e27e21122d4dded04c3f39c3a49ac2494743d6f6ae8efff602206d417a4be9c7431ea69699132438510ade1cf8d746607f77d114907762ed1eb301] [023dd2e892290e41bb78efce6ea30a97015ef13eaaa9ebb7b0514485fc365cc391]"
sequence 4294967295
}
}
lock_time 0
outputs
{
output
{
address_hash a73706385fffbf18855f2aee2a6168f29dbb597e
script "dup hash160 [a73706385fffbf18855f2aee2a6168f29dbb597e] equalverify checksig"
value 130000000
}
output
{
address_hash ad6e80394af99ece5d7701bf2f457480b93965b7
script "dup hash160 [ad6e80394af99ece5d7701bf2f457480b93965b7] equalverify checksig"
value 49525957813
}
}
version 1
}
Say, I want to check which of the outputs can be sent from address mvm74FACaagz94rjWbNmW2EmhJdmEGcxpa
So I take its Hash160 in Python:
>> hashlib.new('ripemd160', hashlib.sha256("mvm74FACaagz94rjWbNmW2EmhJdmEGcxpa".encode('utf-8')).digest()).hexdigest()
'748598cd9b004aecf8a2d97464fb1f2a90562ffe'
That is not the result I expected: a73706385fffbf18855f2aee2a6168f29dbb597e
Meanwhile, this online service calculates hash correctly.
How do I Hash160 a bitcoin address, preferably in Python?

while I can't help with python, you may want to look at "http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html", it has good explanation. Also I'm not sure if I understand your logic with the addresses to spend from. You would use the UTXOs from previous transactions... So I'd use "listunspent" in the core wallet, to see the prev tx ID and the vout, to use in a new (unsigned) transaction. An address hash cannot be reversed easily, that's why we have hash functions. Easy to go into one direction, impossible to reverse. That gives us the security in the whole bitcoin network.
– pebwindkraft – 2017-09-20T20:48:53.270@pebwindkraft But I need the script in previous output to sign, don't I? Also, seems to me I got the encoding idea wrong. Hash160 clearly has bytes bigger than 3a (58 decimal), so my decoding function is nonsense – lotrus28 – 2017-09-20T20:52:22.427
yes, you give it the scriptPubKey, see the meanwhile famous 19step example, and some python at the end: here: https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx
– pebwindkraft – 2017-09-20T21:05:00.890