0

Getting senders account

Say we got txid by listtransactions:

"txid" : "2ca54b92338e52bbb16562dd7a91e8670d9362bb255e21fb568acc13e732b6b7"

then

getrawtransaction 2ca54b92338e52bbb16562dd7a91e8670d9362bb255e21fb568acc13e732b6b7

and

decoderawtransaction 0100000001b2314a1f3d2552d781836cbf266b558eea31fb9f6b0e6da9340ab12e8760df0b000000006b483045022100dab5b2ef5e5be67fc0421c637c60a3d21064bcc7afe69f86909d0a7f91ae99440220762ad9a1d9c20a22378136e5653c2e7134499d1ac0ed86aba883faa7fbf6753f012102f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2ffffffff02172e0100000000001976a914dc05a2f50f5ae09df42f584f5a5582891a41665088ac2e2f4100000000001976a914380e50d59602e9f9960f893f6f2c0f6eb7791b6088ac00000000

out of which we finally receive:

"asm" : "3045022100dab5b2ef5e5be67fc0421c637c60a3d21064bcc7afe69f86909d0a7f91ae99440220762ad9a1d9c20a22378136e5653c2e7134499d1ac0ed86aba883faa7fbf6753f01 02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2"

So far so good. Last part is publickey, if understand correctly:02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2, which can be translated to address

Then I do following in python to get senders address: import hashlib

pkey="02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2"

ripemd160 = hashlib.new('ripemd160')

ripemd160.update(hashlib.sha256(pkey.decode('hex')).digest())

but ripemd160.hexdigest() returns 8cdd1b71d32e53a9fe326212281a4a99a1c093a8, and thats not what i want.

It should return valid address, and result seems a bit off to me. I think .hexdigest is wrong way to do it, should be converted to base58.

How properly convert ripemd160.digest into account address?

Thanks a lot

3

The bitcoin protocol doesn't really support the concept of a transaction sender.

All you can come up with is an address owned by someone who previously controlled the transaction's outputs, which however might not actually be the sender (e.g. for e-wallets) and who may not actually intend to receive anything there in the first place.

Take some time to see a sample implementation written in C# (GetTransactionSenderAddress()).

  • aware of that, still it is interesting subject. I am aiming at similar to satoshidice system, which prolly was mentioned already 1000000000 times here aiming at ltc, and whats i am really to do, is to implement interesting model of lottery(i am mathematic, not programmer) however - tech stuff needs implementation, and I am puzzled here somewhat. To be honest annoys hell out of me, since i am eager to implement math model to live, and cant get ovet this annoyance – Timo Junolainen Apr 23 '14 at 12:10
  • SatoshiDice became a dead business model the minute a thousand clones popped up, but still it's a good way to get some hands-on experience with the protocol. Just keep in mind that even SatoshiDice often fails to determine the transaction's sender address. The sample code I posted above is tested and works well with fat clients (such as the Bitcoin Core) but it will mostly fail for thin clients and e-wallets. – George Kimionis Apr 23 '14 at 12:18
  • I am not cloning dice, i just find moneygate usable to me. I welcome any idea, to have one, constant, (mine) acc, where anyone at any time can transfer any ammount, provided with reply-to adress, so i can automatically cashout. Besides that i dont rip anything from satoshidice idea, have interesting own ) – Timo Junolainen Apr 23 '14 at 12:32
  • In this case you might want to take a closer look to the refund address facility introduced with the 0.9 client: bitcoin.stackexchange.com/questions/24423/… – George Kimionis Apr 23 '14 at 12:40
  • no.. developing for litecoins. however, i think i can answer my question. – Timo Junolainen Apr 23 '14 at 15:42
0

I think I found solution to problem.. if someone will find it helpful, to get senders address for python:

import json
import bitcoinrpc
conn = bitcoinrpc.connect_to_remote('username', 'password', host='127.0.0.1', port=9332)
accounts=conn.listaccounts()
for a in accounts:
        name=json.dumps(a)
        name = name[1:-1]

        #print name
        tran=conn.listtransactions(name)
        for t in tran:
            act=t
            txid=t.txid
            raw=conn.getrawtransaction(txid,0)
            dec=conn.decoderawtransaction(raw)
            vin=dec['vin'][0]['txid']
            raw=conn.getrawtransaction(vin,0)
            dec=conn.decoderawtransaction(raw)
            vout=dec['vout']
            print json.dumps(vout[0]['scriptPubKey']['addresses'])[2:-2]

also, in config add txindex=1 and run litecoind -reindex from cmdline

  • 1
    props for C# snippet, inspirational. – Timo Junolainen Apr 23 '14 at 19:45
0

Sorry, i guess i misunderstood your question: You have to encode the ripemd160 to base58 as you can see here

def pubKeyToAddr(s):
  ripemd160 = hashlib.new('ripemd160')
  ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
  return utils.base58CheckEncode(0, ripemd160.digest())

Anyway, you can always check the details of how to construct address.
Aditionaly, if you want to use the testnet, remember to replace the first char from 0 to 0x6F like this

  return utils.base58CheckEncode(0x6F, ripemd160.digest())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.