public function tx($txid = null, $xgcAddress = null) { $user = Session::read('default'); if ($user == "") { return $this->redirect('wallet::login'); } $wallet = Users::find("first", array("conditions" => array("walletid" => $user['walletid']))); $greencoinAddress = $wallet['greencoinAddress'][0]; if ($xgcAddress != $greencoinAddress) { return $this->redirect('wallet::transactions'); } $address = Addresses::find("first", array("conditions" => array("a_id" => $greencoinAddress))); //$txid = "315965f1702a9bc0f5dede3f8bb81e8497e004789965452988d136b16391b8a5"; $balance = $address['balance'] / 100000000; $sent = $address['sent'] / 100000000; $receive = $address['receive'] / 100000000; $tx = Txes::find("first", array("conditions" => array("txid" => $txid))); $blockheight = Txes::find("first", array('order' => array("blockindex" => -1))); return compact('greencoinAddress', 'wallet', 'balance', 'sent', 'receive', 'last_txs', 'address', 'tx', 'blockheight'); }
public function txes($address = null) { if ($address == "") { $user = Session::read('default'); if ($user == "") { return $this->redirect('wallet::login'); } $wallet = Users::find("first", array("conditions" => array("walletid" => $user['walletid']))); $greencoinAddress = $wallet['greencoinAddress'][0]; } else { $greencoinAddress = $address; } $address = Addresses::find("first", array("conditions" => array("a_id" => $greencoinAddress))); $balance = $address['balance'] / 100000000; $sent = $address['sent'] / 100000000; $received = $address['received'] / 100000000; $txes = array(); $txesout = Txes::find("all", array("conditions" => array("vout.addresses" => $greencoinAddress), "order" => array("timestamp" => -1), "limit" => 100)); $i = 0; foreach ($txesout as $tx) { foreach ($tx['vout'] as $txvout) { if ($txvout['addresses'] == $greencoinAddress) { $txes[$i]['amount'] = $txvout['amount']; $txes[$i]['type'] = "in"; $txes[$i]['timestamp'] = $tx['timestamp']; $txes[$i]['txid'] = $tx['txid']; } } foreach ($tx['vin'] as $txvin) { if ($txvin['addresses'] == $greencoinAddress) { $txes[$i]['amount'] = $txes[$i]['amount'] - $txvin['amount']; } } $i++; } return $this->render(array('json' => array('success' => 1, 'balance' => $balance, 'sent' => $sent, 'received' => $received, 'address' => $greencoinAddress, 'txes' => $txes))); }