Author

Topic: Help parsing blockchain.info transactions... (Read 647 times)

sr. member
Activity: 467
Merit: 266
December 19, 2014, 12:33:24 PM
#7
To cover all cases, you need to scan both inputs and outputs for your address. Tally the amount on each side. You receive money if the total outputs > the total inputs.
Remember that you can be spending more than one prev output and could be receiving into several outputs.
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
December 19, 2014, 12:30:16 PM
#6
My friend helped me find the answer to this.

I have to use:
Code:
["inputs"][0]["prev_out"]

Instead of:
Code:
["out"][1]

Thank you DannyHamilton for your patience and help!
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
December 19, 2014, 12:07:10 PM
#5
I'm still having a difficult time understanding what you're trying to do.

You say, "the address that I am receiving the json from", but addresses don't send json.  Addresses receive bitcoins. Therefore, you can't receive json from an address.

I prefer not to click links to external sites, so I haven't been able to look at your code yet.  Assuming that you are requesting json data from blockchain.info for a specific transactionID...

Are you saying that you want to do nothing at all if there isn't exactly one "sending address", and that you want to do nothing at all if there isn't exactly one "receiving address", and that if there is exactly one of each then you want to display the single "sending" address?

You are aware that MOST transactions will have more than one "receiving" address, right? (one for the bitcoins "spent" and one for the "change") Therefore most of the time you will display "nothing".
I know you don't receive json from addresses, but I was referring to the link where I referenced the json in my code.
https://blockchain.info/address/1B1o3cW1nbfh68UE4GT9WNn7rL4YVUhbb8?filter=2&format=json

I just want to display how much ^ Address received, along with the address that sent it.

Here is my code since you don't trust links:
Code:
        $ch curl_init(); 

        
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
        
curl_setopt($chCURLOPT_URL"https://blockchain.info/address/1B1o3cW1nbfh68UE4GT9WNn7rL4YVUhbb8?filter=2&format=json");

        
$output curl_exec($ch); 

        
curl_close($ch);      

        
$a=json_decode($output,TRUE);
?>


   
       
       
       
   
if (is_array($a["txs"])) { ?>
    foreach ($a["txs"] as $tx) { ?>
       

           
           
           
       
    ?>
?>

            Date Received
       

            Address(es)
       

            Received
       

                (date("Y-m-d",$tx["time"])); ?>
           

                ($tx["out"][1]["addr"]); ?>
           

                (round($tx["out"][1]["value"]/1000000004)); ?> BTC(($tx["hash"]); ?>">TX)
           
legendary
Activity: 3416
Merit: 4658
December 19, 2014, 12:00:42 PM
#4
I need help parsing blockchain.info transactions.

Right now I have this code here: Google Doc

I have it taking the second ["out"] but, that does not always work because
every transaction does not have two inputs, and the second ["out"] is not always
actual input address.

Long story short, I need to know how to select the actual values of the received amounts, along with the true sending address.

There won't always be a "sending address" and there might be multiple "sending addresses".  You can't count on the "sending address" belonging to the sender, and if there are multiple addresses, you can't even count on them all belonging to the same person.

Unless you are the sender or the receiver it is impossible to tell with certainty which of the outputs is the "spent" output, and which is the "change".  It is possible for all the outputs in a transaction to effectively be "change" without any "spent" outputs at all.  It is also possible for all the outputs in a transaction to be "spent" outputs without any "change" at all.  For that matter, it is even possible that some outputs are neither "spent" nor "change" (when the script is OP_RETURN).

Perhaps you should describe what you are trying to accomplish, instead of how you are trying to do it.  It sounds like you are starting from a flawed understanding of how bitcoin works, and are therefore not implementing your end goal in the best possible way.
Okay, here is what I'm wanting to accomplish.
I want to display the address that sent the btc to the address that I am receiving the json from, along with the amount received.

It's as simple as that... and if there are multiple addresses, I don't want that transaction to be displayed.

I'm still having a difficult time understanding what you're trying to do.

You say, "the address that I am receiving the json from", but addresses don't send json.  Addresses receive bitcoins. Therefore, you can't receive json from an address.

I prefer not to click links to external sites, so I haven't been able to look at your code yet.  Assuming that you are requesting json data from blockchain.info for a specific transactionID...

Are you saying that you want to do nothing at all if there isn't exactly one "sending address", and that you want to do nothing at all if there isn't exactly one "receiving address", and that if there is exactly one of each then you want to display the single "sending" address?

You are aware that MOST transactions will have more than one "receiving" address, right? (one for the bitcoins "spent" and one for the "change") Therefore most of the time you will display "nothing".
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
December 19, 2014, 11:50:27 AM
#3
I need help parsing blockchain.info transactions.

Right now I have this code here: Google Doc

I have it taking the second ["out"] but, that does not always work because
every transaction does not have two inputs, and the second ["out"] is not always
actual input address.

Long story short, I need to know how to select the actual values of the received amounts, along with the true sending address.

There won't always be a "sending address" and there might be multiple "sending addresses".  You can't count on the "sending address" belonging to the sender, and if there are multiple addresses, you can't even count on them all belonging to the same person.

Unless you are the sender or the receiver it is impossible to tell with certainty which of the outputs is the "spent" output, and which is the "change".  It is possible for all the outputs in a transaction to effectively be "change" without any "spent" outputs at all.  It is also possible for all the outputs in a transaction to be "spent" outputs without any "change" at all.  For that matter, it is even possible that some outputs are neither "spent" nor "change" (when the script is OP_RETURN).

Perhaps you should describe what you are trying to accomplish, instead of how you are trying to do it.  It sounds like you are starting from a flawed understanding of how bitcoin works, and are therefore not implementing your end goal in the best possible way.

Okay, here is what I'm wanting to accomplish.
I want to display the address that sent the btc to the address that I am receiving the json from, along with the amount received.

It's as simple as that... and if there are multiple addresses, I don't want that transaction to be displayed.
legendary
Activity: 3416
Merit: 4658
December 19, 2014, 11:39:53 AM
#2
I need help parsing blockchain.info transactions.

Right now I have this code here: Google Doc

I have it taking the second ["out"] but, that does not always work because
every transaction does not have two inputs, and the second ["out"] is not always
actual input address.

Long story short, I need to know how to select the actual values of the received amounts, along with the true sending address.

There won't always be a "sending address" and there might be multiple "sending addresses".  You can't count on the "sending address" belonging to the sender, and if there are multiple addresses, you can't even count on them all belonging to the same person.

Unless you are the sender or the receiver it is impossible to tell with certainty which of the outputs is the "spent" output, and which is the "change".  It is possible for all the outputs in a transaction to effectively be "change" without any "spent" outputs at all.  It is also possible for all the outputs in a transaction to be "spent" outputs without any "change" at all.  For that matter, it is even possible that some outputs are neither "spent" nor "change" (when the script is OP_RETURN).

Perhaps you should describe what you are trying to accomplish, instead of how you are trying to do it.  It sounds like you are starting from a flawed understanding of how bitcoin works, and are therefore not implementing your end goal in the best possible way.
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
December 19, 2014, 10:15:06 AM
#1
I need help parsing blockchain.info transactions.

Right now I have this code here: Google Doc

I have it taking the second ["out"] but, that does not always work because
every transaction does not have two inputs, and the second ["out"] is not always
actual input address.

Long story short, I need to know how to select the actual values of the received amounts, along with the true sending address.
Jump to: