我目前正在安装一个处理比特币的网络应用程序。我终于安装了它,但是当我打开帐户页面并尝试添加比特币支付地址时,我一直得到"您必须输入一个有效的地址"错误。
代码的帐户部分位于支付特定部分下方开始关于下降的四分之一,它还使用粘贴在此部分代码下方的bitcoin_model。
aFile = input("Please enter the name for your txt. file: ")
fileName = (aFile + ".txt")
WRITE = "w"
APPEND = "a"
file = []
name = " "
while name != "DONE" :
name = input("Please enter the guest name (Enter DONE if there is no more names) : ").upper()
file.append(name)
file.remove("DONE")
print("The guests list in alphabetical order, and it will save in " + fileName + " :")
file.sort()
for U in file :
print(U)
outputfile = open(fileName, mode = WRITE)
outputfile.write(name)
outputfile.close()
print("file written successfully.")
下面是代码的bitcoin_model部分。
<?php
/**
* Accounts.php
*
* Provides accounts functionality, and users profiles/settings
* @category Accounts
* @package BitWasp
* @licence Unlicence
* @subpackage Controllers
* @author Thomas Kerin <thomas@bitwasp.co>
*/
defined('BASEPATH') OR exit('No direct script access allowed');
use BitWasp\BitcoinLib\BitcoinLib;
/**
* Accounts Management Controller
*
* @category Accounts
* @package BitWasp
* @licence Unlicence
* @subpackage Controllers
* @author Thomas Kerin <thomas@bitwasp.co>
*/
class Accounts extends MY_Controller
{
/**
* Constructor
*
* @access public
*/
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->library('gpg');
$this->load->model('accounts_model');
$this->load->model('location_model');
}
/**
* View a users profile
* URI: /user/$hash
*
* Users can load a public profile of other users. If the
* Accounts_Model\get() returns FALSE, the requested account does not
* exist, and the user is redirected to the homepage. Otherwise,
* the specified view is loaded into the Layout class.
*
* @param string $hash
*/
public function view($hash)
{
// Load the specified user, redirect if they don't exist.
$data['user'] = $this->accounts_model->get(array('user_hash' => $hash));
if ($data['user'] == false)
redirect('');
$this->load->model('items_model');
$this->load->model('review_model');
// Load information for the view.
$data['page'] = 'accounts/view';
$data['title'] = $data['user']['user_name'];
$data['logged_in'] = $this->current_user->logged_in();
$data['user_role'] = $this->current_user->user_role;
$data['reviews'] = $this->review_model->random_latest_reviews(8, 'user', $data['user']['user_hash']);
$data['review_count']['all'] = $this->review_model->count_reviews('user', $data['user']['user_hash']);
$data['review_count']['positive'] = $this->review_model->count_reviews('user', $data['user']['user_hash'], 0);
$data['review_count']['disputed'] = $this->review_model->count_reviews('user', $data['user']['user_hash'], 1);
$data['average_rating'] = $this->review_model->current_rating('user', $hash);
if ($data['user']['user_role'] == 'Vendor')
$data['items'] = $this->items_model->get_list(array('vendor_hash' => $data['user']['user_hash']));
$this->_render($data['page'], $data);
}
/**
* Payout
*
* This page allows buyers/sellers to set up refund/payout addresses. These addresses
* are the destination for any funds meant for that user. Administrators do not have this.
*
* Users must enter their password to make this change.
*/
public function payout()
{
if ($this->current_user->user_role == 'Admin')
redirect('');
$this->load->model('bitcoin_model');
$data['address'] = $this->bitcoin_model->get_payout_address($this->current_user->user_id);
if ($this->input->post('submit_payout_address') == 'Submit') {
if ($this->form_validation->run('submit_payout_address')) {
$user_info = $this->users_model->get(array('id' => $this->current_user->user_id));
$check_login = $this->users_model->check_password($this->current_user->user_name, $this->general->password($this->input->post('password'), $user_info['salt']));
if (is_array($check_login) == TRUE && $check_login['id'] == $this->current_user->user_id) {
if ($this->bitcoin_model->set_payout_address($this->current_user->user_id, $this->input->post('address'))) {
$this->current_user->set_return_message('Payout address has been saved', 'success');
redirect('account');
} else {
$data['returnMessage'] = 'Unable to update your address at this time.';
}
} else {
$data['returnMessage'] = 'Your password was incorrect.';
}
}
}
$data['page'] = 'accounts/payout';
$data['title'] = (($this->current_user->user_role == 'Vendor') ? 'Payout' : 'Refund') . ' Address';
$this->_render('accounts/payout', $data);
}
bw_payout_address mysql数据库部分。
use BitWasp\BitcoinLib\BitcoinLib;
use BitWasp\BitcoinLib\Electrum;
use BitWasp\BitcoinLib\BIP32;
/**
* Bitcoin Model
*
* This class handles the database queries relating to orders.
*
* @package BitWasp
* @subpackage Models
* @category Bitcoin
* @author BitWasp
*
*/
class Bitcoin_model extends CI_Model
{
/**
* Construct
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Get Fees Address
*
* This function generates the next fees address from the electrum
* MPK, logs the usage, and adds the address to the watch address
* list.
*
* @param string $user_hash
* @param string $magic_byte
* @return string
*/
public function get_fees_address($user_hash, $magic_byte)
{
$this->load->model('bip32_model');
$key = $this->bip32_model->get_next_admin_child();
$address = BitcoinLib::public_key_to_address($key['public_key'], $magic_byte);
// Log electrum usage
$this->bitcoin_model->log_key_usage('fees', $this->bw_config->bip32_mpk, $key['key_index'], $key['public_key'], FALSE, $user_hash);
// Add the address to the watch list.
$this->add_watch_address($address, 'fees');
return $address;
}
/**
* Set Payout Address
*
* @param $user_id
* @param $address
* @return bool
*/
public function set_payout_address($user_id, $address)
{
return $this->db->insert('payout_address', array('user_id' => $user_id, 'address' => $address, 'time' => time())) == TRUE;
}
/**
* Get Payout Address
*
* @param $user_id
* @return bool
*/
public function get_payout_address($user_id)
{
$q = $this->db->limit(1)->order_by('time')->get_where('payout_address', array('user_id' => $user_id));
if ($q->num_rows() > 0) {
$row = $q->row_array();
$row['time_f'] = $this->general->format_time($row['time']);
} else {
$row = FALSE;
}
return $row;
}
此代码是否有任何问题,或者我还缺少什么?