xmr-rpc: allow to list transactions

very basic list, this rpc is screwed... not even a proper timestamp...
This commit is contained in:
Tanguy Pruvot 2017-02-01 02:13:10 +01:00
parent 8d930e0f33
commit acc8285a90
4 changed files with 87 additions and 11 deletions

View file

@ -218,8 +218,59 @@ class WalletRPC {
$this->error = $this->rpc_wallet->error; $this->error = $this->rpc_wallet->error;
break; break;
case 'listtransactions': case 'listtransactions':
$res = $this->rpc_wallet->get_bulk_payments(); // make it as close as possible as bitcoin rpc... sigh (todo: xmr-rpc function)
$txs = array();
$named_params = array('transfer_type' => 'all');
$res = $this->rpc_wallet->incoming_transfers($named_params);
$res = isset($res['transfers']) ? $res['transfers'] : array();
$this->error = $this->rpc_wallet->error; $this->error = $this->rpc_wallet->error;
foreach ($res as $k=>$tx) {
$tx['category'] = 'receive';
$tx['txid'] = $tx['tx_hash'];
$tx['amount'] = $tx['amount'] / 1e12;
$raw = $this->rpc->gettransactions(array(
'txs_hashes' => array($tx['tx_hash']),
'decode_as_json' => true
));
$raw = reset(arraySafeVal($raw,'txs',array()));
if (!empty($raw)) {
$k = (double) $raw['block_height'] + ($k/1000.0);
unset($raw['as_hex']);
unset($raw['tx_hash']);
//$raw['json'] = json_decode($raw['as_json']);
unset($raw['as_json']);
}
$tx = array_merge($tx, $raw);
unset($tx['tx_hash']);
$k = sprintf("%015.4F", $k); // sort key
$txs[$k] = $tx;
}
$named_params = array('min_block_height' => 1);
$res = $this->rpc_wallet->get_bulk_payments($named_params);
$res = isset($res['payments']) ? $res['payments'] : array();
foreach ($res as $k=>$tx) {
$tx['category'] = 'send';
$k = (double) $raw['block_height'] + 0.5 + ($k/1000.0); // sort key
$tx['txid'] = $tx['tx_hash'];
$tx['amount'] = $tx['amount'] / 1e12;
$raw = $this->rpc->gettransactions(array(
'txs_hashes' => array($tx['tx_hash']),
'decode_as_json' => true
));
$raw = reset(arraySafeVal($raw,'txs',array()));
if (!empty($raw)) {
unset($raw['as_hex']);
unset($raw['tx_hash']);
//$raw['json'] = json_decode($raw['as_json']);
unset($raw['as_json']);
}
$tx = array_merge($tx, $raw);
unset($tx['tx_hash']);
$k = sprintf("%015.4F", $k);
$txs[$k] = $tx;
}
krsort($txs);
$res = array_values($txs);
break; break;
case 'getaddress': case 'getaddress':
$res = $this->rpc_wallet->getaddress(); $res = $this->rpc_wallet->getaddress();
@ -241,7 +292,10 @@ class WalletRPC {
$this->error = $this->rpc_wallet->error; $this->error = $this->rpc_wallet->error;
break; break;
case 'incoming_transfers': // deprecated ? case 'incoming_transfers': // deprecated ?
$res = $this->rpc_wallet->incoming_transfers(); $named_params = array(
"transfer_type"=>arraySafeVal($params, 0)
);
$res = $this->rpc_wallet->incoming_transfers($named_params);
$this->error = $this->rpc_wallet->error; $this->error = $this->rpc_wallet->error;
break; break;
case 'sendtoaddress': case 'sendtoaddress':
@ -298,6 +352,16 @@ class WalletRPC {
$res = $this->rpc_wallet->store(); $res = $this->rpc_wallet->store();
$this->error = $this->rpc_wallet->error; $this->error = $this->rpc_wallet->error;
break; break;
case 'gettransactions':
$named_params = array(
"txs_hashes" => array(arraySafeVal($params, 0, array())),
'decode_as_json' => true
);
$res = $this->rpc->gettransactions($named_params);
unset($res['txs_as_hex']); // dup
unset($res['txs_as_json']); // dup
$this->error = $this->rpc->error;
return $res;
default: default:
// default to daemon // default to daemon
$res = $this->rpc->__call($method,$params); $res = $this->rpc->__call($method,$params);

View file

@ -43,11 +43,11 @@ class CryptoRPC
switch ($method) { switch ($method) {
case 'getheight': case 'getheight':
case 'getinfo': case 'getinfo':
case 'gettransactions':
case 'start_mining': case 'start_mining':
case 'stop_mining': case 'stop_mining':
return $this->rpcget($method, $params); return $this->rpcget($method, $params);
case 'gettransactions': // decodetransaction
case 'sendrawtransaction': case 'sendrawtransaction':
return $this->rpcpost($method, $params); return $this->rpcpost($method, $params);
@ -63,6 +63,7 @@ class CryptoRPC
// queries with named params // queries with named params
case 'getblocktemplate': case 'getblocktemplate':
case 'get_payments': case 'get_payments':
case 'incoming_transfers':
if (count($params) == 1) { if (count($params) == 1) {
// __call put all params in array $params // __call put all params in array $params
$pop = array_shift($params); $pop = array_shift($params);
@ -110,11 +111,13 @@ class CryptoRPC
); );
curl_setopt_array($curl, $options); curl_setopt_array($curl, $options);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); $postdata = json_encode($data);
//debuglog(json_encode($data)); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
//debuglog($postdata);
// Execute the request and decode to an array // Execute the request and decode to an array
$this->raw_response = curl_exec($curl); $this->raw_response = curl_exec($curl);
//debuglog($this->raw_response);
$this->response = json_decode($this->raw_response, TRUE); $this->response = json_decode($this->raw_response, TRUE);

View file

@ -12,13 +12,13 @@ echo CUFHtml::openTag('fieldset', array('class'=>'inlineLabels'));
echo CUFHtml::openActiveCtrlHolder($market, 'deposit_address'); echo CUFHtml::openActiveCtrlHolder($market, 'deposit_address');
echo CUFHtml::activeLabelEx($market, 'deposit_address'); echo CUFHtml::activeLabelEx($market, 'deposit_address');
echo CUFHtml::activeTextField($market, 'deposit_address', array('maxlength'=>200)); echo CUFHtml::activeTextField($market, 'deposit_address', array('maxlength'=>200));
echo "<p class='formHint2'>.</p>"; echo '<p class="formHint2">Use Address::PaymentID on XMR forks</p>';
echo CUFHtml::closeCtrlHolder(); echo CUFHtml::closeCtrlHolder();
echo CUFHtml::openActiveCtrlHolder($market, 'base_coin'); echo CUFHtml::openActiveCtrlHolder($market, 'base_coin');
echo CUFHtml::activeLabelEx($market, 'base_coin'); echo CUFHtml::activeLabelEx($market, 'base_coin');
echo CUFHtml::activeTextField($market, 'base_coin', array('maxlength'=>16,'style'=>'width: 40px;')); echo CUFHtml::activeTextField($market, 'base_coin', array('maxlength'=>16,'style'=>'width: 40px;'));
echo "<p class='formHint2'>Default (empty) is BTC</p>"; echo '<p class="formHint2">Default (empty) is BTC</p>';
echo CUFHtml::closeCtrlHolder(); echo CUFHtml::closeCtrlHolder();
echo CUFHtml::closeTag('fieldset'); echo CUFHtml::closeTag('fieldset');

View file

@ -81,7 +81,7 @@ foreach($list as $market)
echo '<td title="'.$updated.'">'.$price.'</td>'; echo '<td title="'.$updated.'">'.$price.'</td>';
echo '<td title="'.$updated.'">'.$price2.'</td>'; echo '<td title="'.$updated.'">'.$price2.'</td>';
echo '<td>'; echo '<td style="max-width: 800px; text-overflow: ellipsis; overflow: hidden;">';
if (!empty($market->deposit_address)) { if (!empty($market->deposit_address)) {
$name = CJavaScript::encode($market->name); $name = CJavaScript::encode($market->name);
$addr = CJavaScript::encode($market->deposit_address); $addr = CJavaScript::encode($market->deposit_address);
@ -307,12 +307,13 @@ $txs_array = array(); $lastday = '';
if (!empty($txs)) { if (!empty($txs)) {
// to hide truncated days sums // to hide truncated days sums
$tx = reset($txs); $tx = reset($txs);
if (count($txs) == 2500)
if (count($txs) == 2500 && isset($tx['time']))
$lastday = strftime('%F', $tx['time']); $lastday = strftime('%F', $tx['time']);
if (!empty($txs)) foreach($txs as $tx) if (!empty($txs)) foreach($txs as $tx)
{ {
if (intval($tx['time']) > $list_since) if (ArraySafeVal($tx, 'time', $list_since+1) > $list_since)
$txs_array[] = $tx; $txs_array[] = $tx;
} }
@ -393,7 +394,7 @@ if ($DCR) {
$rows = 0; $rows = 0;
foreach($txs_array as $tx) foreach($txs_array as $tx)
{ {
$category = $tx['category']; $category = ArraySafeVal($tx,'category');
if ($category == 'spent') continue; if ($category == 'spent') continue;
$block = null; $block = null;
@ -402,6 +403,12 @@ foreach($txs_array as $tx)
echo '<tr class="ssrow '.$category.'">'; echo '<tr class="ssrow '.$category.'">';
if (!isset($tx['time'])) {
// martian wallets
echo '<td colspan="8">'.json_encode($tx).'</td>';
continue;
}
$d = datetoa2($tx['time']); $d = datetoa2($tx['time']);
echo '<td><b>'.$d.'</b></td>'; echo '<td><b>'.$d.'</b></td>';
@ -470,6 +477,8 @@ end;
$sums = array(); $sums = array();
foreach($txs_array as $tx) foreach($txs_array as $tx)
{ {
if (!isset($tx['time'])) continue;
$day = strftime('%F', $tx['time']); // YYYY-MM-DD $day = strftime('%F', $tx['time']); // YYYY-MM-DD
if ($day == $lastday) break; // do not show truncated days if ($day == $lastday) break; // do not show truncated days