From fd0f0fd656ecec4c0e02035430d8a8de65ff23b6 Mon Sep 17 00:00:00 2001 From: lubuzzo Date: Wed, 6 Mar 2019 15:04:51 -0300 Subject: [PATCH 1/3] Adding support for the latest Bitcoin's changes - Accounts was removed, instead, now, we have labels --- include/classes/bitcoinwrapper.class.php | 18 +++-- include/lib/jsonRPCClient.php | 8 +-- .../pages/admin/checks/check_daemon.inc.php | 10 ++- include/pages/admin/wallet.inc.php | 25 ++++++- templates/bootstrap/admin/wallet/accounts.tpl | 69 +++++++++++++------ templates/bootstrap/admin/wallet/status.tpl | 6 +- .../bootstrap/admin/wallet/transactions.tpl | 6 +- 7 files changed, 103 insertions(+), 39 deletions(-) diff --git a/include/classes/bitcoinwrapper.class.php b/include/classes/bitcoinwrapper.class.php index c399e52e..4bd318ec 100755 --- a/include/classes/bitcoinwrapper.class.php +++ b/include/classes/bitcoinwrapper.class.php @@ -40,7 +40,7 @@ class BitcoinWrapper extends BitcoinClient { 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; @@ -55,15 +55,21 @@ class BitcoinWrapper extends BitcoinClient { // 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() { diff --git a/include/lib/jsonRPCClient.php b/include/lib/jsonRPCClient.php index b6675f2d..35133b17 100644 --- a/include/lib/jsonRPCClient.php +++ b/include/lib/jsonRPCClient.php @@ -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); } @@ -97,7 +97,7 @@ class jsonRPCClient { '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 @@ -112,12 +112,12 @@ class jsonRPCClient { // 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); diff --git a/include/pages/admin/checks/check_daemon.inc.php b/include/pages/admin/checks/check_daemon.inc.php index a4d44507..baa68b01 100644 --- a/include/pages/admin/checks/check_daemon.inc.php +++ b/include/pages/admin/checks/check_daemon.inc.php @@ -35,11 +35,17 @@ try { $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"; diff --git a/include/pages/admin/wallet.inc.php b/include/pages/admin/wallet.inc.php index 6aca3a69..16c75d4c 100644 --- a/include/pages/admin/wallet.inc.php +++ b/include/pages/admin/wallet.inc.php @@ -11,14 +11,32 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $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(); @@ -26,7 +44,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { 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 { @@ -69,6 +87,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $smarty->assign("PEERINFO", $aGetPeerInfo); $smarty->assign('PRECISION', $coin->getCoinValuePrevision()); $smarty->assign("TRANSACTIONS", $aGetTransactions); + $smarty->assign("LABELSCOMMAND", $labelsCommand); } else { $debug->append('Using cached page', 3); } diff --git a/templates/bootstrap/admin/wallet/accounts.tpl b/templates/bootstrap/admin/wallet/accounts.tpl index 7b7d2249..e66616b9 100644 --- a/templates/bootstrap/admin/wallet/accounts.tpl +++ b/templates/bootstrap/admin/wallet/accounts.tpl @@ -2,50 +2,75 @@
- Wallet Accounts + {if $LABELSCOMMAND} + Wallet Labels + {else} + Wallet Accounts + {/if}
{foreach key=NAME item=VALUE from=$ACCOUNTS}
- Account: {$NAME|default:"Default"} + {if $LABELSCOMMAND} + Label: {$VALUE|default:"Default"} + {else} + Account: {$NAME|default:"Default"} + {/if}
-
-
-
- Balance Info -
-
- - - - - -
Balance{$VALUE|number_format:"8"}
+ {if (not ($LABELSCOMMAND))} +
+
+
+ Balance Info +
+
+ + + + + +
Balance{$VALUE|number_format:"8"}
+
-
+ {/if} {foreach key=ACCOUNT item=ADDRESS from=$ACCOUNTADDRESSES} {if $ACCOUNT == $NAME} - + {if $LABELSCOMMAND} +
+ {else}
+ {/if}
- Addresses assigned to Account {$ACCOUNT|default:"Default"} + {if $LABELSCOMMAND} + Addresses assigned to Label {$VALUE|default:"Default"} + {else} + Addresses assigned to Account {$ACCOUNT|default:"Default"} + {/if}
{foreach from=$ACCOUNTADDRESSES[$ACCOUNT] key=ACCOUNT1 item=ADDRESS1} -{if $ADDRESS1@iteration is even by 1} - - +{if not $LABELSCOMMAND} + {if $ADDRESS1@iteration is even by 1} + + + {else} + + + {/if} {else} - - + {foreach from=$ACCOUNT1 key=ACCOUNT2 item=ADDRESS2} + + + + {/foreach} {/if} {/foreach} diff --git a/templates/bootstrap/admin/wallet/status.tpl b/templates/bootstrap/admin/wallet/status.tpl index c1d2f477..a64be996 100644 --- a/templates/bootstrap/admin/wallet/status.tpl +++ b/templates/bootstrap/admin/wallet/status.tpl @@ -14,7 +14,11 @@ - + {if $LABELSCOMMAND} + + {else} + + {/if} diff --git a/templates/bootstrap/admin/wallet/transactions.tpl b/templates/bootstrap/admin/wallet/transactions.tpl index 63f627ca..9ffdaf4c 100644 --- a/templates/bootstrap/admin/wallet/transactions.tpl +++ b/templates/bootstrap/admin/wallet/transactions.tpl @@ -9,7 +9,11 @@
{$ADDRESS1}
{$ADDRESS1}
{$ADDRESS1}
{$ADDRESS1}
{$ADDRESS2}
Peers Status BlocksAccountsLabelsAccounts
- + {if $LABELSCOMMAND} + + {else} + + {/if} From 2cdfc9e46dda83f9ded61c697dbaa6e63ee62a2d Mon Sep 17 00:00:00 2001 From: lubuzzo Date: Wed, 6 Mar 2019 15:07:21 -0300 Subject: [PATCH 2/3] Typo --- include/config/error_codes.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/config/error_codes.inc.php b/include/config/error_codes.inc.php index f01f5588..80ccc822 100644 --- a/include/config/error_codes.inc.php +++ b/include/config/error_codes.inc.php @@ -7,7 +7,7 @@ $aErrorCodes['E0002'] = 'Upstream shares not found'; $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'; From 480cefab6818f7f7adc129baf5a6e45a442ae0e5 Mon Sep 17 00:00:00 2001 From: lubuzzo Date: Wed, 6 Mar 2019 15:21:51 -0300 Subject: [PATCH 3/3] Added coin_c11.class to fix the diffbits to Chaincoin (C11) based coins --- include/classes/coins/coin_c11.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 include/classes/coins/coin_c11.class.php diff --git a/include/classes/coins/coin_c11.class.php b/include/classes/coins/coin_c11.class.php new file mode 100644 index 00000000..d2c6cc5f --- /dev/null +++ b/include/classes/coins/coin_c11.class.php @@ -0,0 +1,12 @@ +
AccountLabelAccountAddress Category Amount