mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-29 23:00:33 +00:00
xmr-rpc: allow to list transactions
very basic list, this rpc is screwed... not even a proper timestamp...
This commit is contained in:
parent
8d930e0f33
commit
acc8285a90
4 changed files with 87 additions and 11 deletions
|
@ -218,8 +218,59 @@ class WalletRPC {
|
|||
$this->error = $this->rpc_wallet->error;
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
case 'getaddress':
|
||||
$res = $this->rpc_wallet->getaddress();
|
||||
|
@ -241,7 +292,10 @@ class WalletRPC {
|
|||
$this->error = $this->rpc_wallet->error;
|
||||
break;
|
||||
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;
|
||||
break;
|
||||
case 'sendtoaddress':
|
||||
|
@ -298,6 +352,16 @@ class WalletRPC {
|
|||
$res = $this->rpc_wallet->store();
|
||||
$this->error = $this->rpc_wallet->error;
|
||||
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 to daemon
|
||||
$res = $this->rpc->__call($method,$params);
|
||||
|
|
|
@ -43,11 +43,11 @@ class CryptoRPC
|
|||
switch ($method) {
|
||||
case 'getheight':
|
||||
case 'getinfo':
|
||||
case 'gettransactions':
|
||||
case 'start_mining':
|
||||
case 'stop_mining':
|
||||
return $this->rpcget($method, $params);
|
||||
|
||||
case 'gettransactions': // decodetransaction
|
||||
case 'sendrawtransaction':
|
||||
return $this->rpcpost($method, $params);
|
||||
|
||||
|
@ -63,6 +63,7 @@ class CryptoRPC
|
|||
// queries with named params
|
||||
case 'getblocktemplate':
|
||||
case 'get_payments':
|
||||
case 'incoming_transfers':
|
||||
if (count($params) == 1) {
|
||||
// __call put all params in array $params
|
||||
$pop = array_shift($params);
|
||||
|
@ -110,11 +111,13 @@ class CryptoRPC
|
|||
);
|
||||
|
||||
curl_setopt_array($curl, $options);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
//debuglog(json_encode($data));
|
||||
$postdata = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
|
||||
//debuglog($postdata);
|
||||
|
||||
// Execute the request and decode to an array
|
||||
$this->raw_response = curl_exec($curl);
|
||||
//debuglog($this->raw_response);
|
||||
|
||||
$this->response = json_decode($this->raw_response, TRUE);
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ echo CUFHtml::openTag('fieldset', array('class'=>'inlineLabels'));
|
|||
echo CUFHtml::openActiveCtrlHolder($market, 'deposit_address');
|
||||
echo CUFHtml::activeLabelEx($market, 'deposit_address');
|
||||
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::openActiveCtrlHolder($market, 'base_coin');
|
||||
echo CUFHtml::activeLabelEx($market, 'base_coin');
|
||||
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::closeTag('fieldset');
|
||||
|
|
|
@ -81,7 +81,7 @@ foreach($list as $market)
|
|||
echo '<td title="'.$updated.'">'.$price.'</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)) {
|
||||
$name = CJavaScript::encode($market->name);
|
||||
$addr = CJavaScript::encode($market->deposit_address);
|
||||
|
@ -307,12 +307,13 @@ $txs_array = array(); $lastday = '';
|
|||
if (!empty($txs)) {
|
||||
// to hide truncated days sums
|
||||
$tx = reset($txs);
|
||||
if (count($txs) == 2500)
|
||||
|
||||
if (count($txs) == 2500 && isset($tx['time']))
|
||||
$lastday = strftime('%F', $tx['time']);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -393,7 +394,7 @@ if ($DCR) {
|
|||
$rows = 0;
|
||||
foreach($txs_array as $tx)
|
||||
{
|
||||
$category = $tx['category'];
|
||||
$category = ArraySafeVal($tx,'category');
|
||||
if ($category == 'spent') continue;
|
||||
|
||||
$block = null;
|
||||
|
@ -402,6 +403,12 @@ foreach($txs_array as $tx)
|
|||
|
||||
echo '<tr class="ssrow '.$category.'">';
|
||||
|
||||
if (!isset($tx['time'])) {
|
||||
// martian wallets
|
||||
echo '<td colspan="8">'.json_encode($tx).'</td>';
|
||||
continue;
|
||||
}
|
||||
|
||||
$d = datetoa2($tx['time']);
|
||||
echo '<td><b>'.$d.'</b></td>';
|
||||
|
||||
|
@ -470,6 +477,8 @@ end;
|
|||
$sums = array();
|
||||
foreach($txs_array as $tx)
|
||||
{
|
||||
if (!isset($tx['time'])) continue;
|
||||
|
||||
$day = strftime('%F', $tx['time']); // YYYY-MM-DD
|
||||
if ($day == $lastday) break; // do not show truncated days
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue