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

End of function wallet_fetch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.18 ms | 1412 KiB | 17 Q