-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathapi.php
100 lines (97 loc) · 3.23 KB
/
api.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
$key = "1cdbb159-0d61-42df-9d4c-0785416f1cda";
require_once('jsonrpcphp/includes/jsonRPCClient.php');
$bitcoin ="";
$port = "";
if (!isset($_GET['type'])) {
if ($_GET['type'] == "bitcoin") {
$port = 8332;
}
if ($_GET['type'] == "litecoin") {
$port = 9332;
}
if ($_GET['type'] == "dogecoin") {
$port = 22555;
}
}
$bitcoin = new jsonRPCClient('http://bitcoinrpc:[email protected]:'.$port.'/');
if (!isset($_GET['key'])) {
$data = array("error"=>1,"errormsg"=>"Invalid Key","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
$gkey = $_GET['key'];
$gkey = mb_convert_encoding($gkey, 'UTF-8', 'UTF-8');
if ($gkey != $key) {
$data = array("error"=>1,"errormsg"=>"Invalid Key","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
if (!isset($_GET['command'])) {
$data = array("error"=>2,"errormsg"=>"Invalid Command","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
$command = $_GET['command'];
$command = mb_convert_encoding($command, 'UTF-8', 'UTF-8');
if ($command == "getBalance") {
$data = array("error"=>0,"errormsg"=>"","time"=>time(),"command"=>$command,"response"=>$bitcoin->getbalance());
header('Content-Type: application/json');
echo json_encode($data);
} else if ($command="sendFrom") {
if (!isset($_GET['qr'])) {
$data = array("error"=>3,"errormsg"=>"Invalid Wallet Address","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
$qr = $_GET['qr'];
if (trim($qr) == "") {
$data = array("error"=>3,"errormsg"=>"Invalid Wallet Address","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
if (!isset($_GET['amount'])) {
$data = array("error"=>4,"errormsg"=>"Invalid Amount","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
$amount = $_GET['amount'];
if (trim($amount) == "") {
$data = array("error"=>4,"errormsg"=>"Invalid Amount","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
if (!is_numeric($amount)) {
$data = array("error"=>4,"errormsg"=>"Invalid Amount","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
//ok lets sends some coin
try {
$txid = @$bitcoin->sendfrom("john",(string)$qr,(float)$amount);
$data = array("error"=>0,"errormsg"=>"","time"=>time(),"command"=>$command,"txid"=>$txid);
header('Content-Type: application/json');
echo json_encode($data);
exit;
} catch (Exception $e) {
$data = array("error"=>5,"errormsg"=>"Error Processing Transaction","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
print_r($output);
} else {
$data = array("error"=>2,"errormsg"=>"Invalid Command","time"=>time());
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
?>