Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: mnemonix on April 21, 2013, 07:57:48 AM



Title: [SOLVED] Sender-Address of ScriptSig
Post by: mnemonix on April 21, 2013, 07:57:48 AM
Hi all,

I've been fighting with jsonrpc and bitcoind for about 2 days ...  :(

I still have the problem that I can't determine the sender address of received payments.

One easy solution would have been to simple grab the VOut of the previos transaction and extract the sender from there but bitcoind doesn't save transactions for which there are no private keys in the wallet. And I didn't figure out how I could motivate bitcoind to ask the p2p-network for details to a transaction with hash=X.

Currently, I know the pubkey of the sender has to be in scriptsig somewhere but it seems to be impossible to extract it from there.

After googling a lot, I didn't find any sample codes extracting the hash and converting it to a base58 address.

Coule someone please give me some tips?

Thank you in advance!

All the best,
Thomas


Title: Re: Sender-Address of ScriptSig
Post by: mnemonix on April 21, 2013, 08:17:00 AM
Finally figured it out with bitcoinj ...

Code:
	private static String s="483045022001bef6b42a6a7cb4dfac6ce93982b0d0a0f3bf0fe55134c278e2a6726d11c596022100fec6b4acd6364007334ec6359a5a5bdde055624824de5f8c0dca064564856f51012103a097b85e726f5e66232c33da2eca4bb0936d8d30a4c721abd0a1717cc5c06708";

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

/**
* @param args
* @throws ScriptException
*/
public static void main(String[] args) throws ScriptException {
TransactionInput tin = new TransactionInput(NetworkParameters.testNet3(), null, hexStringToByteArray(s));
Address a = tin.getScriptSig().getFromAddress();
System.out.println(a.toString());
}

The code outputs correctly "mkMUgWeh3mfpgvKgjK81rUMqKfNoww7tie" (txid: 1d893276bcae417e39aa08b60d02c9b3d4d5e2380aba6bcf359b6d752923ae9f)


Title: Re: [SOLVED] Sender-Address of ScriptSig
Post by: kjj on April 21, 2013, 12:07:56 PM
You are setting yourself up for trouble.  Bitcoin contains no concept of a "sender".


Title: Re: [SOLVED] Sender-Address of ScriptSig
Post by: CIYAM on April 21, 2013, 12:18:06 PM
Also understand that in general for people using web wallets the UTXO source addresses are *not* their own addresses at all (so sending back to them would actually just be sending money to the service rather than a user of it).


Title: Re: [SOLVED] Sender-Address of ScriptSig
Post by: mnemonix on April 21, 2013, 07:00:56 PM
Also understand that in general for people using web wallets the UTXO source addresses are *not* their own addresses at all (so sending back to them would actually just be sending money to the service rather than a user of it).


That's very interesting ... As I know, satoshidice does exactly the same ... They send the won bitcoins to the sender address back.

I havn't heared of any problems yet ... Do you know more you could tell me about?

This "sending back to sender" is crucial for my development project and it would be good to hear of problems in advance :)

*edit*: ah, here is a interesting discussion about ... it seems you are very right and I should give the opportunity to specify an address to which the money is sent after being processed by my engine ...

https://bitcointalk.org/index.php?topic=77870.120 (https://bitcointalk.org/index.php?topic=77870.120)


Title: Re: [SOLVED] Sender-Address of ScriptSig
Post by: CIYAM on April 22, 2013, 01:59:46 AM
That's very interesting ... As I know, satoshidice does exactly the same ... They send the won bitcoins to the sender address back.

I havn't heared of any problems yet ... Do you know more you could tell me about?

There have been a few topics raised by people who sent money from a Mt. Gox (or other similar) account to SD which means the returns went to Mt. Gox rather than the user (and apparently there are warnings on the SD page about not using web wallets).

*edit*: ah, here is a interesting discussion about ... it seems you are very right and I should give the opportunity to specify an address to which the money is sent after being processed by my engine ...

https://bitcointalk.org/index.php?topic=77870.120 (https://bitcointalk.org/index.php?topic=77870.120)

Yes - that would be the much preferred approach (and *please* don't send back 1 satoshi + fee *signals* like SD does when you lose).


Title: Re: [SOLVED] Sender-Address of ScriptSig
Post by: mnemonix on April 22, 2013, 07:52:05 AM
That's very interesting ... As I know, satoshidice does exactly the same ... They send the won bitcoins to the sender address back.

I havn't heared of any problems yet ... Do you know more you could tell me about?

There have been a few topics raised by people who sent money from a Mt. Gox (or other similar) account to SD which means the returns went to Mt. Gox rather than the user (and apparently there are warnings on the SD page about not using web wallets).

Okay, understood ... This will make my engine much more easier, because I don't have to keep a full transaction index and I don't have to watch my transaction list ...

It's often the case that something is quite difficult to solve when choosing an unnatural way to solve the problem ...


Quote
Yes - that would be the much preferred approach (and *please* don't send back 1 satoshi + fee *signals* like SD does when you lose).

You mean the bitcoin network flooding of small-ammount transactions? :)


Title: Re: [SOLVED] Sender-Address of ScriptSig
Post by: CIYAM on April 22, 2013, 08:35:11 AM
You mean the bitcoin network flooding of small-ammount transactions? :)

Yes - without wanting to get into the debate about scalability it serves little useful purpose to be sending 1 satoshi "signals" through the blockchain.


Title: Re: Sender-Address of ScriptSig
Post by: myohmy81 on January 31, 2015, 07:38:39 AM
Finally figured it out with bitcoinj ...

Code:
	private static String s="483045022001bef6b42a6a7cb4dfac6ce93982b0d0a0f3bf0fe55134c278e2a6726d11c596022100fec6b4acd6364007334ec6359a5a5bdde055624824de5f8c0dca064564856f51012103a097b85e726f5e66232c33da2eca4bb0936d8d30a4c721abd0a1717cc5c06708";

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

/**
* @param args
* @throws ScriptException
*/
public static void main(String[] args) throws ScriptException {
TransactionInput tin = new TransactionInput(NetworkParameters.testNet3(), null, hexStringToByteArray(s));
Address a = tin.getScriptSig().getFromAddress();
System.out.println(a.toString());
}

The code outputs correctly "mkMUgWeh3mfpgvKgjK81rUMqKfNoww7tie" (txid: 1d893276bcae417e39aa08b60d02c9b3d4d5e2380aba6bcf359b6d752923ae9f)

hey i have question

if sendAddress is multisig address(ex https://blockchain.info/tx/ad0c703eb06d9dd9556a160a8cfb318e666cc2baf44a95c826ce8bd0b2bcba9a)

this code available?





Title: Re: Sender-Address of ScriptSig
Post by: dabura667 on January 31, 2015, 11:39:46 AM
Finally figured it out with bitcoinj ...

Code:
	private static String s="483045022001bef6b42a6a7cb4dfac6ce93982b0d0a0f3bf0fe55134c278e2a6726d11c596022100fec6b4acd6364007334ec6359a5a5bdde055624824de5f8c0dca064564856f51012103a097b85e726f5e66232c33da2eca4bb0936d8d30a4c721abd0a1717cc5c06708";

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

/**
* @param args
* @throws ScriptException
*/
public static void main(String[] args) throws ScriptException {
TransactionInput tin = new TransactionInput(NetworkParameters.testNet3(), null, hexStringToByteArray(s));
Address a = tin.getScriptSig().getFromAddress();
System.out.println(a.toString());
}

The code outputs correctly "mkMUgWeh3mfpgvKgjK81rUMqKfNoww7tie" (txid: 1d893276bcae417e39aa08b60d02c9b3d4d5e2380aba6bcf359b6d752923ae9f)

hey i have question

if sendAddress is multisig address(ex https://blockchain.info/tx/ad0c703eb06d9dd9556a160a8cfb318e666cc2baf44a95c826ce8bd0b2bcba9a)

this code available?

The same code should work with BitcoinJ. .getFromAddress() will return P2SH if the ScriptSig is P2SH