forked from xblau/node-interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.php
70 lines (53 loc) · 1.71 KB
/
requests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
defined( 'NODEMON_RUNNING') || die( 'Access denied.' );
function create_request( $method, $params = array() ) {
$request = array(
'jsonrpc' => '1.0',
'id' => 'request',
'method' => $method,
'params' => $params
);
return json_encode( $request );
}
function send_request( $request, $username='', $password='', $serverurl='' ) {
global $nodeconfig;
// use node config if no args given
if( empty($username)) { $username = $nodeconfig['username']; }
if( empty($password)) { $password = $nodeconfig['password']; }
if( empty($serverurl)) { $serverurl = $nodeconfig['serverurl']; }
$conn = curl_init();
curl_setopt( $conn, CURLOPT_URL, $serverurl );
curl_setopt( $conn, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $conn, CURLOPT_POST, true );
curl_setopt( $conn, CURLOPT_POSTFIELDS, $request );
curl_setopt( $conn, CURLOPT_HTTPHEADER, array('Content-Type: text/plain') );
curl_setopt( $conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $conn, CURLOPT_USERPWD, $username . ':' . $password );
$response = curl_exec( $conn );
curl_close( $conn );
return json_decode( $response, true );
}
$getnetinfo = send_request(
create_request( 'getnetworkinfo' )
);
$getpeerinfo = send_request(
create_request( 'getpeerinfo' )
);
$listbanned = send_request(
create_request( 'listbanned' )
);
$getbcinfo = send_request(
create_request( 'getblockchaininfo' )
);
$getnettotals = send_request(
create_request( 'getnettotals' )
);
$getmpinfo = send_request(
create_request( 'getmempoolinfo' )
);
if( $getnetinfo['result']['version'] > 150000 ) {
$uptime = send_request(
create_request( 'uptime' )
);
}
?>