various small changes

This commit is contained in:
Tanguy Pruvot 2016-05-30 09:15:41 +02:00
parent f26060c15f
commit 738848b7e9
3 changed files with 31 additions and 11 deletions

View file

@ -8,6 +8,7 @@ class WalletRPC {
private $rpc;
// cache
private $account;
private $accounts;
private $info;
private $height = 0;
@ -26,6 +27,7 @@ class WalletRPC {
switch ($coin->rpcencoding) {
case 'GETH':
$this->type = 'Ethereum';
$this->account = empty($coin->account) ? $coin->master_wallet : $coin->account;
$this->rpc = new Ethereum($coin->rpchost, $coin->rpcport);
break;
default:
@ -46,9 +48,9 @@ class WalletRPC {
// convert common methods used by yiimp
switch ($method) {
case 'getaccountaddress':
if (!isset($this->accounts))
$this->accounts = $this->rpc->eth_accounts();
return arraySafeVal($this->accounts, 0, $params);
if (!empty($params[0]))
return $params[0];
return $this->account;
case 'getinfo':
if (!isset($this->info)) {
$info = array();
@ -88,14 +90,25 @@ class WalletRPC {
$info['generate'] = $this->rpc->eth_mining();
$info['errors'] = '';
return $info;
case 'getblock':
$hash = (string) arraySafeVal($params,0);
$block = $this->rpc->eth_getBlockByHash($hash);
return $block;
case 'getblockhash':
$n = arraySafeVal($params,0);
$block = $this->rpc->eth_getBlockByNumber($n, true);
return $block->hash;
case 'gettransaction':
case 'getrawtransaction':
$txid = arraySafeVal($params,0,'');
$tx = $this->rpc->eth_getTransactionByHash($txid);
return $tx;
case 'getwork':
return false; //$this->rpc->eth_getWork(); auto enable miner!
// todo...
case 'getpeerinfo':
$peers = array();
return $peers;
case 'getwork':
return $this->rpc->eth_getWork();
// todo...
case 'getblocktemplate':
return $this->rpc->eth_getWork();
case 'listtransactions':
$txs = array();
return $txs;

View file

@ -7,6 +7,7 @@ echo <<<end
tr.ssrow.filtered { display: none; }
th.status, td.status { min-width: 28px; max-width: 48px; text-align: center; }
td.status { font-family: monospace; font-size: 9pt; letter-spacing: 3px; }
td.status span.progress { font-size: .8em; letter-spacing: 0; }
td.status span.hidden { visibility: hidden; }
</style>
end;
@ -87,8 +88,8 @@ foreach($coins as $coin)
else echo '&nbsp;';
if($coin->block_height < $coin->target_height) {
$percent = round($coin->block_height*100/$coin->target_height, 2);
echo '<br/><span style="font-size: .8em">'.$percent.'%</span>';
$percent = round($coin->block_height*100/$coin->target_height, 1);
echo '<br/><span class="progress">'.$percent.'%</span>';
}
echo "</td>";

View file

@ -128,7 +128,10 @@ if (!empty($query)) try {
if ($param === 'true' || $param === 'false') {
$param = $param === 'true' ? true : false;
}
else $param = (is_numeric($param)) ? 0 + $param : trim($param,'"');
else if (strpos($param, '0x') === 0)
$param = "$param"; // eth hex crap
else
$param = (is_numeric($param)) ? 0 + $param : trim($param,'"');
$p[] = $param;
}
@ -157,6 +160,9 @@ if (!empty($query)) try {
case 7:
$result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6]);
break;
case 8:
$result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6], $p[7]);
break;
default:
$result = 'error: too much parameters';
}