示例#1
0
 public function submitTransaction()
 {
     $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];
     $address = Addresses::find("first", array('conditions' => array('a_id' => $greencoinAddress)));
     $balance = $address['balance'];
     $sent = $address['sent'];
     $amount = $this->request->query['amount'];
     $fee = $this->request->query['fee'];
     //exit;
     $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $hex = $this->request->query['signedtx'];
     $getinfo = $greencoin->getinfo();
     //		print_r($getinfo);
     $sendrawtransaction = $greencoin->sendrawtransaction($hex);
     //		print_r($sendrawtransaction);
     //		print_r($hex);
     if (is_array($sendrawtransaction)) {
         if (array_key_exists('error', $sendrawtransaction)) {
             return $this->render(array('json' => $sendrawtransaction));
         }
     } else {
         $newbalance = (double) $balance - (double) $amount - (double) $fee;
         $newsent = (double) $sent + (double) $amount + (double) $fee;
         $data = array('txs.addresses' => $sendrawtransaction, 'txs.type' => 'vout', 'balance' => $newbalance, 'sent' => $newsent);
         $conditions = array('a_id' => $greencoinAddress);
         Addresses::update($data, $conditions);
         return $this->render(array('json' => $sendrawtransaction));
     }
 }