Created
November 27, 2014 12:13
-
-
Save bitkevin/452ed06239e0b3253337 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp | |
index a303b5d..7411d36 100644 | |
--- a/src/rpcblockchain.cpp | |
+++ b/src/rpcblockchain.cpp | |
@@ -465,3 +465,49 @@ Value getblockchaininfo(const Array& params, bool fHelp) | |
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); | |
return obj; | |
} | |
+ | |
+ | |
+Value gettinyblocktxs(const Array& params, bool fHelp) | |
+{ | |
+ if (fHelp || params.size() < 1 || params.size() > 3) | |
+ throw runtime_error("gettinyblocktxs \"blockhash\" \"txIdBytes\" \"txIds\""); | |
+ | |
+ std::string strHash = params[0].get_str(); | |
+ int txIdLen = atoi(params[1].get_str()) * 2; | |
+ std::string txIdsStr = params[2].get_str(); | |
+ uint256 hash(strHash); | |
+ | |
+ std::set<std::string> tinyIds; | |
+ for (int i = 0; i < (int)txIdsStr.length() / txIdLen; i++) { | |
+ tinyIds.insert(txIdsStr.substr(i * txIdLen, txIdLen)); | |
+ } | |
+ | |
+ if (mapBlockIndex.count(hash) != 0) | |
+ throw runtime_error("block already exists"); | |
+ | |
+ vector<uint256> vtxid; | |
+ mempool.queryHashes(vtxid); | |
+ | |
+ Array txs; | |
+ BOOST_FOREACH(const uint256& hash, vtxid) | |
+ { | |
+ std::string tinyId = hash.ToString().substr(0, txIdLen); | |
+ if (tinyIds.count(tinyId) == 0) { | |
+ continue; | |
+ } | |
+ CTransaction tx; | |
+ uint256 hashBlock = 0; | |
+ if (!GetTransaction(hash, tx, hashBlock, true)) | |
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction (tangpool)"); | |
+ | |
+ CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); | |
+ ssTx << tx; | |
+ | |
+ Object in; | |
+ in.push_back(Pair("hash", hash.ToString())); | |
+ in.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end()))); | |
+ | |
+ txs.push_back(in); | |
+ } | |
+ return txs; | |
+} | |
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp | |
index f43acf4..140ce87 100644 | |
--- a/src/rpcserver.cpp | |
+++ b/src/rpcserver.cpp | |
@@ -248,6 +248,7 @@ static const CRPCCommand vRPCCommands[] = | |
{ "gettxout", &gettxout, true, false, false }, | |
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false, false }, | |
{ "verifychain", &verifychain, true, false, false }, | |
+ { "gettinyblocktxs", &gettinyblocktxs, true, false, false }, | |
/* Mining */ | |
{ "getblocktemplate", &getblocktemplate, true, false, false }, | |
diff --git a/src/rpcserver.h b/src/rpcserver.h | |
index 1092c69..66eb5af 100644 | |
--- a/src/rpcserver.h | |
+++ b/src/rpcserver.h | |
@@ -187,5 +187,6 @@ extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp) | |
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); | |
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); | |
extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); | |
+extern json_spirit::Value gettinyblocktxs(const json_spirit::Array& params, bool fHelp); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment