2016-08-15 50 views
0

如何从任何服务中检索比特币交易的哈希码。例如。从比特币交易的URL中检索哈希码

HTTPS [:] // blockchain [点]方式/ TX/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e

HTTPS [:] // blockchain [点]方式/ TX/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e? adv_view = 1

HTTPS [:] // BTC [点] blockr [点] IO/TX /信息/ a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e

+0

欢迎堆栈溢出!我编辑了问题的格式以提高可读性,这可能会增加接收有用答案的可能性。 –

回答

0

手动从串

例如读它,在 “https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e”只读最后的64个字符。发送代码总是64个字符。

正则表达式

如果你从哪个你想读的TX-ID的多个服务/网站,你可以保存其中的Tx-ID开始字符串中的位置,然后读取64个字符那里。既然你没有说你要使用的编程语言,我将展示在C++一个例子:

#include <iostream> 
#include <string> 
#include <vector> 
#include <regex> 


using namespace std; 

struct PositionInString 
{ 
    PositionInString(string h, unsigned int p) : host(h), position(p) {} 

    string host; 
    unsigned int position; 
}; 

int main() 
{ 
    vector<PositionInString> positions; 
    positions.push_back(PositionInString("blockchain.info", 27)); 
    positions.push_back(PositionInString("btc.blockr.io", 30)); 

    while(true) 
    { 
      string url; 
      cout << "Enter url: "; 
      cin >> url; 

      regex reg_ex("([a-z0-9|-]+\\.)*[a-z0-9|-]+\\.[a-z]+"); 
      smatch match; 
      string extract; 

      if (regex_search(url, match, reg_ex)) 
      { 
       extract = match[0]; 
      } 
      else 
      { 
       cout << "Could not extract." << endl; 
       continue; 
      } 



      bool found = false; 
      for(auto& v : positions) 
      { 
       if(v.host.compare(extract) == 0) 
       { 
        cout << "Tx-Id: " << url.substr(v.position, 64) << endl; 
        found = true; 
        break; 
       } 
      } 

      if(found == false) 
       cout << "Unknown host \"" << extract << "\"" << endl; 
    } 


    return 0; 
} 

输出:

Enter url: https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e 
Tx-Id: a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e 
+0

感谢@Bobface,但我想功能可以使用它的每个服务自己的doman我不需要收集域功能 – Ngan

+0

然后使用正则表达式搜索64个字符的字符串。 – Bobface