My QT-Wallet DIY 3\# â€"â€" Watch Blockchain
-
Now, I need to search and export every blockchain information . I know that explorer.feathercoin.com can show blockchain ,but I need to export information and transaction to file. so I import them to oracle database or mySQL. Then blockchain is big data , If analyze all the information ,I may need hadoop 2.3.
I add a new class ToolsDialog, in toolsdialog.h and toolsdialog.cpp .
You can input blockhash or blockid ,show its information. Then you can export them to a text file.
First run : feathercoin-qt.exe -txindex=1 -reindex=1
After : feathercoin-qt.exe -txindex=1
-
I posted some of the main code, blockchain structure is very complex, they are divided into four parts.
void ToolsDialog::showBlock(const string& strHash,unsigned int iTxid) { string strBlockHash=strHash; if (isDigitString(tr(strBlockHash.c_str()))==true) { Array params(1); params[0]=atoi(strBlockHash.c_str()); Value vHash=getblockhash(params,0); strBlockHash=vHash.get_str().c_str(); } if ((iTxid>0)==false) { iTxid=0; } bool verbose=true; Array params(2); params[0]=strBlockHash; params[1]=verbose; Value strJson=getblock(params,false); const Object &obj = strJson.get_obj(); for (unsigned int i = 0; i < obj.size(); ++i) { const Pair& p = obj[i]; const string& name =p.name_; const Value& vvalue = p.value_; if (name =="hash"){ blockModel->setItem(0,0,new QStandardItem(tr(vvalue.get_str().c_str()))); } if (name =="confirmations"){ blockModel->setItem(0,1,new QStandardItem(tr("%1").arg(vvalue.get_int()))); } if (name =="size"){ blockModel->setItem(0,2,new QStandardItem(tr("%1").arg(vvalue.get_int()))); } if (name =="height"){ blockModel->setItem(0,3,new QStandardItem(tr("%1").arg(vvalue.get_int()))); } if (name =="version"){ blockModel->setItem(0,4,new QStandardItem(tr("%1").arg(vvalue.get_int()))); } if (name =="merkleroot"){ blockModel->setItem(0,5,new QStandardItem(tr(vvalue.get_str().c_str()))); } if (name =="tx"){ blockModel->setItem(0,6,new QStandardItem(tr("%1").arg(vvalue.get_array().size()))); const Array& params=vvalue.get_array(); txModel->setRowCount(params.size()); for (unsigned int t = 0; t < params.size(); ++t) { Array paramsTx(2); paramsTx[0]=params[t].get_str(); paramsTx[1]=1; Value strTxJson=getrawtransaction(paramsTx,false); const Object &objTx = strTxJson.get_obj(); for (unsigned int j = 0; j < objTx.size(); ++j) { const Pair& pTx = objTx[j]; const string& nameTx =pTx.name_; const Value& vvalueTx = pTx.value_; if (nameTx =="txid"){ txModel->setItem(t,0,new QStandardItem(tr(vvalueTx.get_str().c_str()))); } if (nameTx =="version"){ txModel->setItem(t,1,new QStandardItem(tr("%1").arg(vvalueTx.get_int()))); } if (nameTx =="locktime"){ txModel->setItem(t,2,new QStandardItem(tr("%1").arg(vvalueTx.get_int()))); } if (nameTx =="vin"){ txModel->setItem(t,3,new QStandardItem(tr("%1").arg(vvalueTx.get_array().size()))); if (t==iTxid){ const Array& paramsVin=vvalueTx.get_array(); txInModel->setRowCount(paramsVin.size()); for (unsigned int ti = 0; ti < paramsVin.size(); ++ti) { const Object &objInTx = paramsVin[ti].get_obj(); string strVinTxHash=""; int nVout=-1; for (unsigned int tir = 0; tir < objInTx.size(); ++tir) { const Pair& pInTx = objInTx[tir]; const string& nameInTx =pInTx.name_; const Value& vvalueInTx = pInTx.value_; if (nameInTx =="txid"){ txInModel->setItem(ti,0,new QStandardItem(vvalueInTx.get_str().c_str())); strVinTxHash=vvalueInTx.get_str().c_str(); } if (nameInTx =="vout"){ txInModel->setItem(ti,1,new QStandardItem(tr("%1").arg(vvalueInTx.get_int()))); nVout=vvalueInTx.get_int(); if ((strVinTxHash!="")&&(nVout>=0)) { Array paramsVoutTx(2); paramsVoutTx[0]=strVinTxHash; paramsVoutTx[1]=1; Value strVoutTxJson=getrawtransaction(paramsVoutTx,false); const Object &objVoutTx = strVoutTxJson.get_obj(); for (unsigned int j = 0; j < objVoutTx.size(); ++j) { const Pair& pTx2 = objVoutTx[j]; const string& nameTx2 =pTx2.name_; const Value& vvalueTx2 = pTx2.value_; if (nameTx2 =="vout"){ const Array& paramsVout2=vvalueTx2.get_array(); const Object &objOutTx2 = paramsVout2[nVout].get_obj(); for (unsigned int tvr = 0; tvr < objOutTx2.size(); ++tvr) { const Pair& pOutTx2 = objOutTx2[tvr]; const string& nameOutTx2 =pOutTx2.name_; const Value& vvalueOutTx2 = pOutTx2.value_; int nVout2=0; if (nameOutTx2 =="value"){ txInModel->setItem(ti,3,new QStandardItem(tr("%1").arg(vvalueOutTx2.get_real()))); } if (nameOutTx2 =="n"){ nVout2=vvalueOutTx2.get_int(); } if (nameOutTx2 =="scriptPubKey") { const Object &objscriptPubKey2 = vvalueOutTx2.get_obj(); for (unsigned int tvrk = 0; tvrk < objscriptPubKey2.size(); ++tvrk) { const Pair& pOutKey2 = objscriptPubKey2[tvrk]; const string& nameOutKey2 =pOutKey2.name_; const Value& vvalueOutKey2 = pOutKey2.value_; if (nameOutKey2 =="addresses"){ const Array& paramsVoutAddr2=vvalueOutKey2.get_array(); QString nameOutKeyAddr2 =""; for (unsigned int tvrka = 0; tvrka < paramsVoutAddr2.size(); ++tvrka) { nameOutKeyAddr2=nameOutKeyAddr2+tr(paramsVoutAddr2[0].get_str().c_str()); } txInModel->setItem(ti,2,new QStandardItem(nameOutKeyAddr2)); } } } } } } } } if (nameInTx =="coinbase"){ txInModel->setItem(ti,0,new QStandardItem(tr("Generation"))); } } } } } if (nameTx =="vout"){ txModel->setItem(t,4,new QStandardItem(tr("%1").arg(vvalueTx.get_array().size()))); //select TxID if (t==iTxid){ const Array& paramsVout=vvalueTx.get_array(); txOutModel->setRowCount(paramsVout.size()); for (unsigned int tv = 0; tv < paramsVout.size(); ++tv) { const Object &objOutTx = paramsVout[tv].get_obj(); for (unsigned int tvr = 0; tvr < objOutTx.size(); ++tvr) { const Pair& pOutTx = objOutTx[tvr]; const string& nameOutTx =pOutTx.name_; const Value& vvalueOutTx = pOutTx.value_; if (nameOutTx =="value"){ txOutModel->setItem(tv,1,new QStandardItem(tr("%1").arg(vvalueOutTx.get_real()))); } if (nameOutTx =="scriptPubKey"){ const Object &objscriptPubKey = vvalueOutTx.get_obj(); for (unsigned int tvrk = 0; tvrk < objscriptPubKey.size(); ++tvrk) { const Pair& pOutKey = objscriptPubKey[tvrk]; const string& nameOutKey =pOutKey.name_; const Value& vvalueOutKey = pOutKey.value_; if (nameOutKey =="addresses"){ const Array& paramsVoutAddr=vvalueOutKey.get_array(); QString nameOutKeyAddr =""; for (unsigned int tvrka = 0; tvrka < paramsVoutAddr.size(); ++tvrka) { nameOutKeyAddr=nameOutKeyAddr+tr(paramsVoutAddr[tvrka].get_str().c_str()); } txOutModel->setItem(tv,0,new QStandardItem(nameOutKeyAddr)); } } } } } } } if (nameTx =="confirmations"){ txModel->setItem(t,5,new QStandardItem(tr("%1").arg(vvalueTx.get_int()))); } if (nameTx =="time"){ txModel->setItem(t,6,new QStandardItem(tr("%1").arg(vvalueTx.get_int()))); } } } } if (name =="time"){ blockModel->setItem(0,7,new QStandardItem(tr("%1").arg(vvalue.get_int()))); } if (name =="nonce"){ blockModel->setItem(0,8,new QStandardItem(tr("%1").arg(vvalue.get_int()))); } if (name =="bits"){ blockModel->setItem(0,9,new QStandardItem(tr(vvalue.get_str().c_str()))); } if (name =="difficulty"){ blockModel->setItem(0,10,new QStandardItem(tr("%1").arg(vvalue.get_real()))); } if (name =="previousblockhash"){ blockModel->setItem(0,11,new QStandardItem(tr(vvalue.get_str().c_str()))); } if (name =="nextblockhash"){ blockModel->setItem(0,12,new QStandardItem(tr(vvalue.get_str().c_str()))); } } } void ToolsDialog::on_seekButton() { string strHash=ui->hashEdit->text().toStdString(); showBlock(strHash,0); }