// Add to DB DB::insert('coin_wallets', array('address_type' => $_POST['address_type'], 'sigs_required' => $required_sigs, 'sigs_total' => $total_sigs, 'display_name' => $_POST['wallet_name'])); $wallet_id = DB::insertId(); // Gather BIP32 keys $keys = array(); for ($x = 1; $x <= $total_sigs; $x++) { // Auto-generate, if needed if ($_POST['autogen_keys'] == 1) { $private_key = $b32->generate_master_key(); $public_key = $b32->extended_private_to_public($private_key); array_push($keys, array('num' => $x, 'private_key' => $private_key, 'public_key' => $public_key)); } else { $public_key = $_POST['bip32_key' . $x]; } // Add key to db DB::insert('coin_wallets_keys', array('wallet_id' => $wallet_id, 'public_key' => $enc_client->encrypt($public_key))); } // User message if ($_POST['autogen_keys'] == 1) { $template = new template('admin/setup/bip32_keys'); $template->assign('keys', $keys); $template->parse(); exit(0); } else { $template->add_message("Successfully added new wallet, {$_POST['wallet_name']}"); } } // Delete checked wallets } elseif (isset($_POST['submit']) && $_POST['submit'] == tr('Delete Checked Wallets')) { // Go through wallets $ids = get_chk('wallet_id');
public function add_wallet() { // Initialize global $template; $enc_client = new encrypt(); // Set variables $required_sigs = $_POST['address_type'] == 'standard' ? 1 : $_POST['multisig_sig_required']; $total_sigs = $_POST['address_type'] == 'standard' ? 1 : $_POST['multisig_sig_total']; // Validate public keys if ($_POST['autogen_keys'] == 0) { for ($x = 1; $x <= $total_sigs; $x++) { if (!($import = $this->import($_POST['bip32_key' . $x]))) { $template->add_message("The #{$x} BIP32 key you specified is an invalid BIP32 key.", 'error'); } elseif ($import['type'] != 'public') { $template->add_message("The #{$x} BIP32 key you specified is an invalid BIP32 key.", 'error'); } } } // Create wallet, if no errors $wallet_id = 0; if ($template->has_errors != 1) { // Add to DB DB::insert('coin_wallets', array('address_type' => $_POST['address_type'], 'sigs_required' => $required_sigs, 'sigs_total' => $total_sigs, 'display_name' => $_POST['wallet_name'])); $wallet_id = DB::insertId(); // Gather BIP32 keys $keys = array(); for ($x = 1; $x <= $total_sigs; $x++) { // Auto-generate, if needed if ($_POST['autogen_keys'] == 1) { $private_key = $this->generate_master_key(); $public_key = $this->extended_private_to_public($private_key); array_push($keys, array('num' => $x, 'private_key' => $private_key, 'public_key' => $public_key)); } else { $public_key = $_POST['bip32_key' . $x]; } // Add key to db DB::insert('coin_wallets_keys', array('wallet_id' => $wallet_id, 'public_key' => $enc_client->encrypt($public_key))); } // User message if ($_POST['autogen_keys'] == 1) { $template = new template('admin/setup/bip32_keys'); $template->assign('keys', $keys); $template->parse(); exit(0); } else { $template->add_message("Successfully added new wallet, {$_POST['wallet_name']}"); } } // Return return $wallet_id; }
global $template, $config; $bip32 = new bip32(); // Transfer wallet if (isset($_POST['submit']) && $_POST['submit'] == tr('Transfer Wallet')) { // Initialize $enc_client = new encrypt(); // Get wallet if (!($wrow = DB::queryFirstRow("SELECT * FROM coin_wallets WHERE id = %d", $_POST['wallet_id']))) { trigger_error("Wallet does not exist, ID# {$wallet_id}", E_USER_ERROR); } // Add new wallet to DB DB::insert('coin_wallets', array('address_type' => $wrow['address_type'], 'sigs_required' => $wrow['sigs_required'], 'sigs_total' => $wrow['sigs_total'], 'display_name' => $wrow['display_name'])); $new_wallet_id = DB::insertId(); // Gather BIP32 keys for ($x = 1; $x <= $wrow['sigs_total']; $x++) { $public_key = $enc_client->encrypt($_POST['public_key' . $x]); DB::insert('coin_wallets_keys', array('wallet_id' => $new_wallet_id, 'public_key' => $public_key)); } // Gather private keys $x = 1; $privkeys = array(); while (1) { $var = 'private_key' . $x; if (!isset($_POST[$var])) { break; } $privkeys[] = $_POST[$var]; $x++; } // Get total inputs $balance = DB::queryFirstField("SELECT sum(amount) FROM coin_inputs WHERE wallet_id = %d AND is_spent = 0", $_POST['wallet_id']);
if (empty($_POST['uname'])) { $res = json_encode(array('error_msg' => 'param is empty(uname)', 'error_code' => -2)); exit($res); } if (empty($_POST['code'])) { $res = json_encode(array('error_msg' => 'param is empty(code)', 'error_code' => -3)); exit($res); } //客户端接收数据 $uname = $_POST['uname']; //加密后MD5值 $code = $_POST['code']; //服务器端查询数据库 $db = new DB(); $res = $db->get_one('SELECT pwd FROM user where uname="' . $uname . '"'); $pwd = $res['pwd']; if (empty($pwd)) { $res = json_encode(array('error_msg' => 'user is not exist', 'error_code' => -4)); exit($res); } //加密 $ept = new encrypt(); $server_code = $ept->encrypt($uname, $pwd); if ($server_code == $code) { $_SESSION['uname'] = $uname; $res = json_encode(array('error_msg' => 'success.', 'error_code' => 200)); exit($res); } else { $res = json_encode(array('error_msg' => 'password is wrong.', 'error_code' => -1)); exit($res); }