Exemple #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);
                 }
             }
         }
     }
 }
Exemple #2
0
 public function checkaddress()
 {
     $coin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $security = (int) 2;
     $publickeys = array($this->request->query['pk0'], $this->request->query['pk1'], $this->request->query['pk2']);
     $createMultiSig = $coin->createmultisig($security, $publickeys);
     $data = array('msx' => $createMultiSig);
     return $this->render(array('json' => array("success" => 1, "msx" => $createMultiSig)));
 }
Exemple #3
0
 public function payment()
 {
     $title = "Payment";
     if ($this->request->data) {
         $verify = $this->request->data['verify'];
         $username = $this->request->data['username'];
         $password = $this->request->data['password'];
         $admin = $this->request->data['admin'];
         $totp = $this->request->data['totp'];
         $currency = $this->request->data['currency'];
         if ($password == "") {
             return $this->redirect(array('controller' => 'users', 'action' => 'paymentadminconfirm/' . $currency . '/' . $verify));
         }
         if ($admin == "") {
             return $this->redirect(array('controller' => 'users', 'action' => 'paymentadminconfirm/' . $currency . '/' . $verify));
         }
         $useradmin = Users::find('first', array('conditions' => array('username' => $admin, 'password' => String::hash($password))));
         $pos = strrpos($useradmin['email'], 'siicrypto.com');
         if ($pos === false) {
             // note: three equal signs
             return $this->redirect(array('controller' => 'users', 'action' => 'paymentadminconfirm/' . $currency . '/' . $verify));
         }
         $detailadmin = Details::find('first', array('conditions' => array('username' => $admin)));
         $ga = new GoogleAuthenticator();
         if ($totp == "") {
             return $this->redirect(array('controller' => 'users', 'action' => 'paymentadminconfirm/' . $currency . '/' . $verify));
         } else {
             $checkResult = $ga->verifyCode($detailadmin['secret'], $totp, 2);
             if ($checkResult != 1) {
                 return $this->redirect(array('controller' => 'users', 'action' => 'paymentadminconfirm/' . $currency . '/' . $verify));
             }
         }
         $transaction = Transactions::find('first', array('conditions' => array('verify.payment' => $verify, 'username' => $username, 'Currency' => $currency, 'Paid' => 'No')));
         $user = Users::find('first', array('conditions' => array('username' => $username)));
         $id = $user['_id'];
         $email = $user['email'];
         if ($id == "") {
             return $this->redirect('/login');
         }
         $details = Details::find('first', array('conditions' => array('user_id' => (string) $id)));
         $amount = abs($transaction['Amount']);
         if ($details['balance.' . $currency] <= $amount) {
             $txmessage = "Not Sent! Amount does not match!";
             return compact('txmessage');
         }
         ///////////////////Special for bitcoin as it uses blockchain!
         if ($currency == 'BTC') {
             $guid = BITCOIN_GUID;
             $firstpassword = BITCOIN_FIRST;
             $secondpassword = BITCOIN_SECOND;
             $amount = abs($transaction['Amount']);
             if ($details['balance.BTC'] <= $amount) {
                 return false;
             }
             $fee = $transaction['txFee'];
             $address = $transaction['address'];
             $satoshi = (double) $amount * 100000000;
             $fee_satoshi = (double) $fee * 100000000;
             $json_url = "http://blockchain.info/merchant/{$guid}/payment?password={$firstpassword}&second_password={$secondpassword}&to={$address}&amount={$satoshi}&fee={$fee_satoshi}";
             $json_data = file_get_contents($json_url);
             $json_feed = json_decode($json_data);
             $txmessage = $json_feed->message;
             $txid = $json_feed->tx_hash;
             if ($txid != null) {
                 $data = array('DateTime' => new \MongoDate(), 'TransactionHash' => $txid, 'Paid' => 'Yes', 'Transfer' => $txmessage, 'Admin' => $admin);
                 $transaction = Transactions::find('first', array('conditions' => array('verify.payment' => $verify, 'username' => $username, 'Paid' => 'No')))->save($data);
             }
         } else {
             //						print_r($currency);
             //						print_r($address);
             //						print_r($comment);
             $amount = abs($transaction['Amount']);
             if ($details['balance.' . $currency] <= $amount) {
                 return false;
             }
             $fee = abs($transaction['txFee']);
             $address = $transaction['address'];
             $satoshi = (double) $amount * 100000000;
             $fee_satoshi = (double) $fee * 100000000;
             ///////////////////// Change of code required when Virtual Currency added
             switch ($currency) {
                 case "LTC":
                     $coin = new Litecoin('http://' . LITECOIN_WALLET_SERVER . ':' . LITECOIN_WALLET_PORT, LITECOIN_WALLET_USERNAME, LITECOIN_WALLET_PASSWORD);
                     break;
                 case "XGC":
                     $coin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
                     break;
             }
         }
         // End for /////////////////// Change of code required when Virtual Currency added
         $comment = "User: "******"; Address: " . $address . "; Amount:" . $amount . ";";
         if ($currency == 'LTC' || $currency == 'XGC') {
             if ((double) $details['balance.' . $currency] >= (double) $amount) {
                 $settxfee = $coin->settxfee($fee);
                 $txid = $coin->sendfrom('NilamDoctor', $address, (double) $amount, (int) 1, $comment);
             }
         }
         if ($txid != null) {
             $data = array('DateTime' => new \MongoDate(), 'TransactionHash' => $txid, 'Added' => false, 'Paid' => 'Yes', 'Transfer' => $comment, 'Admin' => $admin);
             $transaction = Transactions::find('all', array('conditions' => array('verify.payment' => $verify, 'username' => $username, 'Currency' => $currency, 'Paid' => 'No')))->save($data);
             $transaction = Transactions::find('first', array('conditions' => array('verify.payment' => $verify, 'username' => $username, 'Currency' => $currency, 'Paid' => 'Yes')));
             $balance = (double) $details['balance.' . $currency] - (double) $amount;
             $balance = (double) $balance + (double) $fee;
             $dataDetails = array('balance.' . $currency => (double) $balance);
             $details = Details::find('all', array('conditions' => array('user_id' => (string) $id)))->save($dataDetails);
             $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
             $body = $view->render('template', compact('transaction', 'details', 'txid', 'currency'), array('controller' => 'users', 'template' => 'withdrawSent', 'type' => 'mail', 'layout' => false));
             $transport = Swift_MailTransport::newInstance();
             $mailer = Swift_Mailer::newInstance($transport);
             $message = Swift_Message::newInstance();
             $message->setSubject($currency . " sent from " . COMPANY_URL);
             $message->setFrom(array(NOREPLY => $currency . ' sent from ' . COMPANY_URL));
             $message->setTo($email);
             $message->addBcc(MAIL_1);
             $message->addBcc(MAIL_2);
             $message->addBcc(MAIL_3);
             $message->setBody($body, 'text/html');
             $txmessage = number_format($amount, 8) . $currency . "  transfered to " . $address;
             $mailer->send($message);
         }
         $transactions = Transactions::find('first', array('conditions' => array('username' => $user['username'], 'Added' => false, 'Currency' => $currency, 'Paid' => 'No')));
         return compact('txmessage', 'txid', 'json_url', 'json_feed', 'title', 'currency', 'transactions');
     }
 }
 public function pushtx($tx = null)
 {
     if ($tx == "") {
         $tx = $this->request->query['tx'];
     }
     if ($tx == "") {
         return $this->render(array('json' => array('success' => 0)));
     }
     //print_r($tx);
     $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $signrawtransaction = $greencoin->signrawtransaction($tx);
     //print_r($signrawtransaction['complete']);
     if ($signrawtransaction['complete'] == true || $signrawtransaction['complete'] == 1) {
         $sendrawtransaction = $greencoin->sendrawtransaction($signrawtransaction['hex']);
     }
     //print_r($sendrawtransaction);
     if (strlen($sendrawtransaction) == 64) {
         return $this->render(array('json' => array('success' => 1, 'txid' => $sendrawtransaction)));
     }
     return $this->render(array('json' => array('success' => 0)));
 }