Updates library.php to support more functions

Updates library.php to have the full capability of https://github.com/monero-integrations/monerophp
This commit is contained in:
cryptochangements34 2017-07-17 16:25:34 -05:00 committed by GitHub
parent bf46a1e735
commit f835a9e771
1 changed files with 120 additions and 3 deletions

View File

@ -9,10 +9,9 @@
* http://implix.com
* Modified to work with monero-rpc wallet by Serhack and cryptochangements
*/
class jsonRPCClient
class Monero_Library
{
protected $url = null, $is_debug = false, $parameters_structure = 'array';
protected $curl_options = array(
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 8
@ -77,7 +76,7 @@ class jsonRPCClient
return $this;
}
public function _run($pMethod, $pParams)
private function request($pMethod, $pParams)
{
static $requestId = 0;
// generating uniuqe id per process
@ -217,4 +216,122 @@ class jsonRPCClient
}
}
public function _run($method,$params = null)
{
$result = $this->request($method, $params);
return $result; //the result is returned as an array
}
//prints result as json
public function _print($json)
{
$json_encoded = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo $json_encoded;
}
/*
* The following functions can all be called to interact with the monero rpc wallet
* They will majority of them will return the result as an array
* Example: $daemon->address(); where $daemon is an instance of this class, will return the wallet address as string within an array
*/
public function address()
{
$address = $this->_run('getaddress');
return $address;
}
public function getbalance()
{
$balance = $this->_run('getbalance');
return $balance;
}
public function getheight()
{
$height = $this->_run('getheight');
return $height;
}
public function incoming_transfer($type)
{
$incoming_parameters = array('transfer_type' => $type);
$incoming_transfers = $this->_run('incoming_transfers', $incoming_parameters);
return $incoming_transfers;
}
public function get_transfers($input_type, $input_value)
{
$get_parameters = array($input_type => $input_value);
$get_transfers = $this->_run('get_transfers', $get_parameters);
return $get_transfers;
}
public function view_key()
{
$query_key = array('key_type' => 'view_key');
$query_key_method = $this->_run('query_key', $query_key);
return $query_key_method;
}
/* A payment id can be passed as a string
A random payment id will be generatd if one is not given */
public function make_integrated_address($payment_id)
{
$integrate_address_parameters = array('payment_id' => $payment_id);
$integrate_address_method = $this->_run('make_integrated_address', $integrate_address_parameters);
return $integrate_address_method;
}
public function split_integrated_address($integrated_address)
{
if(!isset($integrated_address)){
echo "Error: Integrated_Address mustn't be null";
}
else{
$split_params = array('integrated_address' => $integrated_address);
$split_methods = $this->_run('split_integrated_address', $split_params);
return $split_methods;
}
}
public function make_uri($address, $amount, $recipient_name = null, $description = null)
{
// If I pass 1, it will be 0.0000001 xmr. Then
$new_amount = $amount * 100000000;
$uri_params = array('address' => $address, 'amount' => $new_amount, 'payment_id' => '', 'recipient_name' => $recipient_name, 'tx_description' => $description);
$uri = $this->_run('make_uri', $uri_params);
return $uri;
}
public function parse_uri($uri)
{
$uri_parameters = array('uri' => $uri);
$parsed_uri = $this->_run('parse_uri', $uri_parameters);
return $parsed_uri;
}
public function transfer($amount, $address, $mixin = 4)
{
$new_amount = $amount * 1000000000000;
$destinations = array('amount' => $new_amount, 'address' => $address);
$transfer_parameters = array('destinations' => array($destinations), 'mixin' => $mixin, 'get_tx_key' => true, 'unlock_time' => 0, 'payment_id' => '');
$transfer_method = $this->_run('transfer', $transfer_parameters);
return $transfer_method;
}
public function get_payments($payment_id)
{
$get_payments_parameters = array('payment_id' => $payment_id);
$get_payments = $this->_run('get_payments', $get_payments_parameters);
return $get_payments;
}
public function get_bulk_payments($payment_id, $min_block_height)
{
$get_bulk_payments_parameters = array('payment_id' => $payment_id, 'min_block_height' => $min_block_height);
$get_bulk_payments = $this->_run('get_bulk_payments', $get_bulk_payments_parameters);
return $get_bulk_payments;
}
}