commit
19094e73e3
@ -35,9 +35,9 @@ $aAllBlocks = $block->getAllUnconfirmed(max($config['network_confirmations'],$co
|
|||||||
|
|
||||||
$log->logInfo("ID\tHeight\tBlockhash\tConfirmations");
|
$log->logInfo("ID\tHeight\tBlockhash\tConfirmations");
|
||||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||||
$aBlockInfo = $bitcoin->query('getblock', $aBlock['blockhash']);
|
$aBlockInfo = $bitcoin->getblock($aBlock['blockhash']);
|
||||||
// Fetch this blocks transaction details to find orphan blocks
|
// Fetch this blocks transaction details to find orphan blocks
|
||||||
$aTxDetails = $bitcoin->query('gettransaction', $aBlockInfo['tx'][0]);
|
$aTxDetails = $bitcoin->gettransaction($aBlockInfo['tx'][0]);
|
||||||
$log->logInfo($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']);
|
$log->logInfo($aBlock['id'] . "\t" . $aBlock['height'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']);
|
||||||
if ($aTxDetails['details'][0]['category'] == 'orphan') {
|
if ($aTxDetails['details'][0]['category'] == 'orphan') {
|
||||||
// We have an orphaned block, we need to invalidate all transactions for this one
|
// We have an orphaned block, we need to invalidate all transactions for this one
|
||||||
|
|||||||
@ -32,7 +32,7 @@ if (!$strLastBlockHash) $strLastBlockHash = '';
|
|||||||
|
|
||||||
// Fetch all transactions since our last block
|
// Fetch all transactions since our last block
|
||||||
if ( $bitcoin->can_connect() === true ){
|
if ( $bitcoin->can_connect() === true ){
|
||||||
$aTransactions = $bitcoin->query('listsinceblock', $strLastBlockHash);
|
$aTransactions = $bitcoin->listsinceblock($strLastBlockHash);
|
||||||
} else {
|
} else {
|
||||||
$log->logFatal('Unable to connect to RPC server backend');
|
$log->logFatal('Unable to connect to RPC server backend');
|
||||||
$monitoring->endCronjob($cron_name, 'E0006', 1, true);
|
$monitoring->endCronjob($cron_name, 'E0006', 1, true);
|
||||||
@ -48,7 +48,7 @@ if (empty($aTransactions['transactions'])) {
|
|||||||
// Let us add those blocks as unaccounted
|
// Let us add those blocks as unaccounted
|
||||||
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
|
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
|
||||||
if ( $aData['category'] == 'generate' || $aData['category'] == 'immature' ) {
|
if ( $aData['category'] == 'generate' || $aData['category'] == 'immature' ) {
|
||||||
$aBlockRPCInfo = $bitcoin->query('getblock', $aData['blockhash']);
|
$aBlockRPCInfo = $bitcoin->getblock($aData['blockhash']);
|
||||||
$config['reward_type'] == 'block' ? $aData['amount'] = $aData['amount'] : $aData['amount'] = $config['reward'];
|
$config['reward_type'] == 'block' ? $aData['amount'] = $aData['amount'] : $aData['amount'] = $config['reward'];
|
||||||
$aData['height'] = $aBlockRPCInfo['height'];
|
$aData['height'] = $aBlockRPCInfo['height'];
|
||||||
$aData['difficulty'] = $aBlockRPCInfo['difficulty'];
|
$aData['difficulty'] = $aBlockRPCInfo['difficulty'];
|
||||||
@ -82,7 +82,7 @@ if (empty($aAllBlocks)) {
|
|||||||
if ( !$iPreviousShareId = $block->getLastShareId())
|
if ( !$iPreviousShareId = $block->getLastShareId())
|
||||||
$iPreviousShareId = 0;
|
$iPreviousShareId = 0;
|
||||||
// Fetch this blocks upstream ID
|
// Fetch this blocks upstream ID
|
||||||
$aBlockRPCInfo = $bitcoin->query('getblock', $aBlock['blockhash']);
|
$aBlockRPCInfo = $bitcoin->getblock($aBlock['blockhash']);
|
||||||
if ($share->findUpstreamShare($aBlockRPCInfo, $iPreviousShareId)) {
|
if ($share->findUpstreamShare($aBlockRPCInfo, $iPreviousShareId)) {
|
||||||
$iCurrentUpstreamId = $share->getUpstreamShareId();
|
$iCurrentUpstreamId = $share->getUpstreamShareId();
|
||||||
// Rarely happens, but did happen once to me
|
// Rarely happens, but did happen once to me
|
||||||
|
|||||||
@ -246,8 +246,7 @@ class BitcoinClientException extends ErrorException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(INCLUDE_DIR . "/xmlrpc.inc.php");
|
require_once(INCLUDE_DIR . "/jsonRPCClient.php");
|
||||||
require_once(INCLUDE_DIR . "/jsonrpc.inc.php");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bitcoin client class for access to a Bitcoin server via JSON-RPC-HTTP[S]
|
* Bitcoin client class for access to a Bitcoin server via JSON-RPC-HTTP[S]
|
||||||
@ -258,7 +257,7 @@ require_once(INCLUDE_DIR . "/jsonrpc.inc.php");
|
|||||||
* @author Mike Gogulski
|
* @author Mike Gogulski
|
||||||
* http://www.gogulski.com/ http://www.nostate.com/
|
* http://www.gogulski.com/ http://www.nostate.com/
|
||||||
*/
|
*/
|
||||||
class BitcoinClient extends jsonrpc_client {
|
class BitcoinClient extends jsonRPCClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a jsonrpc_client object to talk to the bitcoin server and return it,
|
* Create a jsonrpc_client object to talk to the bitcoin server and return it,
|
||||||
@ -297,15 +296,8 @@ class BitcoinClient extends jsonrpc_client {
|
|||||||
throw new BitcoinClientException("Port must be an integer and between 1 and 65535");
|
throw new BitcoinClientException("Port must be an integer and between 1 and 65535");
|
||||||
if (!empty($certificate_path) && !is_readable($certificate_path))
|
if (!empty($certificate_path) && !is_readable($certificate_path))
|
||||||
throw new BitcoinClientException("Certificate file " . $certificate_path . " is not readable");
|
throw new BitcoinClientException("Certificate file " . $certificate_path . " is not readable");
|
||||||
$uri = $scheme . "://" . $username . ":" . $password . "@" . $address . ":" . $port . "/";
|
$uri = $scheme . "://" . $username . ":" . $password . "@" . $address . "/";
|
||||||
parent::__construct($uri);
|
parent::__construct($uri);
|
||||||
$this->setDebug($debug_level);
|
|
||||||
$this->setSSLVerifyHost(0);
|
|
||||||
if ($scheme == "https")
|
|
||||||
if (!empty($certificate_path))
|
|
||||||
$this->setCaCertificate($certificate_path);
|
|
||||||
else
|
|
||||||
$this->setSSLVerifyPeer(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,575 +318,4 @@ class BitcoinClient extends jsonrpc_client {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a Bitcoin server query argument to a jsonrpcval
|
|
||||||
*
|
|
||||||
* @param mixed $argument
|
|
||||||
* @return jsonrpcval
|
|
||||||
* @throws none
|
|
||||||
* @todo Make this method private.
|
|
||||||
*/
|
|
||||||
public function query_arg_to_parameter($argument) {
|
|
||||||
$type = "";// "string" is encoded as this default type value in xmlrpc.inc
|
|
||||||
if (is_numeric($argument)) {
|
|
||||||
if (intval($argument) != floatval($argument)) {
|
|
||||||
$argument = floatval($argument);
|
|
||||||
$type = "double";
|
|
||||||
} else {
|
|
||||||
$argument = intval($argument);
|
|
||||||
$type = "int";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_bool($argument))
|
|
||||||
$type = "boolean";
|
|
||||||
if (is_int($argument))
|
|
||||||
$type = "int";
|
|
||||||
if (is_float($argument))
|
|
||||||
$type = "double";
|
|
||||||
if (is_array($argument))
|
|
||||||
$type = "array";
|
|
||||||
return new jsonrpcval($argument, $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a JSON-RPC message and optional parameter arguments to the server.
|
|
||||||
*
|
|
||||||
* Use the API functions if possible. This method remains public to support
|
|
||||||
* changes being made to the API before this libarary can be updated.
|
|
||||||
*
|
|
||||||
* @param string $message
|
|
||||||
* @param mixed $args, ...
|
|
||||||
* @return mixed
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @see xmlrpc.inc:php_xmlrpc_decode()
|
|
||||||
*/
|
|
||||||
public function query($message) {
|
|
||||||
if (!$message || empty($message))
|
|
||||||
throw new BitcoinClientException("Bitcoin client query requires a message");
|
|
||||||
$msg = new jsonrpcmsg($message);
|
|
||||||
if (func_num_args() > 1) {
|
|
||||||
for ($i = 1; $i < func_num_args(); $i++) {
|
|
||||||
$msg->addParam(self::query_arg_to_parameter(func_get_arg($i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = $this->send($msg);
|
|
||||||
if ($response->faultCode()) {
|
|
||||||
throw new BitcoinClientException($response->faultString());
|
|
||||||
}
|
|
||||||
return php_xmlrpc_decode($response->value());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The following functions implement the Bitcoin RPC API as documented at https://www.bitcoin.org/wiki/doku.php?id=api
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safely copies wallet.dat to destination, which can be a directory or
|
|
||||||
* a path with filename.
|
|
||||||
*
|
|
||||||
* @param string $destination
|
|
||||||
* @return mixed Nothing, or an error array
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function backupwallet($destination) {
|
|
||||||
if (!$destination || empty($destination))
|
|
||||||
throw new BitcoinClientException("backupwallet requires a destination");
|
|
||||||
return $this->query("backupwallet", $destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the server's available balance, or the balance for $account with
|
|
||||||
* at least $minconf confirmations.
|
|
||||||
*
|
|
||||||
* @param string $account Account to check. If not provided, the server's
|
|
||||||
* total available balance is returned.
|
|
||||||
* @param integer $minconf If specified, only transactions with at least
|
|
||||||
* $minconf confirmations will be included in the returned total.
|
|
||||||
* @return float Bitcoin balance
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getbalance($account = NULL, $minconf = 1) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('getbalance requires a numeric minconf >= 0');
|
|
||||||
if ($account == NULL)
|
|
||||||
return $this->query("getbalance");
|
|
||||||
return $this->query("getbalance", $account, $minconf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of blocks in the longest block chain.
|
|
||||||
*
|
|
||||||
* @return integer Current block count
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getblockcount() {
|
|
||||||
return $this->query("getblockcount");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the block number of the latest block in the longest block chain.
|
|
||||||
*
|
|
||||||
* @return integer Block number
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getblocknumber() {
|
|
||||||
return $this->query("getblocknumber");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of connections to other nodes.
|
|
||||||
*
|
|
||||||
* @return integer Connection count
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getconnectioncount() {
|
|
||||||
return $this->query("getconnectioncount");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
|
|
||||||
*
|
|
||||||
* @return float Difficulty
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getdifficulty() {
|
|
||||||
return $this->query("getdifficulty");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns boolean true if server is trying to generate bitcoins, false otherwise.
|
|
||||||
*
|
|
||||||
* @return boolean Generation status
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getgenerate() {
|
|
||||||
return $this->query("getgenerate");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell Bitcoin server to generate Bitcoins or not, and how many processors
|
|
||||||
* to use.
|
|
||||||
*
|
|
||||||
* @param boolean $generate
|
|
||||||
* @param integer $maxproc
|
|
||||||
* Limit generation to $maxproc processors, unlimited if -1
|
|
||||||
* @return mixed Nothing if successful, error array if not
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function setgenerate($generate = TRUE, $maxproc = -1) {
|
|
||||||
if (!is_numeric($maxproc) || $maxproc < -1)
|
|
||||||
throw new BitcoinClientException('setgenerate: $maxproc must be numeric and >= -1');
|
|
||||||
return $this->query("setgenerate", $generate, $maxproc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array containing server information.
|
|
||||||
*
|
|
||||||
* @return array Server information
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getinfo() {
|
|
||||||
return $this->query("getinfo");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the account associated with the given address.
|
|
||||||
*
|
|
||||||
* @param string $address
|
|
||||||
* @return string Account
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.17
|
|
||||||
*/
|
|
||||||
public function getaccount($address) {
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("getaccount requires an address");
|
|
||||||
return $this->query("getaccount", $address);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the label associated with the given address.
|
|
||||||
*
|
|
||||||
* @param string $address
|
|
||||||
* @return string Label
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @deprecated Since 0.3.17
|
|
||||||
*/
|
|
||||||
public function getlabel($address) {
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("getlabel requires an address");
|
|
||||||
return $this->query("getlabel", $address);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the account associated with the given address.
|
|
||||||
* $account may be omitted to remove an account from an address.
|
|
||||||
*
|
|
||||||
* @param string $address
|
|
||||||
* @param string $account
|
|
||||||
* @return NULL
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.17
|
|
||||||
*/
|
|
||||||
public function setaccount($address, $account = "") {
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("setaccount requires an address");
|
|
||||||
return $this->query("setaccount", $address, $account);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the label associated with the given address.
|
|
||||||
* $label may be omitted to remove a label from an address.
|
|
||||||
*
|
|
||||||
* @param string $address
|
|
||||||
* @param string $label
|
|
||||||
* @return NULL
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @deprecated Since 0.3.17
|
|
||||||
*/
|
|
||||||
public function setlabel($address, $label = "") {
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("setlabel requires an address");
|
|
||||||
return $this->query("setlabel", $address, $label);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new bitcoin address for receiving payments.
|
|
||||||
*
|
|
||||||
* If $account is specified (recommended), it is added to the address book so
|
|
||||||
* payments received with the address will be credited to $account.
|
|
||||||
*
|
|
||||||
* @param string $account Label to apply to the new address
|
|
||||||
* @return string Bitcoin address
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getnewaddress($account = NULL) {
|
|
||||||
if (!$account || empty($account))
|
|
||||||
return $this->query("getnewaddress");
|
|
||||||
return $this->query("getnewaddress", $account);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total amount received by $address in transactions with at least
|
|
||||||
* $minconf confirmations.
|
|
||||||
*
|
|
||||||
* @param string $address
|
|
||||||
* Bitcoin address
|
|
||||||
* @param integer $minconf
|
|
||||||
* Minimum number of confirmations for transactions to be counted
|
|
||||||
* @return float Bitcoin total
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getreceivedbyaddress($address, $minconf = 1) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('getreceivedbyaddress requires a numeric minconf >= 0');
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("getreceivedbyaddress requires an address");
|
|
||||||
return $this->query("getreceivedbyaddress", $address, $minconf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total amount received by addresses associated with $account
|
|
||||||
* in transactions with at least $minconf confirmations.
|
|
||||||
*
|
|
||||||
* @param string $account
|
|
||||||
* @param integer $minconf
|
|
||||||
* Minimum number of confirmations for transactions to be counted
|
|
||||||
* @return float Bitcoin total
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.17
|
|
||||||
*/
|
|
||||||
public function getreceivedbyaccount($account, $minconf = 1) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('getreceivedbyaccount requires a numeric minconf >= 0');
|
|
||||||
if (!$account || empty($account))
|
|
||||||
throw new BitcoinClientException("getreceivedbyaccount requires an account");
|
|
||||||
return $this->query("getreceivedbyaccount", $account, $minconf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total amount received by addresses with $label in
|
|
||||||
* transactions with at least $minconf confirmations.
|
|
||||||
*
|
|
||||||
* @param string $label
|
|
||||||
* @param integer $minconf
|
|
||||||
* Minimum number of confirmations for transactions to be counted
|
|
||||||
* @return float Bitcoin total
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @deprecated Since 0.3.17
|
|
||||||
*/
|
|
||||||
public function getreceivedbylabel($label, $minconf = 1) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('getreceivedbylabel requires a numeric minconf >= 0');
|
|
||||||
if (!$label || empty($label))
|
|
||||||
throw new BitcoinClientException("getreceivedbylabel requires a label");
|
|
||||||
return $this->query("getreceivedbylabel", $label, $minconf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a list of server RPC commands or help for $command, if specified.
|
|
||||||
*
|
|
||||||
* @param string $command
|
|
||||||
* @return string Help text
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function help($command = NULL) {
|
|
||||||
if (!$command || empty($command))
|
|
||||||
return $this->query("help");
|
|
||||||
return $this->query("help", $command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of arrays showing how many Bitcoins have been received by
|
|
||||||
* each address in the server's wallet.
|
|
||||||
*
|
|
||||||
* @param integer $minconf Minimum number of confirmations before payments are included.
|
|
||||||
* @param boolean $includeempty Whether to include addresses that haven't received any payments.
|
|
||||||
* @return array An array of arrays. The elements are:
|
|
||||||
* "address" => receiving address
|
|
||||||
* "account" => the account of the receiving address
|
|
||||||
* "amount" => total amount received by the address
|
|
||||||
* "confirmations" => number of confirmations of the most recent transaction included
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function listreceivedbyaddress($minconf = 1, $includeempty = FALSE) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('listreceivedbyaddress requires a numeric minconf >= 0');
|
|
||||||
return $this->query("listreceivedbyaddress", $minconf, $includeempty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of arrays showing how many Bitcoins have been received by
|
|
||||||
* each account in the server's wallet.
|
|
||||||
*
|
|
||||||
* @param integer $minconf
|
|
||||||
* Minimum number of confirmations before payments are included.
|
|
||||||
* @param boolean $includeempty
|
|
||||||
* Whether to include addresses that haven't received any payments.
|
|
||||||
* @return array An array of arrays. The elements are:
|
|
||||||
* "account" => the label of the receiving address
|
|
||||||
* "amount" => total amount received by the address
|
|
||||||
* "confirmations" => number of confirmations of the most recent transaction included
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.17
|
|
||||||
*/
|
|
||||||
public function listreceivedbyaccount($minconf = 1, $includeempty = FALSE) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('listreceivedbyaccount requires a numeric minconf >= 0');
|
|
||||||
return $this->query("listreceivedbyaccount", $minconf, $includeempty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of arrays showing how many Bitcoins have been received by
|
|
||||||
* each label in the server's wallet.
|
|
||||||
*
|
|
||||||
* @param integer $minconf Minimum number of confirmations before payments are included.
|
|
||||||
* @param boolean $includeempty Whether to include addresses that haven't received any payments.
|
|
||||||
* @return array An array of arrays. The elements are:
|
|
||||||
* "label" => the label of the receiving address
|
|
||||||
* "amount" => total amount received by the address
|
|
||||||
* "confirmations" => number of confirmations of the most recent transaction included
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @deprecated Since 0.3.17
|
|
||||||
*/
|
|
||||||
public function listreceivedbylabel($minconf = 1, $includeempty = FALSE) {
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('listreceivedbylabel requires a numeric minconf >= 0');
|
|
||||||
return $this->query("listreceivedbylabel", $minconf, $includeempty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send amount from the server's available balance.
|
|
||||||
*
|
|
||||||
* $amount is a real and is rounded to the nearest 0.01. Returns string "sent" on success.
|
|
||||||
*
|
|
||||||
* @param string $address Destination Bitcoin address or IP address
|
|
||||||
* @param float $amount Amount to send. Will be rounded to the nearest 0.01.
|
|
||||||
* @param string $comment
|
|
||||||
* @param string $comment_to
|
|
||||||
* @return string Hexadecimal transaction ID on success.
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @todo Document the comment arguments better.
|
|
||||||
*/
|
|
||||||
public function sendtoaddress($address, $amount, $comment = NULL, $comment_to = NULL) {
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("sendtoaddress requires a destination address");
|
|
||||||
if (!$amount || empty($amount))
|
|
||||||
throw new BitcoinClientException("sendtoaddress requires an amount to send");
|
|
||||||
if (!is_numeric($amount) || $amount <= 0)
|
|
||||||
throw new BitcoinClientException("sendtoaddress requires the amount sent to be a number > 0");
|
|
||||||
$amount = floatval($amount);
|
|
||||||
if (!$comment && !$comment_to)
|
|
||||||
return $this->query("sendtoaddress", $address, $amount);
|
|
||||||
if (!$comment_to)
|
|
||||||
return $this->query("sendtoaddress", $address, $amount, $comment);
|
|
||||||
return $this->query("sendtoaddress", $address, $amount, $comment, $comment_to);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop the Bitcoin server.
|
|
||||||
*
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function stop() {
|
|
||||||
return $this->query("stop");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that $address looks like a proper Bitcoin address.
|
|
||||||
*
|
|
||||||
* @param string $address String to test for validity as a Bitcoin address
|
|
||||||
* @return array An array containing:
|
|
||||||
* "isvalid" => true or false
|
|
||||||
* "ismine" => true if the address is in the server's wallet
|
|
||||||
* "address" => bitcoinaddress
|
|
||||||
* Note: ismine and address are only returned if the address is valid.
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function validateaddress($address) {
|
|
||||||
if (!$address || empty($address))
|
|
||||||
throw new BitcoinClientException("validateaddress requires a Bitcoin address");
|
|
||||||
return $this->query("validateaddress", $address);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return information about a specific transaction.
|
|
||||||
*
|
|
||||||
* @param string $txid 64-digit hexadecimal transaction ID
|
|
||||||
* @return array An error array, or an array containing:
|
|
||||||
* "amount" => float Transaction amount
|
|
||||||
* "fee" => float Transaction fee
|
|
||||||
* "confirmations" => integer Network confirmations of this transaction
|
|
||||||
* "txid" => string The transaction ID
|
|
||||||
* "message" => string Transaction "comment" message
|
|
||||||
* "to" => string Transaction "to" message
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.18
|
|
||||||
*/
|
|
||||||
public function gettransaction($txid) {
|
|
||||||
if (!$txid || empty($txid) || strlen($txid) != 64 || !preg_match('/^[0-9a-fA-F]+$/', $txid))
|
|
||||||
throw new BitcoinClientException("gettransaction requires a valid hexadecimal transaction ID");
|
|
||||||
return $this->query("gettransaction", $txid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move bitcoins between accounts.
|
|
||||||
*
|
|
||||||
* @param string $fromaccount
|
|
||||||
* Account to move from. If given as an empty string ("") or NULL, bitcoins will
|
|
||||||
* be moved from the wallet balance to the target account.
|
|
||||||
* @param string $toaccount
|
|
||||||
* Account to move to
|
|
||||||
* @param float $amount
|
|
||||||
* Amount to move
|
|
||||||
* @param integer $minconf
|
|
||||||
* Minimum number of confirmations on bitcoins being moved
|
|
||||||
* @param string $comment
|
|
||||||
* Transaction comment
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.18
|
|
||||||
*/
|
|
||||||
public function move($fromaccount = "", $toaccount, $amount, $minconf = 1, $comment = NULL) {
|
|
||||||
if (!$fromaccount)
|
|
||||||
$fromaccount = "";
|
|
||||||
if (!$toaccount || empty($toaccount) || !$amount || !is_numeric($amount) || $amount <= 0)
|
|
||||||
throw new BitcoinClientException("move requires a from account, to account and numeric amount > 0");
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('move requires a numeric $minconf >= 0');
|
|
||||||
if (!$comment || empty($comment))
|
|
||||||
return $this->query("move", $fromaccount, $toaccount, $amount, $minconf);
|
|
||||||
return $this->query("move", $fromaccount, $toaccount, $amount, $minconf, $comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send $amount from $account's balance to $toaddress. This method will fail
|
|
||||||
* if there is less than $amount bitcoins with $minconf confirmations in the
|
|
||||||
* account's balance (unless $account is the empty-string-named default
|
|
||||||
* account; it behaves like the sendtoaddress method). Returns transaction
|
|
||||||
* ID on success.
|
|
||||||
*
|
|
||||||
* @param string $account Account to send from
|
|
||||||
* @param string $toaddress Bitcoin address to send to
|
|
||||||
* @param float $amount Amount to send
|
|
||||||
* @param integer $minconf Minimum number of confirmations on bitcoins being sent
|
|
||||||
* @param string $comment
|
|
||||||
* @param string $comment_to
|
|
||||||
* @return string Hexadecimal transaction ID
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.18
|
|
||||||
*/
|
|
||||||
public function sendfrom($account, $toaddress, $amount, $minconf = 1, $comment = NULL, $comment_to = NULL) {
|
|
||||||
if (!$account || !$toaddress || empty($toaddress) || !$amount || !is_numeric($amount) || $amount <= 0)
|
|
||||||
throw new BitcoinClientException("sendfrom requires a from account, to account and numeric amount > 0");
|
|
||||||
if (!is_numeric($minconf) || $minconf < 0)
|
|
||||||
throw new BitcoinClientException('sendfrom requires a numeric $minconf >= 0');
|
|
||||||
if (!$comment && !$comment_to)
|
|
||||||
return $this->query("sendfrom", $account, $toaddress, $amount, $minconf);
|
|
||||||
if (!$comment_to)
|
|
||||||
return $this->query("sendfrom", $account, $toaddress, $amount, $minconf, $comment);
|
|
||||||
$this->query("sendfrom", $account, $toaddress, $amount, $minconf, $comment, $comment_to);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return formatted hash data to work on, or try to solve specified block.
|
|
||||||
*
|
|
||||||
* If $data is provided, tries to solve the block and returns true if successful.
|
|
||||||
* If $data is not provided, returns formatted hash data to work on.
|
|
||||||
*
|
|
||||||
* @param string $data Block data
|
|
||||||
* @return mixed
|
|
||||||
* boolean TRUE if $data provided and block solving successful
|
|
||||||
* array otherwise, containing:
|
|
||||||
* "midstate" => string, precomputed hash state after hashing the first half of the data
|
|
||||||
* "data" => string, block data
|
|
||||||
* "hash1" => string, formatted hash buffer for second hash
|
|
||||||
* "target" => string, little endian hash target
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.18
|
|
||||||
*/
|
|
||||||
public function getwork($data = NULL) {
|
|
||||||
if (!$data)
|
|
||||||
return $this->query("getwork");
|
|
||||||
return $this->query("getwork", $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current bitcoin address for receiving payments to $account.
|
|
||||||
* The account and address will be created if $account doesn't exist.
|
|
||||||
*
|
|
||||||
* @param string $account Account name
|
|
||||||
* @return string Bitcoin address for $account
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
* @since 0.3.18
|
|
||||||
*/
|
|
||||||
public function getaccountaddress($account) {
|
|
||||||
if (!$account || empty($account))
|
|
||||||
throw new BitcoinClientException("getaccountaddress requires an account");
|
|
||||||
return $this->query("getaccountaddress", $account);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a recent hashes per second performance measurement.
|
|
||||||
*
|
|
||||||
* @return integer Hashes per second
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function gethashespersec() {
|
|
||||||
return $this->query("gethashespersec");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of addresses associated with the given account.
|
|
||||||
*
|
|
||||||
* @param string $account
|
|
||||||
* @return array
|
|
||||||
* A simple array of Bitcoin addresses associated with $account, empty
|
|
||||||
* if the account doesn't exist.
|
|
||||||
* @throws BitcoinClientException
|
|
||||||
*/
|
|
||||||
public function getaddressesbyaccount($account) {
|
|
||||||
if (!$account || empty($account))
|
|
||||||
throw new BitcoinClientException("getaddressesbyaccount requires an account");
|
|
||||||
return $this->query("getaddressesbyaccount", $account);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class BitcoinWrapper extends BitcoinClient {
|
|||||||
$this->oDebug->append("STA " . __METHOD__, 4);
|
$this->oDebug->append("STA " . __METHOD__, 4);
|
||||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||||
try {
|
try {
|
||||||
$dNetworkHashrate = $this->query('getmininginfo');
|
$dNetworkHashrate = $this->getmininginfo();
|
||||||
if (is_array($dNetworkHashrate)) {
|
if (is_array($dNetworkHashrate)) {
|
||||||
if (array_key_exists('networkhashps', $dNetworkHashrate)) {
|
if (array_key_exists('networkhashps', $dNetworkHashrate)) {
|
||||||
$dNetworkHashrate = $dNetworkHashrate['networkhashps'];
|
$dNetworkHashrate = $dNetworkHashrate['networkhashps'];
|
||||||
|
|||||||
165
public/include/jsonRPCClient.php
Normal file
165
public/include/jsonRPCClient.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
COPYRIGHT
|
||||||
|
|
||||||
|
Copyright 2007 Sergio Vaccaro <sergio@inservibile.org>
|
||||||
|
|
||||||
|
This file is part of JSON-RPC PHP.
|
||||||
|
|
||||||
|
JSON-RPC PHP is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
JSON-RPC PHP is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with JSON-RPC PHP; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The object of this class are generic jsonRPC 1.0 clients
|
||||||
|
* http://json-rpc.org/wiki/specification
|
||||||
|
*
|
||||||
|
* @author sergio <jsonrpcphp@inservibile.org>
|
||||||
|
*/
|
||||||
|
class jsonRPCClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug state
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $debug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server URL
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $url;
|
||||||
|
/**
|
||||||
|
* The request id
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
/**
|
||||||
|
* If true, notifications are performed instead of requests
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $notification = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the connection parameters
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param boolean $debug
|
||||||
|
*/
|
||||||
|
public function __construct($url,$debug = false) {
|
||||||
|
// server URL
|
||||||
|
$this->url = $url;
|
||||||
|
// proxy
|
||||||
|
empty($proxy) ? $this->proxy = '' : $this->proxy = $proxy;
|
||||||
|
// debug state
|
||||||
|
empty($debug) ? $this->debug = false : $this->debug = true;
|
||||||
|
// message id
|
||||||
|
$this->id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the notification state of the object. In this state, notifications are performed, instead of requests.
|
||||||
|
*
|
||||||
|
* @param boolean $notification
|
||||||
|
*/
|
||||||
|
public function setRPCNotification($notification) {
|
||||||
|
empty($notification) ?
|
||||||
|
$this->notification = false
|
||||||
|
:
|
||||||
|
$this->notification = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a jsonRCP request and gets the results as an array
|
||||||
|
*
|
||||||
|
* @param string $method
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function __call($method,$params) {
|
||||||
|
|
||||||
|
// check
|
||||||
|
if (!is_scalar($method)) {
|
||||||
|
throw new Exception('Method name has no scalar value');
|
||||||
|
}
|
||||||
|
|
||||||
|
// check
|
||||||
|
if (is_array($params)) {
|
||||||
|
// no keys
|
||||||
|
$params = array_values($params);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Params must be given as array');
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets notification or request task
|
||||||
|
if ($this->notification) {
|
||||||
|
$currentId = NULL;
|
||||||
|
} else {
|
||||||
|
$currentId = $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepares the request
|
||||||
|
$request = array(
|
||||||
|
'method' => $method,
|
||||||
|
'params' => $params,
|
||||||
|
'id' => $currentId
|
||||||
|
);
|
||||||
|
$request = json_encode($request);
|
||||||
|
$this->debug && $this->debug.='***** Request *****'."\n".$request."\n".'***** End Of request *****'."\n\n";
|
||||||
|
|
||||||
|
// performs the HTTP POST
|
||||||
|
$opts = array ('http' => array (
|
||||||
|
'method' => 'POST',
|
||||||
|
'header' => 'Content-type: application/json',
|
||||||
|
'content' => $request
|
||||||
|
));
|
||||||
|
$context = stream_context_create($opts);
|
||||||
|
if ($fp = fopen($this->url, 'r', false, $context)) {
|
||||||
|
$response = '';
|
||||||
|
while($row = fgets($fp)) {
|
||||||
|
$response.= trim($row)."\n";
|
||||||
|
}
|
||||||
|
$this->debug && $this->debug.='***** Server response *****'."\n".$response.'***** End of server response *****'."\n";
|
||||||
|
$response = json_decode($response,true);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Unable to connect to '.$this->url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug output
|
||||||
|
if ($this->debug) {
|
||||||
|
echo nl2br($debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
// final checks and return
|
||||||
|
if (!$this->notification) {
|
||||||
|
// check
|
||||||
|
if ($response['id'] != $currentId) {
|
||||||
|
throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
|
||||||
|
}
|
||||||
|
if (!is_null($response['error'])) {
|
||||||
|
throw new Exception('Request error: '.$response['error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response['result'];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($bitcoin->can_connect() === true){
|
if ($bitcoin->can_connect() === true){
|
||||||
$aGetInfo = $bitcoin->query('getinfo');
|
$aGetInfo = $bitcoin->getinfo();
|
||||||
} else {
|
} else {
|
||||||
$aGetInfo = array('errors' => 'Unable to connect');
|
$aGetInfo = array('errors' => 'Unable to connect');
|
||||||
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
||||||
|
|||||||
@ -12,8 +12,8 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
|||||||
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
||||||
$debug->append('No cached version available, fetching from backend', 3);
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
if ($bitcoin->can_connect() === true){
|
if ($bitcoin->can_connect() === true){
|
||||||
$dBalance = $bitcoin->query('getbalance');
|
$dBalance = $bitcoin->getbalance();
|
||||||
$aGetInfo = $bitcoin->query('getinfo');
|
$aGetInfo = $bitcoin->getinfo();
|
||||||
if (is_array($aGetInfo) && array_key_exists('newmint', $aGetInfo)) {
|
if (is_array($aGetInfo) && array_key_exists('newmint', $aGetInfo)) {
|
||||||
$dNewmint = $aGetInfo['newmint'];
|
$dNewmint = $aGetInfo['newmint'];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
|||||||
$dDifficulty = $bitcoin->getdifficulty();
|
$dDifficulty = $bitcoin->getdifficulty();
|
||||||
$dNetworkHashrate = $bitcoin->getnetworkhashps();
|
$dNetworkHashrate = $bitcoin->getnetworkhashps();
|
||||||
$iBlock = $bitcoin->getblockcount();
|
$iBlock = $bitcoin->getblockcount();
|
||||||
is_int($iBlock) && $iBlock > 0 ? $sBlockHash = $bitcoin->query('getblockhash', $iBlock) : $sBlockHash = '';
|
is_int($iBlock) && $iBlock > 0 ? $sBlockHash = $bitcoin->getblockhash($iBlock) : $sBlockHash = '';
|
||||||
} else {
|
} else {
|
||||||
$dDifficulty = 1;
|
$dDifficulty = 1;
|
||||||
$dNetworkHashrate = 1;
|
$dNetworkHashrate = 1;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user