Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions include/classes/bitcoinwrapper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function is_testnet() {
else
return $this->memcache->setCache(__FUNCTION__, parent::getblockchaininfo()['chain'] == 'test', 30);
}

public function getmininginfo() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
Expand All @@ -55,15 +55,21 @@ public function getblockcount() {
// Wrapper method to get the real main account balance
public function getrealbalance() {
$this->oDebug->append("STA " . __METHOD__, 4);
$aAccounts = parent::listaccounts();
$dBalance = parent::getbalance('');
$aAccounts = [];

try {
$aAccounts = parent::listaccounts();
} catch (Exception $e) {
if ($e->getCode() == 404)
$aAccounts = array( '*' => parent::getbalance("*") );
}

// Account checks
if (count($aAccounts) == 1) {
// We only have a single account so getbalance will be fine
return $dBalance;
return parent::getbalance("*");
} else {
$dMainBalance = $aAccounts[''];
return $dMainBalance;
return $aAccounts[0];
}
}
public function getdifficulty() {
Expand Down
12 changes: 12 additions & 0 deletions include/classes/coins/coin_c11.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;

/**
* We extend our CoinBase class
* No need to change anything, base class supports
* scrypt and sha256d
**/
class Coin extends CoinBase {
protected $target_bits = 32;
protected $share_difficulty_precision = 6;
}
2 changes: 1 addition & 1 deletion include/config/error_codes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$aErrorCodes['E0003'] = 'Failed to change shares order';
$aErrorCodes['E0004'] = 'Failed to reset previous block';
$aErrorCodes['E0005'] = 'Unable to fetch blocks upstream share';
$aErrorCodes['E0006'] = 'Unable to conenct to RPC server backend';
$aErrorCodes['E0006'] = 'Unable to connect to RPC server backend';
$aErrorCodes['E0007'] = 'Out of Order Share detected, autofixed';
$aErrorCodes['E0008'] = 'Failed to delete archived shares';
$aErrorCodes['E0009'] = 'Cron disabled by admin';
Expand Down
8 changes: 4 additions & 4 deletions include/lib/jsonRPCClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class jsonRPCClient {
*/
public function __construct($url, $debug = false) {
$this->url = $url;
$this->debug = $debug;
$this->debug = $debug;
$this->debug_output = '';
$this->id = rand(1, 100);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public function __call($method, $params) {
'id' => $this->id
);
$request = json_encode($request);
if ($this->debug) $this->debug_output[] = 'Request: '.$request;
if ($this->debug) $this->debug_output = 'Request: '.$request[0];

// performs the HTTP POST
// extract information from URL for proper authentication
Expand All @@ -112,12 +112,12 @@ public function __call($method, $params) {
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
if (curl_errno($ch)) throw new Exception('RPC call failed: ' . curl_error($ch));
if ($this->debug) $this->debug_output[] = 'Response: ' . $response;
if ($this->debug) $this->debug_output = 'Response: ' . $response[0];
$response = json_decode($response, true);
$resultStatus = curl_getinfo($ch);
if ($resultStatus['http_code'] != '200') {
if ($resultStatus['http_code'] == '401') throw new Exception('RPC call did not return 200: Authentication failed');
throw new Exception('RPC call did not return 200: HTTP error: ' . $resultStatus['http_code'] . ' - JSON Response: [' . @$response['error']['code'] . '] ' . @$response['error']['message']);
throw new Exception('RPC call did not return 200: HTTP error: ' . $resultStatus['http_code'] . ' - JSON Response: [' . @$response['error']['code'] . '] ' . @$response['error']['message'], $resultStatus['http_code']);
}
curl_close($ch);

Expand Down
10 changes: 8 additions & 2 deletions include/pages/admin/checks/check_daemon.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@
$newerror['description'] = "Blockchain download progress is at an estimated $dDownloadPercentage%. It may take a while to complete.";
$newerror['configvalue'] = "wallet.host";
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-local-wallet-rpc";
$error[] = $newerror;
$error[] = $newerror;
$newerror = null;
}
// check if there is more than one account set on wallet
$accounts = $bitcoin->listaccounts();
try {
$accounts = $bitcoin->listaccounts();
} catch (Exception $e) {
if ($e->getCode() == 404)
$accounts = $bitcoin->listwallets();
}

if (count($accounts) > 1 && $accounts[''] <= 0) {
$newerror = array();
$newerror['name'] = "Coin daemon";
Expand Down
25 changes: 22 additions & 3 deletions include/pages/admin/wallet.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,40 @@
$debug->append('No cached version available, fetching from backend', 3);
if ($bitcoin->can_connect() === true) {
$dBalance = $bitcoin->getrealbalance();
$labelsCommand = false;

try {
$dWalletAccounts = $bitcoin->listaccounts();
} catch (Exception $e) {
if ($e->getCode() == 404) {
$dWalletAccounts = $bitcoin->listlabels();
$labelsCommand = true;
}
}

$dWalletAccounts = $bitcoin->listaccounts();
$dAddressCount = count($dWalletAccounts);

$dAccountAddresses = array();
foreach($dWalletAccounts as $key => $value)
{
$dAccountAddresses[$key] = $bitcoin->getaddressesbyaccount((string)$key);
if (!($labelsCommand))
$dAccountAddresses[$key] = $bitcoin->getaddressesbyaccount((string)$key);
else {
if (strlen($value) == 0)
$value = "";

foreach ($bitcoin->getaddressesbylabel((string)$value) as $key2 => $value2) {
$dAccountAddresses[$key][$key2] = $value2;
}
}
}

$aGetInfo = $bitcoin->getinfo();
$aGetPeerInfo = $bitcoin->getpeerinfo();
if ($aGetInfo['connections'] == 0) $aGetInfo['errors'] = 'No peers';
# Check if daemon is downloading the blockchain, estimated
if ($dDownloadPercentage = $bitcoin->getblockchaindownload()) $aGetInfo['errors'] = "Downloading: $dDownloadPercentage%";
$aGetTransactions = $bitcoin->listtransactions('', (int)$setting->getValue('wallet_transaction_limit', 25));
$aGetTransactions = $bitcoin->listtransactions('*', (int)$setting->getValue('wallet_transaction_limit', 25));
if (is_array($aGetInfo) && array_key_exists('newmint', $aGetInfo)) {
$dNewmint = $aGetInfo['newmint'];
} else {
Expand Down Expand Up @@ -69,6 +87,7 @@
$smarty->assign("PEERINFO", $aGetPeerInfo);
$smarty->assign('PRECISION', $coin->getCoinValuePrevision());
$smarty->assign("TRANSACTIONS", $aGetTransactions);
$smarty->assign("LABELSCOMMAND", $labelsCommand);
} else {
$debug->append('Using cached page', 3);
}
Expand Down
69 changes: 47 additions & 22 deletions templates/bootstrap/admin/wallet/accounts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,75 @@
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-users fa-fw"></i> Wallet Accounts
{if $LABELSCOMMAND}
<i class="fa fa-users fa-fw"></i> Wallet Labels
{else}
<i class="fa fa-users fa-fw"></i> Wallet Accounts
{/if}
</div>
<div class="panel-body ">
<div class="panel-group">
{foreach key=NAME item=VALUE from=$ACCOUNTS}
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-user fa-fw"></i> Account: {$NAME|default:"Default"}
{if $LABELSCOMMAND}
<i class="fa fa-user fa-fw"></i> Label: {$VALUE|default:"Default"}
{else}
<i class="fa fa-user fa-fw"></i> Account: {$NAME|default:"Default"}
{/if}
</div>
<div class="panel-body">
<div class="col-lg-4">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-money fa-fw"></i> Balance Info
</div>
<div class="table-responsive panel-body no-padding">
<table class="table table-striped table-bordered table-hover">
<tr>
<td class="col-lg-4">Balance</td>
<td class="col-lg-12">{$VALUE|number_format:"8"}</td>
</tr>
</table>
{if (not ($LABELSCOMMAND))}
<div class="col-lg-4">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-money fa-fw"></i> Balance Info
</div>
<div class="table-responsive panel-body no-padding">
<table class="table table-striped table-bordered table-hover">
<tr>
<td class="col-lg-4">Balance</td>
<td class="col-lg-12">{$VALUE|number_format:"8"}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
{/if}

{foreach key=ACCOUNT item=ADDRESS from=$ACCOUNTADDRESSES}
{if $ACCOUNT == $NAME}

{if $LABELSCOMMAND}
<div class="col-lg-12">
{else}
<div class="col-lg-8">
{/if}
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-book fa-fw"></i> Addresses assigned to Account {$ACCOUNT|default:"Default"}
{if $LABELSCOMMAND}
<i class="fa fa-book fa-fw"></i> Addresses assigned to Label {$VALUE|default:"Default"}
{else}
<i class="fa fa-book fa-fw"></i> Addresses assigned to Account {$ACCOUNT|default:"Default"}
{/if}
</div>
<div class="table-responsive panel-body no-padding">
<table class="table table-striped table-bordered table-hover">
<tbody>
{foreach from=$ACCOUNTADDRESSES[$ACCOUNT] key=ACCOUNT1 item=ADDRESS1}
{if $ADDRESS1@iteration is even by 1}
<td>{$ADDRESS1}</td>
</tr>
{if not $LABELSCOMMAND}
{if $ADDRESS1@iteration is even by 1}
<td>{$ADDRESS1}</td>
</tr>
{else}
<tr>
<td>{$ADDRESS1}</td>
{/if}
{else}
<tr>
<td>{$ADDRESS1}</td>
{foreach from=$ACCOUNT1 key=ACCOUNT2 item=ADDRESS2}
<tr>
<td>{$ADDRESS2}</td>
</tr>
{/foreach}
{/if}
{/foreach}
<tbody>
Expand Down
6 changes: 5 additions & 1 deletion templates/bootstrap/admin/wallet/status.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
<th>Peers</th>
<th>Status</th>
<th>Blocks</th>
<th>Accounts</th>
{if $LABELSCOMMAND}
<th>Labels</th>
{else}
<th>Accounts</th>
{/if}
</tr>
</thead>
<tbody>
Expand Down
6 changes: 5 additions & 1 deletion templates/bootstrap/admin/wallet/transactions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="text-center">Account</th>
{if $LABELSCOMMAND}
<th class="text-center">Label</th>
{else}
<th class="text-center">Account</th>
{/if}
<th class="text-center">Address</th>
<th class="text-center">Category</th>
<th class="text-right">Amount</th>
Expand Down