Bitcoin Forum
May 30, 2024, 02:18:45 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Why does this Python code fail to find the source input address I'm looking for?  (Read 712 times)
derrend (OP)
Hero Member
*****
Offline Offline

Activity: 707
Merit: 505



View Profile WWW
May 16, 2014, 09:29:37 AM
 #1

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

Activity: 4382
Merit: 3061


Vile Vixen and Miss Bitcointalk 2021-2023


View Profile
May 16, 2014, 03:06:51 PM
 #2

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.

Will pretend to do unspeakable things (while actually eating a taco) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
I am not on the scammers' paradise known as Telegram! Do not believe anyone claiming to be me off-forum without a signed message from the above address! Accept no excuses and make no exceptions!
DannyHamilton
Legendary
*
Offline Offline

Activity: 3402
Merit: 4657



View Profile
May 16, 2014, 07:22:47 PM
 #3

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.
derrend (OP)
Hero Member
*****
Offline Offline

Activity: 707
Merit: 505



View Profile WWW
May 16, 2014, 09:51:12 PM
 #4

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?
DannyHamilton
Legendary
*
Offline Offline

Activity: 3402
Merit: 4657



View Profile
May 16, 2014, 10:12:41 PM
 #5

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.
derrend (OP)
Hero Member
*****
Offline Offline

Activity: 707
Merit: 505



View Profile WWW
May 16, 2014, 11:14:20 PM
 #6

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?
dabura667
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
May 17, 2014, 05:09:28 PM
 #7

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.

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
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!