3v4l.org

run code in 300+ PHP versions simultaneously
<?php /****************************************************************************** Wallet Configuration ******************************************************************************/ $GLOBALS["wallet_ip"] = "127.0.0.1"; $GLOBALS["wallet_port"] = "8332"; $GLOBALS["wallet_user"] = "usrename"; $GLOBALS["wallet_pass"] = "password"; /****************************************************************************** Block Chain And Network Information These functions return general information about the block chain, the wallet itself, and the network the wallet/node is attached to. ******************************************************************************/ function getblock ($block_hash) { // The JSON-RPC request starts with a method name $request_array["method"] = "getblock"; // For getblock a block hash is required $request_array["params"][0] = $block_hash; // Send the request to the wallet $info = wallet_fetch ($request_array); // This function returns an array containing the block // data for the specified block hash return ($info); } function getblockhash ($block_index) { // The JSON-RPC request starts with a method name $request_array["method"] = "getblockhash"; // For getblockhash a block index is required $request_array["params"][0] = $block_index; // Send the request to the wallet $info = wallet_fetch ($request_array); // This function returns a string containing the block // hash value for the specified block in the chain return ($info); } function getinfo () { // The JSON-RPC request starts with a method name $request_array["method"] = "getinfo"; // getinfo has no parameters // Send the request to the wallet $info = wallet_fetch ($request_array); // This function returns an array containing information // about the wallet's network and block chain return ($info); } function getnetworkhashps ($block_index=NULL) { // The JSON-RPC request starts with a method name $request_array["method"] = "getnetworkhashps"; // block index is an optional parameter. If no block // index is specified you get the network hashrate for // the latest block if (isset ($block_index)) { $request_array["params"][0] = $block_index; } // Send the request to the wallet $info = wallet_fetch ($request_array); // This function returns a string containing the calculated // network hash rate for the latest block return ($info); } function getrawtransaction ($tx_id, $verbose=1) { // The JSON-RPC request starts with a method name $request_array["method"] = "getrawtransaction"; // For getrawtransaction a txid is required $request_array["params"][0] = $tx_id; $request_array["params"][1] = $verbose; // Send the request to the wallet $info = wallet_fetch ($request_array); // This function returns a string containing the block // hash value for the specified block in the chain return ($info); } /****************************************************************************** JSON-RPC Fetch This function is used to request information form the daemon. ******************************************************************************/ function wallet_fetch ($request_array) { // Encode the request as JSON for the wallet $request = json_encode ($request_array); // Create curl connection object $coind = curl_init(); // Set the IP address and port for the wallet server curl_setopt ($coind, CURLOPT_URL, $GLOBALS["wallet_ip"]); curl_setopt ($coind, CURLOPT_PORT, $GLOBALS["wallet_port"]); // Tell curl to use basic HTTP authentication curl_setopt($coind, CURLOPT_HTTPAUTH, CURLAUTH_BASIC) ; // Provide the username and password for the connection curl_setopt($coind, CURLOPT_USERPWD, $GLOBALS["wallet_user"].":".$GLOBALS["wallet_pass"]); // JSON-RPC Header for the wallet curl_setopt($coind, CURLOPT_HTTPHEADER, array ("Content-type: application/json")); // Prepare curl for a POST request curl_setopt($coind, CURLOPT_POST, TRUE); // Provide the JSON data for the request curl_setopt($coind, CURLOPT_POSTFIELDS, $request); // Indicate we want the response as a string curl_setopt($coind, CURLOPT_RETURNTRANSFER, TRUE); // Required by RPCSSL self-signed cert curl_setopt($coind, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($coind, CURLOPT_SSL_VERIFYHOST, FALSE); // execute the request $response_data = curl_exec($coind); // Close the connection curl_close($coind); // The JSON response is read into an array $info = json_decode ($response_data, TRUE); // If an error message was received the message is returned // to the calling code as a string. if (isset ($info["error"]) || $info["error"] != "") { return $info["error"]["message"]."(Error Code: ".$info["error"]["code"].")"; } // If there was no error the result is returned to the calling code else { return $info["result"]; } } /****************************************************************************** This script is Copyright � 2013 Jake Paysnoe. I hereby release this script into the public domain. Jake Paysnoe Jun 26, 2013 ******************************************************************************/ ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7d5s7
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   FETCH_W                      global              $0      'wallet_ip'
          1        ASSIGN                                                   $0, '127.0.0.1'
    7     2        FETCH_W                      global              $2      'wallet_port'
          3        ASSIGN                                                   $2, '8332'
    8     4        FETCH_W                      global              $4      'wallet_user'
          5        ASSIGN                                                   $4, 'usrename'
    9     6        FETCH_W                      global              $6      'wallet_pass'
          7        ASSIGN                                                   $6, 'password'
  178     8      > RETURN                                                   1

Function getblock:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7d5s7
function name:  getblock
number of ops:  12
compiled vars:  !0 = $block_hash, !1 = $request_array, !2 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   25     1        ASSIGN_DIM                                               !1, 'method'
          2        OP_DATA                                                  'getblock'
   28     3        FETCH_DIM_W                                      $4      !1, 'params'
          4        ASSIGN_DIM                                               $4, 0
          5        OP_DATA                                                  !0
   31     6        INIT_FCALL_BY_NAME                                       'wallet_fetch'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
   35    10      > RETURN                                                   !2
   36    11*     > RETURN                                                   null

End of function getblock

Function getblockhash:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7d5s7
function name:  getblockhash
number of ops:  12
compiled vars:  !0 = $block_index, !1 = $request_array, !2 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   41     1        ASSIGN_DIM                                               !1, 'method'
          2        OP_DATA                                                  'getblockhash'
   44     3        FETCH_DIM_W                                      $4      !1, 'params'
          4        ASSIGN_DIM                                               $4, 0
          5        OP_DATA                                                  !0
   47     6        INIT_FCALL_BY_NAME                                       'wallet_fetch'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
   51    10      > RETURN                                                   !2
   52    11*     > RETURN                                                   null

End of function getblockhash

Function getinfo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7d5s7
function name:  getinfo
number of ops:  8
compiled vars:  !0 = $request_array, !1 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   ASSIGN_DIM                                               !0, 'method'
          1        OP_DATA                                                  'getinfo'
   62     2        INIT_FCALL_BY_NAME                                       'wallet_fetch'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   66     6      > RETURN                                                   !1
   67     7*     > RETURN                                                   null

End of function getinfo

Function getnetworkhashps:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/7d5s7
function name:  getnetworkhashps
number of ops:  14
compiled vars:  !0 = $block_index, !1 = $request_array, !2 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV_INIT                                        !0      null
   72     1        ASSIGN_DIM                                               !1, 'method'
          2        OP_DATA                                                  'getnetworkhashps'
   78     3        ISSET_ISEMPTY_CV                                         !0
          4      > JMPZ                                                     ~4, ->8
   80     5    >   FETCH_DIM_W                                      $5      !1, 'params'
          6        ASSIGN_DIM                                               $5, 0
          7        OP_DATA                                                  !0
   84     8    >   INIT_FCALL_BY_NAME                                       'wallet_fetch'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !2, $7
   88    12      > RETURN                                                   !2
   89    13*     > RETURN                                                   null

End of function getnetworkhashps

Function getrawtransaction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7d5s7
function name:  getrawtransaction
number of ops:  16
compiled vars:  !0 = $tx_id, !1 = $verbose, !2 = $request_array, !3 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
   94     2        ASSIGN_DIM                                               !2, 'method'
          3        OP_DATA                                                  'getrawtransaction'
   97     4        FETCH_DIM_W                                      $5      !2, 'params'
          5        ASSIGN_DIM                                               $5, 0
          6        OP_DATA                                                  !0
   98     7        FETCH_DIM_W                                      $7      !2, 'params'
          8        ASSIGN_DIM                                               $7, 1
          9        OP_DATA                                                  !1
  101    10        INIT_FCALL_BY_NAME                                       'wallet_fetch'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !3, $9
  105    14      > RETURN                                                   !3
  106    15*     > RETURN                                                   null

End of function getrawtransaction

Function wallet_fetch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 91, Position 2 = 94
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 104
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 94
filename:       /in/7d5s7
function name:  wallet_fetch
number of ops:  107
compiled vars:  !0 = $request_array, !1 = $request, !2 = $coind, !3 = $response_data, !4 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  116     0  E >   RECV                                             !0      
  119     1        INIT_FCALL                                               'json_encode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
  122     5        INIT_FCALL_BY_NAME                                       'curl_init'
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !2, $7
  125     8        INIT_FCALL_BY_NAME                                       'curl_setopt'
          9        SEND_VAR_EX                                              !2
         10        FETCH_CONSTANT                                   ~9      'CURLOPT_URL'
         11        SEND_VAL_EX                                              ~9
         12        CHECK_FUNC_ARG                                           
         13        FETCH_FUNC_ARG               global              $10     'wallet_ip'
         14        SEND_FUNC_ARG                                            $10
         15        DO_FCALL                                      0          
  126    16        INIT_FCALL_BY_NAME                                       'curl_setopt'
         17        SEND_VAR_EX                                              !2
         18        FETCH_CONSTANT                                   ~12     'CURLOPT_PORT'
         19        SEND_VAL_EX                                              ~12
         20        CHECK_FUNC_ARG                                           
         21        FETCH_FUNC_ARG               global              $13     'wallet_port'
         22        SEND_FUNC_ARG                                            $13
         23        DO_FCALL                                      0          
  129    24        INIT_FCALL_BY_NAME                                       'curl_setopt'
         25        SEND_VAR_EX                                              !2
         26        FETCH_CONSTANT                                   ~15     'CURLOPT_HTTPAUTH'
         27        SEND_VAL_EX                                              ~15
         28        FETCH_CONSTANT                                   ~16     'CURLAUTH_BASIC'
         29        SEND_VAL_EX                                              ~16
         30        DO_FCALL                                      0          
  132    31        INIT_FCALL_BY_NAME                                       'curl_setopt'
         32        SEND_VAR_EX                                              !2
         33        FETCH_CONSTANT                                   ~18     'CURLOPT_USERPWD'
         34        SEND_VAL_EX                                              ~18
         35        FETCH_R                      global              ~19     'wallet_user'
         36        CONCAT                                           ~20     ~19, '%3A'
         37        FETCH_R                      global              ~21     'wallet_pass'
         38        CONCAT                                           ~22     ~20, ~21
         39        SEND_VAL_EX                                              ~22
         40        DO_FCALL                                      0          
  135    41        INIT_FCALL_BY_NAME                                       'curl_setopt'
         42        SEND_VAR_EX                                              !2
         43        FETCH_CONSTANT                                   ~24     'CURLOPT_HTTPHEADER'
         44        SEND_VAL_EX                                              ~24
         45        SEND_VAL_EX                                              <array>
         46        DO_FCALL                                      0          
  138    47        INIT_FCALL_BY_NAME                                       'curl_setopt'
         48        SEND_VAR_EX                                              !2
         49        FETCH_CONSTANT                                   ~26     'CURLOPT_POST'
         50        SEND_VAL_EX                                              ~26
         51        SEND_VAL_EX                                              <true>
         52        DO_FCALL                                      0          
  141    53        INIT_FCALL_BY_NAME                                       'curl_setopt'
         54        SEND_VAR_EX                                              !2
         55        FETCH_CONSTANT                                   ~28     'CURLOPT_POSTFIELDS'
         56        SEND_VAL_EX                                              ~28
         57        SEND_VAR_EX                                              !1
         58        DO_FCALL                                      0          
  144    59        INIT_FCALL_BY_NAME                                       'curl_setopt'
         60        SEND_VAR_EX                                              !2
         61        FETCH_CONSTANT                                   ~30     'CURLOPT_RETURNTRANSFER'
         62        SEND_VAL_EX                                              ~30
         63        SEND_VAL_EX                                              <true>
         64        DO_FCALL                                      0          
  147    65        INIT_FCALL_BY_NAME                                       'curl_setopt'
         66        SEND_VAR_EX                                              !2
         67        FETCH_CONSTANT                                   ~32     'CURLOPT_SSL_VERIFYPEER'
         68        SEND_VAL_EX                                              ~32
         69        SEND_VAL_EX                                              <false>
         70        DO_FCALL                                      0          
  148    71        INIT_FCALL_BY_NAME                                       'curl_setopt'
         72        SEND_VAR_EX                                              !2
         73        FETCH_CONSTANT                                   ~34     'CURLOPT_SSL_VERIFYHOST'
         74        SEND_VAL_EX                                              ~34
         75        SEND_VAL_EX                                              <false>
         76        DO_FCALL                                      0          
  151    77        INIT_FCALL_BY_NAME                                       'curl_exec'
         78        SEND_VAR_EX                                              !2
         79        DO_FCALL                                      0  $36     
         80        ASSIGN                                                   !3, $36
  154    81        INIT_FCALL_BY_NAME                                       'curl_close'
         82        SEND_VAR_EX                                              !2
         83        DO_FCALL                                      0          
  157    84        INIT_FCALL                                               'json_decode'
         85        SEND_VAR                                                 !3
         86        SEND_VAL                                                 <true>
         87        DO_ICALL                                         $39     
         88        ASSIGN                                                   !4, $39
  161    89        ISSET_ISEMPTY_DIM_OBJ                         0  ~41     !4, 'error'
         90      > JMPNZ_EX                                         ~41     ~41, ->94
         91    >   FETCH_DIM_R                                      ~42     !4, 'error'
         92        IS_NOT_EQUAL                                     ~43     ~42, ''
         93        BOOL                                             ~41     ~43
         94    > > JMPZ                                                     ~41, ->104
  163    95    >   FETCH_DIM_R                                      ~44     !4, 'error'
         96        FETCH_DIM_R                                      ~45     ~44, 'message'
         97        CONCAT                                           ~46     ~45, '%28Error+Code%3A+'
         98        FETCH_DIM_R                                      ~47     !4, 'error'
         99        FETCH_DIM_R                                      ~48     ~47, 'code'
        100        CONCAT                                           ~49     ~46, ~48
        101        CONCAT                                           ~50     ~49, '%29'
        102      > RETURN                                                   ~50
  161   103*       JMP                                                      ->106
  169   104    >   FETCH_DIM_R                                      ~51     !4, 'result'
        105      > RETURN                                                   ~51
  171   106*     > RETURN                                                   null

End of function wallet_fetch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.97 ms | 1444 KiB | 15 Q