Bitcoin Forum
April 25, 2019, 04:09:58 AM *
News: Latest Bitcoin Core release: 0.17.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help understanding payment verification via blockchain.info JSON API  (Read 1485 times)
Ford
Full Member
***
Offline Offline

Activity: 120
Merit: 100



View Profile WWW
July 12, 2013, 12:30:24 PM
 #1

Hi All

Im a simple web developer and trying to understand how to verify payments/transactions.

Can anyone comment on the php code i have so far / test code (i am far from a good php programmer, but get by usually)
And the output as i am not fully understanding it.....
(sorry if these sound dumb questions, but i am loving BitCoin and want to start using it on many more sites!)

Code:

<?php 

$resultBlockHeight 
=  json_decode(file_get_contents('http://blockchain.info/latestblock'));
$current_block_height $resultBlockHeight->height;

$resultBlockChain json_decode(file_get_contents('http://blockchain.info/address/12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L?format=json'));
$total_received =  $resultBlockChain->total_received;
$number_of_transactions $resultBlockChain->n_tx;

if(
$number_of_transactions 0){
$transaction $resultBlockChain->txs;
foreach($transaction as $id){

$transaction_date =  date('d-m-Y G:i:s'$id->time);

if($id->block_height == ''){
$confirmedTransactions 0;
}
else {
$transaction_block_height $id->block_height;
$confirmedTransactions = ($current_block_height $transaction_block_height 1);
}

// test results / output
echo '$total_received '.$total_received.'<br>'
echo '$transaction_date '.$transaction_date .'<br>';
echo '$current_block_height '.$current_block_height.'<br>';
echo '$transaction_block_height '$transaction_block_height .'<br>';
echo '$confirmedTransactions = ' .$confirmedTransactions.'<br>';
// raw array output for $id/traansactions
echo '// trasnsactions output';
echo '<pre> ';
echo print_r($id);
echo '</pre>';

}
}else {
// if number_of_transactions !> 0 
}

if(
$number_of_transactions >= 2){
// fuck knows what to do as it should only be 1.....
}

echo 
'// full object output';
echo 
'<pre>';
echo 
print_r($resultBlockChain);
echo 
'</pre>';


?>



This generates the following output (with my notes and some questions to the side)

Code:

$total_received 10000
$transaction_date 11-07-2013 22:58:02
$current_block_height 246206
$transaction_block_height 246159
$confirmedTransactions = 48

// transactions output
 stdClass Object
(
    [result] => 0  // result number
    [block_height] => 246159 // blockchain height at time of first confirmed transaction
    [time] => 1373601482 // datetime
    [inputs] => Array
        (
            [0] => stdClass Object
                (
                    [prev_out] => stdClass Object // what does prev_out mean?
                        (
                            [n] => 0
                            [value] => 1030000 // i assume this is the total funds moved including spent, change and transaction fee
                            [addr] => 1B5W3zqE3cfnR6Zz5kDokNr1ur1hcc21Ge
                            [tx_index] => 80631906
                            [type] => 0
                        )

                )

        )

    [vout_sz] => 2 // what is this?
    [relayed_by] => 5.9.24.81
    [hash] => d83b05e28786f37700ee10277dde4e485e38f14b25925944dd60b5c4da73d13c
    [vin_sz] => 1  // what is this?
    [tx_index] => 80634444
    [ver] => 1  // what is this?
    [out] => Array
        (
            [0] => stdClass Object
                (
                    [n] => 0
                    [value] => 1010000 // i assume this is change less transaction fee
                    [addr] => 194QwtJQZjzmacigpJnWMqKWp6GQBh7ZAa
                    [tx_index] => 80634444
                    [type] => 0
                )

            [1] => stdClass Object
                (
                    [n] => 1
                    [value] => 10000 // this is the amount i received
                    [addr] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
                    [tx_index] => 80634444
                    [type] => 0
                )

        )

    [size] => 225
)
1

// full object output
stdClass Object
(
    [hash160] => 100d7ae73d621b011eabcb91fd5cd368bf53ea18
    [address] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
    [n_tx] => 1
    [total_received] => 10000
    [total_sent] => 0
    [final_balance] => 10000
    [txs] => Array
        (
            [0] => stdClass Object
                (
                    [result] => 0
                    [block_height] => 246159
                    [time] => 1373601482
                    [inputs] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [prev_out] => stdClass Object
                                        (
                                            [n] => 0
                                            [value] => 1030000
                                            [addr] => 1B5W3zqE3cfnR6Zz5kDokNr1ur1hcc21Ge
                                            [tx_index] => 80631906
                                            [type] => 0
                                        )

                                )

                        )

                    [vout_sz] => 2
                    [relayed_by] => 5.9.24.81
                    [hash] => d83b05e28786f37700ee10277dde4e485e38f14b25925944dd60b5c4da73d13c
                    [vin_sz] => 1
                    [tx_index] => 80634444
                    [ver] => 1
                    [out] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [n] => 0
                                    [value] => 1010000
                                    [addr] => 194QwtJQZjzmacigpJnWMqKWp6GQBh7ZAa
                                    [tx_index] => 80634444
                                    [type] => 0
                                )

                            [1] => stdClass Object
                                (
                                    [n] => 1
                                    [value] => 10000
                                    [addr] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
                                    [tx_index] => 80634444
                                    [type] => 0
                                )

                        )

                    [size] => 225
                )

        )

)
1


I am going to issue a unique payment address to all sales and get the total received to enter into my DB/ecommerce system, but what if someone then pays on the same unique address. is there a better way that i can get the amount actually received rather than the total received? (as if some one can break things, i find they usually will)

Any help at all or advice would be great (and if anyone finds this code or thread useful, great feel free to use it)

Best Regards
Ford

Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1556165398
Hero Member
*
Offline Offline

Posts: 1556165398

View Profile Personal Message (Offline)

Ignore
1556165398
Reply with quote  #2

1556165398
Report to moderator
1556165398
Hero Member
*
Offline Offline

Posts: 1556165398

View Profile Personal Message (Offline)

Ignore
1556165398
Reply with quote  #2

1556165398
Report to moderator
1556165398
Hero Member
*
Offline Offline

Posts: 1556165398

View Profile Personal Message (Offline)

Ignore
1556165398
Reply with quote  #2

1556165398
Report to moderator
ToaDy
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
July 12, 2013, 01:53:40 PM
 #2

Hey man,
For me it seems:
"value The value of the payment received in satoshi (not including fees). Divide by 100000000 to get the value in BTC."

You can find nearly everything in the documentation:
http://blockchain.info/de/api/blockchain_wallet_api



cheers,
Gary
Ford
Full Member
***
Offline Offline

Activity: 120
Merit: 100



View Profile WWW
July 12, 2013, 06:17:57 PM
 #3

Hey man,
For me it seems:
"value The value of the payment received in satoshi (not including fees). Divide by 100000000 to get the value in BTC."

You can find nearly everything in the documentation:
http://blockchain.info/de/api/blockchain_wallet_api



cheers,
Gary

Hi Gary

Thanks for the reply

I am not using the RPC connection as i am after transactions/addresses that are not in the block chain wallet and i think it will only give me details on addresses within the wallet.

I can get the full value form the JSON API, but im wondering out of the various transactions that are returned how to get the transaction that i am after, other than just getting the full received amount

coinprize
Member
**
Offline Offline

Activity: 98
Merit: 10


Invest NASDAQ in Bitcoin


View Profile WWW
July 13, 2013, 02:47:36 AM
 #4

You might wanna to also use the original bitcoin rpc api listtransactions or listsinceblock to get transactions for specific address. check out in here: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

Ford
Full Member
***
Offline Offline

Activity: 120
Merit: 100



View Profile WWW
July 13, 2013, 10:26:58 AM
 #5

You might wanna to also use the original bitcoin rpc api listtransactions or listsinceblock to get transactions for specific address. check out in here: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

Tried that, but it only returns transactions for the accounts held within the bitcoind client, and i did not want to do this as hackers may be able to steel my shiny coins then
I planned to have payments made to an offline wallet.
Please do correct me if i am wrong!
I would be very interested to know if i can get transactions via bitcoind that are not in the same account/wallet (just like blockchain.info somehow manage to do...)
At present i have managed to do it via the BlockChain JSON API, but i worry about scalability (i.e how will blockchain cope if i try to send 10,000+ calls per hour...)

ToaDy
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
July 14, 2013, 03:53:54 PM
 #6

Hey,
I would not worry about this.  Cool

cheers,
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1000


Ian Knowles - CIYAM Lead Developer


View Profile WWW
July 14, 2013, 03:57:18 PM
 #7

I would be very interested to know if i can get transactions via bitcoind that are not in the same account/wallet (just like blockchain.info somehow manage to do...)
At present i have managed to do it via the BlockChain JSON API, but i worry about scalability (i.e how will blockchain cope if i try to send 10,000+ calls per hour...)

You can do this (look at the options for indexing all tx's that were introduced after the levelDB introduction).

To be able to query any tx you'll need to "re-index" (this is another option).

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
Abdussamad
Legendary
*
Offline Offline

Activity: 2086
Merit: 1139



View Profile WWW
July 14, 2013, 05:23:50 PM
 #8


I am going to issue a unique payment address to all sales and get the total received to enter into my DB/ecommerce system, but what if someone then pays on the same unique address. is there a better way that i can get the amount actually received rather than the total received? (as if some one can break things, i find they usually will)

Any help at all or advice would be great (and if anyone finds this code or thread useful, great feel free to use it)

Best Regards
Ford

First up I had no idea you could query blockchain.info data in json format like that. So thanks for that.

Second the solution to your problem is to use a separate address for each transaction. This is actually the recommended way to do things. It will help you to track individual transactions and assign credit to different customers.

Abdussamad
Legendary
*
Offline Offline

Activity: 2086
Merit: 1139



View Profile WWW
July 14, 2013, 05:42:14 PM
 #9

I looked into this a little more and you might be better off using getreceivedbyaddress:

https://blockchain.info/q
http://blockexplorer.com/q

You can see an implementation of this in the function BWWC__getreceivedbyaddress_info in bwwc-utils.php of this WP plugin:

http://wordpress.org/plugins/bitcoin-payments-for-woocommerce/

Abdussamad
Legendary
*
Offline Offline

Activity: 2086
Merit: 1139



View Profile WWW
July 14, 2013, 06:20:24 PM
 #10

Another thing is that there is a question mark on the accuracy of blockchain.info's output when using getreceivedbyaddress. Blockexplorer is correct in this instance:

18+ http://blockexplorer.com/q/getreceivedbyaddress/1H9uAP3x439YvQDoKNGgSYCg3FmrYRzpD2

15+ http://blockchain.info/q/getreceivedbyaddress/1H9uAP3x439YvQDoKNGgSYCg3FmrYRzpD2

I created the following script and it outputs the blockexplorer number both times even when using blockchain.info data:

Code:
<?php
$target_address 
'1H9uAP3x439YvQDoKNGgSYCg3FmrYRzpD2';
$tx json_decodefile_get_contents"http://blockchain.info/address/$target_address?format=json" ), true );

//print_r( $tx );
$sum 0;
foreach( 
$tx'txs' ] as $transaction ) {
foreach( $transaction'out' ] as $output ) {
if( $output'addr' ] == $target_address ) {
//echo $output[ 'value' ]/100000000 . "\n";
$sum += $output'value' ];
}
}
}

echo 
"blockchain.info sum of received: " $sum/100000000;

$bec json_decodefile_get_contents"http://blockexplorer.com/q/mytransactions/$target_address"), true );

//print_r( $bec );
$bec_sum 0;
foreach( 
$bec as $transaction ) {
foreach( $transaction'out' ] as $output ) {
if( $output'address' ] == $target_address ) {
$bec_sum += $output'value' ];
}
}
}

echo 
"\n" "Blockexplorer.com received sum: $bec_sum";

Ford
Full Member
***
Offline Offline

Activity: 120
Merit: 100



View Profile WWW
July 15, 2013, 05:38:42 PM
 #11

I would be very interested to know if i can get transactions via bitcoind that are not in the same account/wallet (just like blockchain.info somehow manage to do...)
At present i have managed to do it via the BlockChain JSON API, but i worry about scalability (i.e how will blockchain cope if i try to send 10,000+ calls per hour...)

You can do this (look at the options for indexing all tx's that were introduced after the levelDB introduction).

To be able to query any tx you'll need to "re-index" (this is another option).


Hello and thanks for the reply

I think i may have worded things wrong by saying "transactions" what i meant is "address" as i dont know the transaction numbers.....
I had tried enabling txindex and re-indexed but it still would not bet details on an "address" that was not in my wallet.
If i have still got this wrong and can get the balance of ANY address please do reply.

Thanks
Ford

Ford
Full Member
***
Offline Offline

Activity: 120
Merit: 100



View Profile WWW
July 15, 2013, 06:02:06 PM
 #12

Hello Again

If anyone does know how i can get bitcoind to provide me details on any address i would be very interested.

After spending the past week integrating a "kind of new ecommerce" system with blockchains JSON API, today i start further development to notice blockchain JSON API is not working......

I should have known better to rely on 3rd parties....

Ford

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!