Author

Topic: Why does this Python code fail to find the source input address I'm looking for? (Read 732 times)

sr. member
Activity: 475
Merit: 252
Mimicking their mistake will only result in unnecessary problems for you.
Shame. Do we happen to have any idea when the btc payment protocol will be released? I have seen a few posts about it around the net but nothing really concrete. Incidentally alsbo do you know what is the minimum amount of btc i am able to send over the network, for example 0.00000001 would cost 0.0001 to send. Does the network accept this?

If any outputs of a transaction are less than 5430 satoshis (0.0000543 BTC) it will not be mined.
hero member
Activity: 707
Merit: 505
Mimicking their mistake will only result in unnecessary problems for you.
Shame. Do we happen to have any idea when the btc payment protocol will be released? I have seen a few posts about it around the net but nothing really concrete. Incidentally alsbo do you know what is the minimum amount of btc i am able to send over the network, for example 0.00000001 would cost 0.0001 to send. Does the network accept this?
legendary
Activity: 3472
Merit: 4801
I'm trying to mimic satoshi dice.

That is a bad idea.  Please don't.  Theirs is a flawed and incorrect model.  Mimicking their mistake will only result in unnecessary problems for you.
hero member
Activity: 707
Merit: 505
What are you really trying to do?
I'm trying to mimic satoshi dice. They return funds to their customers using output addresses, I understand it isn't perfect but what is their method?
legendary
Activity: 3472
Merit: 4801
There's no such thing as a return address in Bitcoin. Don't try to "derive" one; the address you derive will not necessarily be what you expect it to be. What are you really trying to do? If you need to return bitcoins that have previously been sent to you, the correct solution in almost all cases is to just ask for an address.

What Foxpup said is correct.  You should not be trying to guess where someone wants to receive bitcoins.  You will guess incorrectly sometimes.  When people send you bitcoins, they don't always have control over which address was previously used to receive those bitcoins.

As for the bug in your code that is causing the behavior that you are asking about, as far as I can tell:

You aren't storing the vout value from the input.  A transaction can have (and often does have) multiple outputs.  When using a previously unspent output as an input for a transaction, the vout value is an index indicating which of the outputs from the transaction are being spent. If you don't limit your query to this single output, then you will stumble across all the other outputs that the transaction created.
legendary
Activity: 4536
Merit: 3188
Vile Vixen and Miss Bitcointalk 2021-2023
I don't have enough caffeine to read your code right now, but that's not your biggest problem anyway...

Sometimes though the return address derived...
There's no such thing as a return address in Bitcoin. Don't try to "derive" one; the address you derive will not necessarily be what you expect it to be. What are you really trying to do? If you need to return bitcoins that have previously been sent to you, the correct solution in almost all cases is to just ask for an address.
hero member
Activity: 707
Merit: 505
What this code is supposed to do:-

From the decoded raw transaction(s) found in the vin section of a decoded raw transaction I just received, I scrape every vout address and put them in a list.
I then remove addresses if identical to my company address or any address in my wallet.

Code:
    vins = decoderawtransaction(getrawtransaction(input_transaction_hash, verbose=False))['vin']
    vin_lst = []
    c = 0
    
    while c < len(vins):
        vin_lst.append(vins[c]['txid'])
        c += 1
    
    vout_lst = []
    
    for i in vin_lst:
        vouts = decoderawtransaction(getrawtransaction(i, verbose=False))['vout']
        c = 0
    
        while c < len(vouts):
            v = vouts[c]['scriptPubKey']['addresses'][0]
    
            if v != input_address and v not in getaddressesbyaccount('customer'):
                vout_lst.append(v)
    
        c += 1
    
    return_address = vout_lst[0]

Sometimes though the return address derived sends the funds to my wallet for some reason I don't understand.

It may be worth mentioning that i have been sending the funds between only two wallets during testing and wonder if this could be a possible reason?
I am using two instances of bitcoind each in a virtual machine.
Jump to: