Esempio n. 1
0
 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);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function PrepareTransaction()
 {
     $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];
     $addresses = Addresses::find("first", array('conditions' => array('a_id' => $greencoinAddress)));
     $balance = $addresses['balance'] / 100000000;
     $address = $this->request->query['address'];
     $email = $this->request->query['email'];
     $phone = $this->request->query['phone'];
     $privKey = $this->request->query['priv'];
     $totalSendXGC = $this->request->query['totalSendXGC'];
     $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $listunspent = $greencoin->listunspent();
     if (count($listunspent) == 0) {
         return $this->render(array('json' => array('success' => 0)));
     } else {
         $i = 0;
         $finalListUnspent = array();
         $finallistunspent = array();
         foreach ($listunspent as $ls) {
             if ($ls['address'] == $address) {
                 array_push($finalListUnspent, $ls);
             }
         }
     }
     $totalCalculated = 0;
     $balance = 0;
     foreach ($finalListUnspent as $lu) {
         if ($totalCalculated < $totalSendXGC) {
             $totalCalculated = $totalCalculated + $lu['amount'];
             $balance = $balance + $lu['amount'];
             array_push($finallistunspent, $lu);
         }
     }
     //			print_r($finallistunspent);
     if (count($finallistunspent) == 0) {
         return $this->render(array('json' => array('success' => 0)));
     }
     $passon = $this->request->query['passon'];
     $fee = $this->request->query['fee'];
     $passonArray = split(",", $passon);
     $SendTo = array();
     foreach ($passonArray as $pa) {
         $S = split("#", $pa);
         array_push($SendTo, $S);
     }
     $createData = array();
     $amount = 0;
     foreach ($SendTo as $st) {
         $amount = $amount + $st[1];
     }
     $amount = $amount + $fee;
     $lastCreateList = array();
     $finalCreate = array();
     $k = 0;
     foreach ($finallistunspent as $fc) {
         $lastCreateList[$k]['txid'] = $fc['txid'];
         $lastCreateList[$k]['vout'] = $fc['vout'];
         $k++;
     }
     array_push($finalCreate, $lastCreateList);
     if ((double) round($balance - $amount - $fee, 8) > 0) {
         $createData = array($greencoinAddress => (double) round($balance - $amount - $fee, 8));
     }
     foreach ($SendTo as $st) {
         $createData = array_merge($createData, array($st[0] => (double) $st[1]));
     }
     //		print_r($createData);
     $createrawtransaction = $greencoin->createrawtransaction((array) $lastCreateList, (array) $createData);
     //		print_r($createrawtransaction);
     $decoderawtransaction = $greencoin->decoderawtransaction($createrawtransaction);
     //		print_r($decoderawtransaction);
     $finalSignList = array();
     $k = 0;
     foreach ($decoderawtransaction['vout'] as $decodevout) {
         $finalSignList[$k]['txid'] = $decoderawtransaction['txid'];
         $finalSignList[$k]['vout'] = $decodevout['n'];
         $finalSignList[$k]['scriptPubKey'] = $decodevout['scriptPubKey']['hex'];
         $k++;
     }
     //		print_r($createrawtransaction);
     //		print_r($finalSignList);
     //		print_r($privKey);
     $signrawtransaction = $greencoin->signrawtransaction($createrawtransaction, $finalSignList, array($privKey));
     if ($signrawtransaction['complete'] != 1) {
         return $this->render(array('json' => array('success' => 0)));
     } else {
         $sendrawtransaction = $greencoin->sendrawtransaction($signrawtransaction['hex']);
     }
     if (strlen($sendrawtransaction) == 64) {
         return $this->render(array('json' => array('success' => 1, 'txid' => $sendrawtransaction)));
     }
     $data = array('walletid' => $user['walletid'], 'rawtransaction' => $createrawtransaction, 'sendtransaction' => $sendrawtransaction, 'signlist' => $finalSignList, 'signed' => 'No', 'email' => $email, 'phone' => $phone, 'created' => new \MongoDate());
     $transactions = Transactions::create($data)->save();
     return $this->render(array('json' => $rawtransaction));
 }