如何从任何服务检索比特币交易的哈希码。 E.g。
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个字符。 Tx-Codes总是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