-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheth_example.php
More file actions
62 lines (55 loc) · 1.28 KB
/
eth_example.php
File metadata and controls
62 lines (55 loc) · 1.28 KB
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
<?php
require 'Eth.php';
$eth = new Eth(ETH_RPC_SERVER);
if (!$eth) {
die();
}
$current_eth_block = $eth->getBlockNumber();
if (!$current_eth_block) {
die();
}
$erc_tokens['key'] = 'address'; //erc20 token contract address
// echo $current_eth_block . "\n";
$block = $eth->getBlockByNumber($current_eth_block);
if (!$block) {
die();
}
if (!$block['transactions']) {
die();
}
foreach ($block['transactions'] as $key => $value) {
###handle ETH
$block = $eth->getTransactionByHash($value['transaction_hash']);
$t_block_number = hexdec($block['blockNumber']);
if ($block_number >= $t_block_number + 30) {
$receive_value = wei2eth(hexdec($block['value']));
echo 'received';
continue;
}
###handle erc20
if ($erc_tokens) {
foreach ($erc_tokens as $k => $v) {
if ($v == $value['to']) {
$erc_info = $eth->getErc20($value['input']);
$account = $k . '_' . $erc_info['address'];
echo 'pending';
}
}
}
}
function sctonum($num, $double = 20) {
if (false !== stripos($num, "e")) {
$a = explode("e", strtolower($num));
$res = bcmul($a[0], bcpow(10, $a[1], $double), $double);
$res = rtrim($res, '0');
$res = rtrim($res, '.');
return $res;
}
return $num;
}
function wei2eth($amount) {
if (!$amount) {
return 0;
}
return sctonum($amount / 1000000000000000000);
}