Author

Topic: Not sure if this is specifically an RPC problem or code change... (Read 150 times)

jr. member
Activity: 134
Merit: 3
Not worth trying to figure out what client would work. That being said, anyone know where to begin to make it work again while the getinfo is still available ?

Ty.
staff
Activity: 3458
Merit: 6793
Just writing some code
I looked at my client again, getinfo still produces data but with the deprecated warning as part of the array now. So why the code I'm using thats not working but was about a yr ago is now not working. I don't know but would like to find out.

The node I run is of no real signifigance, so if I end up having to keep an older client for the use of getinfo is fine with me.
The data type of getinfo is a JSON object, but your script expects a JSON array. It must have changed data types since your script was written.
jr. member
Activity: 134
Merit: 3
I looked at my client again, getinfo still produces data but with the deprecated warning as part of the array now. So why the code I'm using thats not working but was about a yr ago is now not working. I don't know but would like to find out.

The node I run is of no real signifigance, so if I end up having to keep an older client for the use of getinfo is fine with me.
staff
Activity: 3458
Merit: 6793
Just writing some code
The getinfo RPC command which your script relies on has been removed from Bitcoin Core. You should be able to replace it with the getblockchaininfo command.
legendary
Activity: 3374
Merit: 3095
Playbet.io - Crypto Casino and Sportsbook
Maybe this one could help recently updated 13 days ago.
https://github.com/fguillot/JsonRPC
Just test them first because never tested it..
jr. member
Activity: 134
Merit: 3
Been a few servers ago and client iterations since I have used this but what once pulled stats from my home node, no longer works.

But I know RPC is working with something else right now so not sure what to make it it. But ya, the last time I used this code, maybe a yr ago it worked fine.

Code:
include "jsonRPCClient.php";


$username 'you';
$password 'wish';
$ip 'id';
$port tell;


$info rpc_command'getinfo' );
if( 
is_array$info) ) {
        
$required = array( 'difficulty''blocks' );
        
$numeric_data get_numeric_data$info$required );
        if( !
$numeric_data ) {
                exit( 
"get_info() failed to acquire needed data." );
        }
        
extract$numeric_data );

        
$write_arr'timestamp' ] = time();
        
$write_arr'estimated_difficulty' ] = $difficulty;
        
$write_arr += compact'difficulty''blocks' );

        
$blocks_since_difficulty_change $blocks 2016;
        if( 
$blocks_since_difficulty_change ) {
                
$previous_difficulty_change $blocks $blocks_since_difficulty_change;

                
$current_block_timestamp get_block_timestamp$blocks );
                
$previous_block_timestamp get_block_timestamp$previous_difficulty_change );

                if( ! 
$current_block_timestamp || ! $previous_block_timestamp ) {
                        exit( 
'Could not get block timestamps' );
                }

                
$average_block_time = ($current_block_timestamp $previous_block_timestamp) / $blocks_since_difficulty_change;
                
$estimated_difficulty $difficulty 600 $average_block_time;
                
$write_arr'estimated_difficulty' ] = $estimated_difficulty;
        }
        
write_file$write_arr );
} else {
        exit( 
'Could not getinfo(). getinfo() output is not an array.' );
}

function 
rpc_command$command$arg '' ) {
        global 
$username$password$ip$port;
        static 
$rpc;
        if( ! 
$rpc ) {
                
$rpc = new jsonRPCClient"http://$username:$password@$ip:$port);
        }
        try {
                if( ! empty( 
$arg ) ) {
                        
$ret $rpc->$command$arg );
                } else {
                        
$ret $rpc->$command();
                }
        } catch ( 
Exception $e ) {
                
trigger_error"Exception in rpc_command(). Command is $command. Error is: " $e->getMessage() );
                
$ret false;
        }
        return 
$ret;
}

function 
get_numeric_data$info$keys ) {
        
$ret = array();
        foreach( 
$keys as $key ) {
                if( isset( 
$info$key ] ) && is_numeric$info$key ] ) ) {
                        
$ret$key ] = $info$key ];
                } else {
                        
$ret false;
                        break;
                }
        }
        return 
$ret;
}

function 
get_block_timestamp$block ) {
        if( !
is_numeric$block ) ) {
                return 
false;
        }
        
$block_hash rpc_command'getblockhash'$block );
        if( 
$block_hash !== false && preg_match'/^[0-9a-f]+$/i'$block_hash ) ) {
                
$block_data rpc_command'getblock'$block_hash );
                if( 
is_array$block_data ) && isset( $block_data'time' ] ) && is_numeric$block_data'time' ] ) ) {
                        return 
$block_data'time' ];
                } else {
                        
trigger_error"Error in get_block_timestamp(). Time in blockdata not found or not numeric. Block is $block);
                }
        } else {
                
trigger_error"Error in get_block_timestamp() could not getblockhash for block $block. Hash is $block_hash);
        }
        return 
false;
}

function 
write_file$data ) {
        if( 
is_array$data  ) ) {
                
$h fopen'getinfo.php''w' );
                
fwrite$h"var_export$datatrue  ) . ";" );
                
fclose$h );
                return 
true;
        } else {
                
trigger_error'Error in write_file(). Data is not an array.' );
                return 
false;
        }
}

Out puts this when manually run, normally set on a cron...

[not@here]$ php getdata.php
Could not getinfo(). getinfo() output is not an array.
[not@here]$

I think I copied the entire files code ok, looks good. But ya,the last time I used this code about a yr ago it was / seemed fine and saved the required data to the secondary file I would then pull from to display on my personal sites.

Ty.
Jump to: