Created
February 26, 2015 20:56
-
-
Save dexX7/f6f6f15ddac82ce0e14a to your computer and use it in GitHub Desktop.
Block and transaction position
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
| Value BlockPositionToJSON(const uint256& hash) | |
| { | |
| CTransaction tx; | |
| uint256 hashBlock = 0; | |
| if (!GetTransaction(hash, tx, hashBlock, true)) | |
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); | |
| int nHeight = 0; | |
| int nPosition = -1; | |
| if (hashBlock != 0) { | |
| map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock); | |
| if (mi != mapBlockIndex.end() && (*mi).second) { | |
| CBlockIndex* pindex = (*mi).second; | |
| if (chainActive.Contains(pindex)) | |
| nHeight = pindex->nHeight; | |
| else | |
| nHeight = -1; | |
| CBlock block; | |
| if (ReadBlockFromDisk(block, pindex)) | |
| nPosition = std::find(block.vtx.begin(), block.vtx.end(), tx) - block.vtx.begin(); | |
| } | |
| } | |
| Object result; | |
| result.push_back(Pair("txid", hash.GetHex())); | |
| result.push_back(Pair("blockhash", hashBlock.GetHex())); | |
| result.push_back(Pair("blockheight", nHeight)); | |
| result.push_back(Pair("position", nPosition)); | |
| return result; | |
| } | |
| Value TxPositionToJSON(const uint256& hash) | |
| { | |
| CDiskTxPos position; | |
| int nFile = -1; | |
| unsigned int nPos = 0; | |
| unsigned int nTxOffset = 0; | |
| if (pblocktree->ReadTxIndex(hash, position)) { | |
| nTxOffset = position.nTxOffset; | |
| nFile = position.nFile; | |
| nPos = position.nPos; | |
| } | |
| Object result; | |
| result.push_back(Pair("txid", hash.GetHex())); | |
| result.push_back(Pair("nFile", nFile)); | |
| result.push_back(Pair("nPos", (uint64_t)nPos)); | |
| result.push_back(Pair("nTxOffset", (uint64_t)nTxOffset)); | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment