2017-09-04 156 views
0

我的代碼片段:如何爲比特幣操作設置區塊鏈網址?什麼是區塊鏈操作url的基礎url?

class Blockchain{ 
     protected $guid; // Blockchain wallet identifier (Wallet ID) 
     protected $api_code; // API code, required for creating wallets 
     protected $main_password; // Main Blockchain Wallet password 
     protected $second_password; // Second Blockchain Wallet password if double encryption is enabled 
     protected $port = 3000; // Blockchain Wallet service port 
     protected $base_url = 'http://127.0.0.1'; // Base url to connect to the Blockchain Wallet service 

     public function __construct($config) 
     { 
      // Set config values 
      $this->guid = $config['guid']; 
      $this->main_password = $config['main_password']; 
      // Optional ones 
      $this->api_code = (isset($config['api_code'])) ? $config['api_code'] : NULL; 
      $this->second_password = (isset($config['second_password'])) ? $config['second_password'] : NULL; 
      $this->base_url = (isset($config['base_url'])) ? $config['base_url'] : $this->base_url; 
      $this->port = (isset($config['port'])) ? $config['port'] : $this->port; 

      log_message('info', 'Blockchain Class Initialized'); 

      // Check if the Blockchain Wallet service is running 
      if ($this->execute($this->base_url.':'.$this->port) === NULL) { 
       show_error('Blockchain: Unable to connect to Blockchain Wallet service on: '.$this->base_url.':'.$this->port.''); 
       log_message('error', "Blockchain: Unable to connect to Blockchain Wallet service."); 
      } 
     } 

     public function wallet_balance() 
     { 
      // Get the base url 
      $url=$this->base_url; 

      // Add the port 
      $url.=':'.$this->port.'/'; 

      // Add the api url 
      $url.='merchant/'.$this->guid.'/balance'; 

      // Add options 
      // password 
      $url.='?password='.$this->main_password; 

      // Execute 
      return $this->execute($url); 
     } 

    public function execute($url) 
    { 
     // Get CURL resource 
     $curl = curl_init(); 
     // Set options 
     curl_setopt_array($curl, array(
      CURLOPT_RETURNTRANSFER => TRUE, 
      CURLOPT_URL => $url, 
      // CURLOPT_SSL_VERIFYPEER => FALSE, 
     )); 

     // Send the request & save response 
     $response = curl_exec($curl); 

     // Close request to clear up some resources 
     curl_close($curl); 

     log_message('debug', 'Blockchain: URL executed '.$url); 

     // Return the decoded response as an associative array 
     return json_decode($response, TRUE); 
    } 
} 

會是怎樣的BASE_URL ..

我不理解的基本URL部分..

將它的本地或 「https://api.blockchain.info」(像這樣)

剛纔我在上面的代碼片段的以下聲明中提到了什麼:

protected $base_url = '???????????'; 

從哪個鏈接我會得到正確的迴應?

連接區塊鏈的確切程序是什麼?

請澄清我這個..

+0

你有答案嗎,請在這裏發帖如果得到了......謝謝 –

回答

0

我是Codeigniter-blockchain庫的作者。

base_url是指向您安裝的區塊鏈錢包服務的URL,可以找到安裝服務的完整指南here

您需要安裝nodejsnpm

要安裝Blockchain Wallet服務,運行這個命令:

npm install -g blockchain-wallet-service 

現在安裝後,你可以用這個命令來啓動它:

blockchain-wallet-service start --port 3000 

3000是端口號,可以如果你願意,可以改變它。

現在回庫:

protected $base_url = '???????????'; 

這應該設置爲安裝了Blockchain Wallet服務的URL,在這種情況下localhost127.0.0.1,這已經是默認設置。

protected $port = 3000; 

這是Blockchain Wallet Service運行的端口號,它應該與啓動服務時使用的端口號相同。