红马优购排队系统《134苏1619=5045》红马优购排队系统开发,红马优购模式系统,红马优购排队返利系统,红马优购商城系统,红马优购系统开发。
<?php
define('RPC_IP','127.0.0.1');
define('RPC_PORT',8545);
require 'libs/ethereum-php/ethereum.php';
$e = new EthPay();
class EthPay
{
private $eth;
//让我们建立与parity节点的连接
function __construct()
{
$this->eth = new Ethereum(RPC_IP, RPC_PORT);
if(!$this->eth->net_version()) die('RPC ERROR');
}
/ *
*得到一个地址的余额,
*来自parity的余额以十六进制形式出现在wei中
*使用bc数学函数转换它
* /
function getBalanceOfAddress($addr)
{
$eth_hex = $this->eth->eth_getBalance($addr, 'latest');
$eth = $this->wei2eth($this->bchexdec($eth_hex));
$pending_hex = $this->eth->eth_getBalance($addr, 'pending');
$pending = $this->wei2eth($this->bchexdec($pending_hex));
return array('balance'=>$eth,'pending'=>$pending);
}
function getCurrentPrice($currency='USD')
{
$data = json_decode(file_get_contents('https://api.coinbase.com/v2/prices/ETH-'.$currency.'/spot'),true);
return $data['data']['amount'];
}
/*
*我们将使用vanityeth生成私钥对
* npm install -g vanity-eth
*我们必须重新格式化输出字符串以用作JSON
* /
function genPair()
{
exec('vanityeth', $outputAndErrors, $return_value);
$answer = implode(NULL,$outputAndErrors);
$answer = str_replace('address:','"address":',$answer);
$answer = str_replace('privKey:','"privKey":',$answer);
$answer = str_replace('\'','"',$answer);
return json_decode($answer,true);
}
//以下功能用于转换和处理大数字
function wei2eth($wei)
{
return bcdiv($wei,1000000000000000000,18);
}
function bchexdec($hex) {
if(strlen($hex) == 1) {
return hexdec($hex);
} else {
$remain = substr($hex, 0, -1);
$last = substr($hex, -1);
return bcadd(bcmul(16, $this->bchexdec($remain)), hexdec($last));
}
}