CIP: XCP Dividends for PoS voting

I mentioned how to do this in my previous reply, wrote a quick script to demonstrate…

http://joelooney.org/xcp-wallet/pastbalance.php?addr=15ZiVuWWVbEGzeukANouKG85K5gUnoJ42n&block=398640&asset=XCP

header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');

require 'Client.php';
use JsonRPC\Client;

$client = new Client('http://public.coindaddy.io:4000/api/');
$client->authentication('rpc', '1234');

$addresses = array($_GET["addr"]);
$assets = array($_GET["asset"]);
$block = $_GET["block"];

$filters = array(array('field' => 'address', 'op' => 'IN', 'value' => $addresses), array('field' => 'asset', 'op' => 'IN', 'value' => $assets));

$balances_result = $client->execute('get_balances', array('filters' => $filters, 'filterop' => "AND", 'start_block' => $block));
$credits_result = $client->execute('get_credits', array('filters' => $filters, 'filterop' => "AND", 'start_block' => $block));
$debits_result = $client->execute('get_debits', array('filters' => $filters, 'filterop' => "AND", 'start_block' => $block));
$current_bal = $balances_result[0]["quantity"];

$total_credits = 0;
$total_debits = 0;
foreach ($credits_result as $key => $value) {$total_credits += $value["quantity"];}
foreach ($debits_result as $key => $value) {$total_debits += $value["quantity"];}

$past_bal = $current_bal - $total_credits + $total_debits;

$result = array('asset' => $assets[0], 'current_balance' => $current_bal, 'past_block'=> $block, 'total_credits_since_past_block' => $total_credits, 'total_debits_since_past_block' => $total_debits, 'past_balance' => $past_bal);

echo json_encode($result);
1 Like