-
Notifications
You must be signed in to change notification settings - Fork 3
/
receipt.php
77 lines (67 loc) · 2.11 KB
/
receipt.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
<?php
header('Access-Control-Allow-Origin: *');
require_once 'libs/jsonRPCClient.php';
$gethRPC = new jsonRPCClient('http://127.0.0.1:8545');
if(isset($_REQUEST['hash'])){
header('Content-Type: application/json');
echo getTransactionReceipt($_REQUEST['hash'], $gethRPC);
} else {
header('Content-Type: application/json');
echo blockNumber($gethRPC);
}
function blockNumber($gethRPC){
$data = getDefaultResponse();
try {
$ret = getRPCResponse($gethRPC->eth_blockNumber());
$data['data'] = $ret;
$block=hexdec($ret);
}
catch (exception $e) {
$data['error'] = true;
$data['msg'] = $e->getMessage();
}
return $block;
}
function getTransactionReceipt($hash, $gethRPC){
$data = getDefaultResponse();
try {
$ret = getRPCResponse($gethRPC->eth_getTransactionReceipt($hash), "pending");
$cluster = Cassandra::cluster('127.0.0.1') ->withCredentials("transactions_ro", "Public_transactions")
->build();
$keyspace = 'comchain';
$session = $cluster->connect($keyspace);
$query = "SELECT * FROM testtransactions WHERE hash = ?";
$options = array('arguments' => array($hash));
foreach ($session->execute(new Cassandra\SimpleStatement($query), $options) as $row) {
if ($row['direction']==1){
if ( $row['status']==0 || !isset($arr)) {
$arr = $row;
$arr['addr_from'] = $arr['add1'];
$arr['addr_to'] = $arr['add2'];
$arr['time'] = $arr['time']->value();
}
}
}
$arr['receipt'] = $ret;
$data = $ret;
}
catch (exception $e) {
$data['error'] = true;
$data['msg'] = $e->getMessage();
}
return json_encode($data);
}
function getDefaultResponse(){
$data['error'] = false;
$data['msg'] = "";
$data['data'] = "";
return $data;
}
function getRPCResponse($result){
if(isset($result['result'])){
return $result['result'];
} else {
throw new Exception($result['error']['message']);
}
}
?>