This commit is contained in:
blackjok3r
2018-10-25 00:52:33 +08:00
parent f8dbd08dc8
commit b52da6b921

View File

@@ -321,8 +321,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp)
return chainActive.Height(); return chainActive.Height();
*/ */
UniValue result(UniValue::VARR); UniValue result(UniValue::VARR);
unsigned int lastseqid = 0; unsigned int firstdeqid = lastseqid = i = did1 = 0;
unsigned int i = 0; static std::string streamid,firsttxid;
std::string blockdata;
fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size());
// Iif block tx size is > 2 then we can do this // Iif block tx size is > 2 then we can do this
if ( block.vtx.size() > 2 ) { if ( block.vtx.size() > 2 ) {
@@ -334,26 +335,37 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp)
fprintf(stderr, "skipped tx number: %d \n",i); fprintf(stderr, "skipped tx number: %d \n",i);
} else { } else {
fprintf(stderr, "added tx number: %d \n",i); fprintf(stderr, "added tx number: %d \n",i);
UniValue objTx(UniValue::VOBJ);
std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end());
if ( opretstr.size() > 81 ) { if ( opretstr.size() > 81 ) {
std::string idstr = opretstr.substr (8,64); // stream ID or txid std::string idstr = opretstr.substr (8,64); // stream ID or txid
std::string seqidstr = opretstr.substr (72,8); // sequence ID std::string seqidstr = opretstr.substr (72,8); // sequence ID
std::string data = opretstr.substr (80); // data chunk
unsigned int seqid; unsigned int seqid;
std::stringstream ss; std::stringstream ss;
ss << std::hex << seqidstr; ss << std::hex << seqidstr;
ss >> seqid; ss >> seqid;
std::string data = opretstr.substr (80); // data chunk if ( seqid == 1 ) {
objTx.push_back(Pair("idstr", idstr)); streamid = idstr;
objTx.push_back(Pair("seqid", (int)seqid)); }
objTx.push_back(Pair("data", data)); if ( seqid == (lastseqid + 1 )) {
result.push_back(objTx); blockdata.append(data);
}
if ( did1 == 0 ) {
firstdeqid = seqid;
did1 = 1;
}
lastseqid = seqid;
} }
// function here to extract seqid from first and last TX // function here to extract seqid from first and last TX
// we an push the data or not depending on input from RPC. // we an push the data or not depending on input from RPC.
} }
i = i + 1; i = i + 1;
} }
result.push_back(Pair("streamid", streamid));
result.push_back(Pair("firstseqid", (int)firstseqid));
result.push_back(Pair("lastseqid", (int)lastseqid));
result.push_back(Pair("data", blockdata));
result.push_back(objTx);
} else { } else {
result.push_back(Pair("error","there are no TX in this block.")); result.push_back(Pair("error","there are no TX in this block."));
} }