public function index($s = null) { $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD); $paytxfee = Parameters::find('first'); $txfee = $paytxfee['payxgctxfee']; $getrawtransaction = $greencoin->getrawtransaction($s); $decoderawtransaction = $greencoin->decoderawtransaction($getrawtransaction); foreach ($decoderawtransaction['vout'] as $out) { foreach ($out['scriptPubKey']['addresses'] as $address) { $username = $greencoin->getaccount($address); $Amount = (double) $out['value']; if ($greencoin->getaccount($address) != "") { $Transactions = Transactions::find('first', array('conditions' => array('TransactionHash' => $s))); if ($Transactions['_id'] == "") { $t = Transactions::create(); $Amount = $Amount; $comment = "Move from User: "******"; Address: " . GREENCOINX_ADDRESS . "; Amount:" . $Amount . ";"; $transfer = $greencoin->sendfrom($username, GREENCOINX_ADDRESS, (double) $Amount, (int) 0, $comment); if (isset($transfer['error'])) { $error = $transfer['error']; } else { $error = $transfer; } $data = array('DateTime' => new \MongoDate(), 'TransactionHash' => $s, 'username' => $username, 'address' => $address, 'Currency' => 'XGC', 'Amount' => $Amount, 'Added' => true, 'Transfer' => $comment); $t->save($data); $userName = str_replace("SiiCrypto-", "", $username); $details = Details::find('first', array('conditions' => array('username' => (string) $userName))); $dataDetails = array('balance.XGC' => (double) ((double) $details['balance.XGC'] + (double) $Amount), 'XGCnewaddress' => 'Yes'); $details = Details::find('all', array('conditions' => array('username' => (string) $userName)))->save($dataDetails); } else { $Transactions = Transactions::find('first', array('conditions' => array('TransactionHash' => $s)))->save($data); } } } } }
public function getprevtx() { $user = Session::read('default'); if ($user == "") { return $this->redirect('wallet::login'); } $toAddress = $this->request->query['address']; $amount = $this->request->query['amount']; $email = $this->request->query['email']; $fee = $this->request->query['fee']; $wallet = Users::find("first", array("conditions" => array("walletid" => $user['walletid']))); $greencoinAddress = $wallet['greencoinAddress'][0]; $addressBal = Addresses::find("first", array("conditions" => array("a_id" => $greencoinAddress))); $balance = $addressBal['balance']; $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD); $finalCreate = array(); foreach ($addressBal['txs'] as $tx) { $txid = $tx['addresses']; //print_r($txid); //print_r("**********************************\n"); $getrawtransaction = $greencoin->getrawtransaction($txid); $decoderawtransaction = $greencoin->decoderawtransaction($getrawtransaction); // print_r($decoderawtransaction); foreach ($decoderawtransaction['vout'] as $vout) { //print_r($vout); //print_r("---------------------------\n"); foreach ($vout['scriptPubKey']['addresses'] as $address) { if ($address == $greencoinAddress) { $x_txid = $txid; $x_vout = $vout['n']; $x_value = $vout['value']; $x_scriptPubKey = $vout['scriptPubKey']['hex']; // print_r("txid----"); // print_r( $x_txid); // print_r("\n"); // print_r("vout----"); // print_r( $x_vout); // print_r("\n"); // print_r("SPKhex----"); // print_r( $x_scriptPubKey); // print_r("\n"); } } } $createTrans = array('txid' => $x_txid, 'vout' => $x_vout, "scriptPubKey" => $x_scriptPubKey); array_push($finalCreate, $createTrans); } //print_r((object)$finalCreate) ; $createData = array($toAddress => round($amount, 8)); $createData = array_merge_recursive($createData, array($greencoinAddress => round($balance / 100000000 - $amount - $fee, 8))); // print_r($createData); $createrawtransaction = $greencoin->createrawtransaction((array) (object) $finalCreate, $createData); // print_r($createrawtransaction); // print_r($greencoin->decoderawtransaction($createrawtransaction)); // print_r($greencoin->signrawtransaction($createrawtransaction)); // $signrawtransaction = $greencoin->signrawtransaction($createrawtransaction,array((object)$finalCreate),array($privKey)); // $txid = $greencoin->sendrawtransaction($createrawtransaction); // print_r($txid); // bitcoin.createrawtransaction ([{"txid":unspent[WhichTrans]["txid"], // "vout":unspent[WhichTrans]["vout"], // "scriptPubKey":unspent[WhichTrans]["scriptPubKey"], // "redeemScript":unspent[WhichTrans]["redeemScript"]}], // {SendAddress:HowMuch/100000000.00,ChangeAddress:Leftover/100000000.00}) // bitcoin.signrawtransaction (rawtransact, // [{"txid":unspent[WhichTrans]["txid"], // "vout":unspent[WhichTrans]["vout"],"scriptPubKey":unspent[WhichTrans]["scriptPubKey"], // "redeemScript":unspent[WhichTrans]["redeemScript"]}], // [multisigprivkeyone]) return $this->render(array('json' => array('success' => 1, 'rawtransact' => $createrawtransaction, 'finalCreate' => $finalCreate))); return $this->render(array('layout' => false)); }