-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitdb.php
53 lines (41 loc) · 1.32 KB
/
bitdb.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
<?php
$BITDB_URL = 'https://bitdb.fountainhead.cash/q/';
$BITSOCKET_URL = 'https://bitsocket.fountainhead.cash/s/';
function query_bitdb($query) {
global $BITDB_URL;
$json_string = json_encode($query);
$url = $BITDB_URL . base64_encode($json_string);
return json_decode(file_get_contents($url));
}
function query_bitsocket($query, $fn) {
global $BITSOCKET_URL;
$json_string = json_encode($query);
$url = $BITSOCKET_URL . base64_encode($json_string);
$callback = function($ch, $data) use ($fn) {
$bytes = strlen($data);
static $buf = '';
$buf .= $data;
while(true) {
$pos = strpos($buf, "\n");
if($pos === false) {
break;
}
$data = substr($buf, 0, $pos+1);
$buf = substr($buf, $pos+1);
// comment
if (substr($data, 0, 1) == ":") {
break;
} else if (substr($data, 0, 6) == "data: ") {
$fn(json_decode(substr($data, 6)));
}
}
return $bytes;
};
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
curl_exec($ch);
curl_close($ch);
}