Skip to content

Commit

Permalink
Normalize variable names of DB based classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dexX7 committed Apr 28, 2015
1 parent e9118fe commit 101c543
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 68 deletions.
58 changes: 29 additions & 29 deletions src/mastercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ static void clear_all_state() {
my_offers.clear();
my_accepts.clear();
my_crowds.clear();
_my_sps->clear();
_my_sps->Clear();
exodus_prev = 0;
}

Expand Down Expand Up @@ -3461,12 +3461,12 @@ unsigned int n_found = 0;
// MPSTOList here
std::string CMPSTOList::getMySTOReceipts(string filterAddress)
{
if (!sdb) return "";
if (!pdb) return "";
string mySTOReceipts = "";

Slice skey, svalue;
readoptions.fill_cache = false;
Iterator* it = sdb->NewIterator(readoptions);
Iterator* it = pdb->NewIterator(readoptions);
for(it->SeekToFirst(); it->Valid(); it->Next())
{
skey = it->key();
Expand Down Expand Up @@ -3497,7 +3497,7 @@ std::string CMPSTOList::getMySTOReceipts(string filterAddress)

void CMPSTOList::getRecipients(const uint256 txid, string filterAddress, Array *recipientArray, uint64_t *total, uint64_t *stoFee)
{
if (!sdb) return;
if (!pdb) return;

bool filter = true; //default
bool filterByWallet = true; //default
Expand All @@ -3515,7 +3515,7 @@ void CMPSTOList::getRecipients(const uint256 txid, string filterAddress, Array *

Slice skey, svalue;
readoptions.fill_cache = false;
Iterator* it = sdb->NewIterator(readoptions);
Iterator* it = pdb->NewIterator(readoptions);
for(it->SeekToFirst(); it->Valid(); it->Next())
{
skey = it->key();
Expand Down Expand Up @@ -3581,10 +3581,10 @@ void CMPSTOList::getRecipients(const uint256 txid, string filterAddress, Array *

bool CMPSTOList::exists(string address)
{
if (!sdb) return false;
if (!pdb) return false;

string strValue;
Status status = sdb->Get(readoptions, address, &strValue);
Status status = pdb->Get(readoptions, address, &strValue);

if (!status.ok())
{
Expand All @@ -3596,15 +3596,15 @@ bool CMPSTOList::exists(string address)

void CMPSTOList::recordSTOReceive(string address, const uint256 &txid, int nBlock, unsigned int propertyId, uint64_t amount)
{
if (!sdb) return;
if (!pdb) return;

bool addressExists = s_stolistdb->exists(address);
if (addressExists)
{
//retrieve existing record
std::vector<std::string> vstr;
string strValue;
Status status = sdb->Get(readoptions, address, &strValue);
Status status = pdb->Get(readoptions, address, &strValue);
if (status.ok())
{
// add details to record
Expand All @@ -3617,9 +3617,9 @@ void CMPSTOList::recordSTOReceive(string address, const uint256 &txid, int nBloc
strValue += newValue;
// write updated record
Status status;
if (sdb)
if (pdb)
{
status = sdb->Put(writeoptions, key, strValue);
status = pdb->Put(writeoptions, key, strValue);
file_log("STODBDEBUG : %s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString().c_str(), __LINE__, __FILE__);
}
}
Expand All @@ -3629,9 +3629,9 @@ void CMPSTOList::recordSTOReceive(string address, const uint256 &txid, int nBloc
const string key = address;
const string value = strprintf("%s:%d:%u:%lu,", txid.ToString(), nBlock, propertyId, amount);
Status status;
if (sdb)
if (pdb)
{
status = sdb->Put(writeoptions, key, value);
status = pdb->Put(writeoptions, key, value);
file_log("STODBDEBUG : %s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString().c_str(), __LINE__, __FILE__);
}
}
Expand All @@ -3644,7 +3644,7 @@ void CMPSTOList::printAll()

readoptions.fill_cache = false;

Iterator* it = sdb->NewIterator(readoptions);
Iterator* it = pdb->NewIterator(readoptions);

for(it->SeekToFirst(); it->Valid(); it->Next())
{
Expand All @@ -3659,7 +3659,7 @@ void CMPSTOList::printAll()

void CMPSTOList::printStats()
{
file_log("CMPSTOList stats: tWritten= %d , tRead= %d\n", sWritten, sRead);
file_log("CMPSTOList stats: tWritten= %d , tRead= %d\n", nWritten, nRead);
}

// delete any STO receipts after blockNum
Expand All @@ -3669,7 +3669,7 @@ int CMPSTOList::deleteAboveBlock(int blockNum)
unsigned int count = 0;
std::vector<std::string> vstr;
unsigned int n_found = 0;
leveldb::Iterator* it = sdb->NewIterator(iteroptions);
leveldb::Iterator* it = pdb->NewIterator(iteroptions);
for(it->SeekToFirst(); it->Valid(); it->Next())
{
skey = it->key();
Expand All @@ -3696,9 +3696,9 @@ int CMPSTOList::deleteAboveBlock(int blockNum)
const string key = address;
// write updated record
Status status;
if (sdb)
if (pdb)
{
status = sdb->Put(writeoptions, key, newValue);
status = pdb->Put(writeoptions, key, newValue);
file_log("DEBUG STO - rewriting STO data after reorg\n");
file_log("STODBDEBUG : %s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString().c_str(), __LINE__, __FILE__);
}
Expand All @@ -3715,12 +3715,12 @@ int CMPSTOList::deleteAboveBlock(int blockNum)
// MPTradeList here
bool CMPTradeList::getMatchingTrades(const uint256 txid, unsigned int propertyId, Array *tradeArray, uint64_t *totalSold, uint64_t *totalBought)
{
if (!tdb) return false;
if (!pdb) return false;
leveldb::Slice skey, svalue;
unsigned int count = 0;
std::vector<std::string> vstr;
string txidStr = txid.ToString();
leveldb::Iterator* it = tdb->NewIterator(iteroptions);
leveldb::Iterator* it = pdb->NewIterator(iteroptions);
for(it->SeekToFirst(); it->Valid(); it->Next())
{
skey = it->key();
Expand Down Expand Up @@ -3805,14 +3805,14 @@ bool CMPTradeList::getMatchingTrades(const uint256 txid, unsigned int propertyId

void CMPTradeList::recordTrade(const uint256 txid1, const uint256 txid2, string address1, string address2, unsigned int prop1, unsigned int prop2, uint64_t amount1, uint64_t amount2, int blockNum)
{
if (!tdb) return;
if (!pdb) return;
const string key = txid1.ToString() + "+" + txid2.ToString();
const string value = strprintf("%s:%s:%u:%u:%lu:%lu:%d", address1, address2, prop1, prop2, amount1, amount2, blockNum);
Status status;
if (tdb)
if (pdb)
{
status = tdb->Put(writeoptions, key, value);
++tWritten;
status = pdb->Put(writeoptions, key, value);
++nWritten;
if (msc_debug_tradedb) file_log("%s(): %s\n", __FUNCTION__, status.ToString().c_str());
}
}
Expand All @@ -3825,7 +3825,7 @@ int CMPTradeList::deleteAboveBlock(int blockNum)
std::vector<std::string> vstr;
int block;
unsigned int n_found = 0;
leveldb::Iterator* it = tdb->NewIterator(iteroptions);
leveldb::Iterator* it = pdb->NewIterator(iteroptions);
for(it->SeekToFirst(); it->Valid(); it->Next())
{
skey = it->key();
Expand All @@ -3842,7 +3842,7 @@ int CMPTradeList::deleteAboveBlock(int blockNum)
{
++n_found;
file_log("%s() DELETING FROM TRADEDB: %s=%s\n", __FUNCTION__, skey.ToString().c_str(), svalue.ToString().c_str());
tdb->Delete(writeoptions, skey);
pdb->Delete(writeoptions, skey);
}
}
}
Expand All @@ -3856,15 +3856,15 @@ int CMPTradeList::deleteAboveBlock(int blockNum)

void CMPTradeList::printStats()
{
file_log("CMPTradeList stats: tWritten= %d , tRead= %d\n", tWritten, tRead);
file_log("CMPTradeList stats: tWritten= %d , tRead= %d\n", nWritten, nRead);
}

int CMPTradeList::getMPTradeCountTotal()
{
int count = 0;
Slice skey, svalue;
readoptions.fill_cache = false;
Iterator* it = tdb->NewIterator(readoptions);
Iterator* it = pdb->NewIterator(readoptions);
for(it->SeekToFirst(); it->Valid(); it->Next())
{
++count;
Expand All @@ -3880,7 +3880,7 @@ void CMPTradeList::printAll()

readoptions.fill_cache = false;

Iterator* it = tdb->NewIterator(readoptions);
Iterator* it = pdb->NewIterator(readoptions);

for(it->SeekToFirst(); it->Valid(); it->Next())
{
Expand Down
28 changes: 14 additions & 14 deletions src/mastercore.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,28 +384,28 @@ class CMPSTOList
leveldb::ReadOptions iteroptions;
leveldb::WriteOptions writeoptions;
leveldb::WriteOptions syncoptions;
leveldb::DB *sdb;
leveldb::DB *pdb;
// statistics
unsigned int sWritten;
unsigned int sRead;
unsigned int nWritten;
unsigned int nRead;

public:
CMPSTOList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe):sWritten(0),sRead(0)
CMPSTOList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe):nWritten(0),nRead(0)
{
options.paranoid_checks = true;
options.create_if_missing = true;
readoptions.verify_checksums = true;
iteroptions.verify_checksums = true;
iteroptions.fill_cache = false;
syncoptions.sync = true;
leveldb::Status status = leveldb::DB::Open(options, path.string(), &sdb);
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
PrintToConsole("Loading send-to-owners database: %s\n", status.ToString());
}

~CMPSTOList()
{
delete sdb;
sdb = NULL;
delete pdb;
pdb = NULL;
}

void getRecipients(const uint256 txid, string filterAddress, Array *recipientArray, uint64_t *total, uint64_t *stoFee);
Expand All @@ -427,28 +427,28 @@ class CMPTradeList
leveldb::ReadOptions iteroptions;
leveldb::WriteOptions writeoptions;
leveldb::WriteOptions syncoptions;
leveldb::DB *tdb;
leveldb::DB *pdb;
// statistics
unsigned int tWritten;
unsigned int tRead;
unsigned int nWritten;
unsigned int nRead;

public:
CMPTradeList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe):tWritten(0),tRead(0)
CMPTradeList(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory, bool fWipe):nWritten(0),nRead(0)
{
options.paranoid_checks = true;
options.create_if_missing = true;
readoptions.verify_checksums = true;
iteroptions.verify_checksums = true;
iteroptions.fill_cache = false;
syncoptions.sync = true;
leveldb::Status status = leveldb::DB::Open(options, path.string(), &tdb);
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
PrintToConsole("Loading trades database: %s\n", status.ToString());
}

~CMPTradeList()
{
delete tdb;
tdb = NULL;
delete pdb;
pdb = NULL;
}

void recordTrade(const uint256 txid1, const uint256 txid2, string address1, string address2, unsigned int prop1, unsigned int prop2, uint64_t amount1, uint64_t amount2, int blockNum);
Expand Down
22 changes: 11 additions & 11 deletions src/mastercore_sp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ unsigned int CMPSPInfo::updateSP(unsigned int propertyID, Entry const &info)
writeOptions.sync = true;

// if a value exists move it to the old key
if (false == pDb->Get(readOpts, spKey, &spPrevValue).IsNotFound()) {
if (false == pdb->Get(readOpts, spKey, &spPrevValue).IsNotFound()) {
commitBatch.Put(spPrevKey, spPrevValue);
}
commitBatch.Put(spKey, spValue);
pDb->Write(writeOptions, &commitBatch);
pdb->Write(writeOptions, &commitBatch);

file_log("Updated LevelDB with SP data successfully\n");
return res;
Expand Down Expand Up @@ -100,9 +100,9 @@ unsigned int CMPSPInfo::putSP(unsigned char ecosystem, Entry const &info)
string existingEntry;
leveldb::ReadOptions readOpts;
readOpts.fill_cache = true;
if (false == pDb->Get(readOpts, spKey, &existingEntry).IsNotFound() && false == boost::equals(spValue, existingEntry)) {
if (false == pdb->Get(readOpts, spKey, &existingEntry).IsNotFound() && false == boost::equals(spValue, existingEntry)) {
file_log("%s WRITING SP %d TO LEVELDB WHEN A DIFFERENT SP ALREADY EXISTS FOR THAT ID!!!\n", __FUNCTION__, res);
} else if (false == pDb->Get(readOpts, txIndexKey, &existingEntry).IsNotFound() && false == boost::equals(txValue, existingEntry)) {
} else if (false == pdb->Get(readOpts, txIndexKey, &existingEntry).IsNotFound() && false == boost::equals(txValue, existingEntry)) {
file_log("%s WRITING INDEX TXID %s : SP %d IS OVERWRITING A DIFFERENT VALUE!!!\n", __FUNCTION__, info.txid.ToString().c_str(), res);
}

Expand All @@ -114,7 +114,7 @@ unsigned int CMPSPInfo::putSP(unsigned char ecosystem, Entry const &info)
commitBatch.Put(spKey, spValue);
commitBatch.Put(txIndexKey, txValue);

pDb->Write(writeOptions, &commitBatch);
pdb->Write(writeOptions, &commitBatch);
return res;
}

Expand All @@ -135,7 +135,7 @@ bool CMPSPInfo::getSP(unsigned int spid, Entry &info)

string spKey = (boost::format(FORMAT_BOOST_SPKEY) % spid).str();
string spInfoStr;
if (false == pDb->Get(readOpts, spKey, &spInfoStr).ok()) {
if (false == pdb->Get(readOpts, spKey, &spInfoStr).ok()) {
return false;
}

Expand All @@ -162,7 +162,7 @@ bool CMPSPInfo::hasSP(unsigned int spid)
readOpts.fill_cache = true;

string spKey = (boost::format(FORMAT_BOOST_SPKEY) % spid).str();
leveldb::Iterator *iter = pDb->NewIterator(readOpts);
leveldb::Iterator *iter = pdb->NewIterator(readOpts);
iter->Seek(spKey);
bool res = (iter->Valid() && iter->key().compare(spKey) == 0);
// clean up the iterator
Expand All @@ -179,7 +179,7 @@ unsigned int CMPSPInfo::findSPByTX(uint256 const &txid)

string txIndexKey = (boost::format(FORMAT_BOOST_TXINDEXKEY) % txid.ToString() ).str();
string spidStr;
if (pDb->Get(readOpts, txIndexKey, &spidStr).ok()) {
if (pdb->Get(readOpts, txIndexKey, &spidStr).ok()) {
res = boost::lexical_cast<unsigned int>(spidStr);
}

Expand All @@ -194,7 +194,7 @@ int CMPSPInfo::popBlock(uint256 const &block_hash)

leveldb::ReadOptions readOpts;
readOpts.fill_cache = false;
leveldb::Iterator *iter = pDb->NewIterator(readOpts);
leveldb::Iterator *iter = pdb->NewIterator(readOpts);
for (iter->Seek("sp-"); iter->Valid() && iter->key().starts_with("sp-"); iter->Next()) {
// parse the encoded json, failing if it doesnt parse or is an object
Value spInfoVal;
Expand All @@ -217,7 +217,7 @@ int CMPSPInfo::popBlock(uint256 const &block_hash)
string spPrevKey = (boost::format("blk-%s:sp-%d") % info.update_block.ToString() % propertyID).str();
string spPrevValue;

if (false == pDb->Get(readOpts, spPrevKey, &spPrevValue).IsNotFound()) {
if (false == pdb->Get(readOpts, spPrevKey, &spPrevValue).IsNotFound()) {
// copy the prev state to the current state and delete the old state
commitBatch.Put(iter->key(), spPrevValue);
commitBatch.Delete(spPrevKey);
Expand All @@ -242,7 +242,7 @@ int CMPSPInfo::popBlock(uint256 const &block_hash)
leveldb::WriteOptions writeOptions;
writeOptions.sync = true;

pDb->Write(writeOptions, &commitBatch);
pdb->Write(writeOptions, &commitBatch);

if (res < 0) {
return res;
Expand Down
Loading

0 comments on commit 101c543

Please sign in to comment.