leveldb work.

This commit is contained in:
Christopher Jeffrey 2014-12-01 19:57:15 -08:00
parent 4459bf5b9f
commit 5ad347c892
1 changed files with 90 additions and 47 deletions

View File

@ -187,7 +187,7 @@ using namespace v8;
#define EMPTY ("\\x01") #define EMPTY ("\\x01")
// LevelDB options // LevelDB options
#define USE_LDB_ADDR 0 #define USE_LDB_ADDR 1
/** /**
* Node.js Exposed Function Templates * Node.js Exposed Function Templates
@ -5886,29 +5886,35 @@ read_addr(const std::string addr) {
while (pcursor->Valid()) { while (pcursor->Valid()) {
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
char *k_debug = NULL; char *k_debug = NULL;
leveldb::Slice lastKey = pcursor->key();
leveldb::Slice lastVal = pcursor->value();
try { try {
leveldb::Slice slKey = pcursor->key(); leveldb::Slice slKey = pcursor->key();
CDataStream ssKey(slKey.data(), slKey.data() + slKey.size(), SER_DISK, CLIENT_VERSION); CDataStream ssKey(slKey.data(), slKey.data() + slKey.size(), SER_DISK, CLIENT_VERSION);
char type; char type;
ssKey >> type; ssKey >> type;
//if (slKey.ToString().c_str()[0] == 'b') {
if (type == 'b') { if (type == 'b') {
leveldb::Slice slValue = pcursor->value(); leveldb::Slice slValue = pcursor->value();
// correct:
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION); CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
//CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_NETWORK, PROTOCOL_VERSION);
//std::vector<unsigned char> blockData(ParseHex(slValue.ToString()));
//CDataStream ssValue(blockData, SER_DISK, CLIENT_VERSION);
//CDataStream ssValue(blockData, SER_NETWORK, PROTOCOL_VERSION);
uint256 blockhash; uint256 blockhash;
ssKey >> blockhash; ssKey >> blockhash;
CBlockHeader header;
ssValue >> header;
CDiskBlockPos blockPos;
ssValue >> blockPos;
CDiskBlockPos undoPos;
ssValue >> undoPos;
CBlock cblock; CBlock cblock;
ssValue >> cblock; if (ReadBlockFromDisk(cblock, blockPos)) {
//uint256 blockhash = cblock.GetHash();
k_debug = strdup(blockhash.GetHex().c_str()); k_debug = strdup(blockhash.GetHex().c_str());
BOOST_FOREACH(const CTransaction& ctx, cblock.vtx) { BOOST_FOREACH(const CTransaction& ctx, cblock.vtx) {
BOOST_FOREACH(const CTxIn& txin, ctx.vin) { BOOST_FOREACH(const CTxIn& txin, ctx.vin) {
if (txin.scriptSig.ToString() != expectedScriptSig.ToString()) { if (txin.scriptSig.ToString() != expectedScriptSig.ToString()) {
@ -5960,6 +5966,31 @@ read_addr(const std::string addr) {
} }
} }
} }
}
if (type == 't') {
leveldb::Slice slValue = pcursor->value();
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
uint256 txhash;
ssKey >> txhash;
k_debug = strdup(txhash.GetHex().c_str());
CDiskBlockPos blockPos;
ssValue >> blockPos.nFile;
ssValue >> blockPos.nPos;
CDiskTxPos txPos;
//ssValue >> txPos.nFile;
//ssValue >> txPos.nPos;
txPos.nFile = blockPos.nFile;
txPos.nPos = blockPos.nPos;
ssValue >> txPos.nTxOffset;
}
found: found:
if (k_debug != NULL) { if (k_debug != NULL) {
free(k_debug); free(k_debug);
@ -5967,6 +5998,18 @@ found:
k_debug = NULL; k_debug = NULL;
pcursor->Next(); pcursor->Next();
} catch (std::exception &e) { } catch (std::exception &e) {
//CDataStream ssk(SER_NETWORK, PROTOCOL_VERSION);
//ssk << lastKey.ToString();
//std::string lastKeyHex = HexStr(ssk.begin(), ssk.end());
std::string lastKeyHex = HexStr(lastKey.ToString());
//CDataStream ssv(SER_NETWORK, PROTOCOL_VERSION);
//ssv << lastVal.ToString();
//std::string lastValHex = HexStr(ssv.begin(), ssv.end());
std::string lastValHex = HexStr(lastVal.ToString());
head->err_msg = std::string(lastKeyHex + std::string(": ") + lastValHex);
//head->err_msg = std::string( //head->err_msg = std::string(
// e.what() // e.what()
// + std::string(" : Deserialize or I/O error. Key: ") // + std::string(" : Deserialize or I/O error. Key: ")
@ -5978,11 +6021,11 @@ found:
} }
k_debug = NULL; k_debug = NULL;
//delete pcursor; delete pcursor;
//return head; return head;
pcursor->Next(); //pcursor->Next();
continue; //continue;
} }
} }