src/omnicore/dbstolist.cpp
/**
 * This function deletes records of STO receivers above/equal to a specific block from the STO database.
 *
 * Returns the number of records changed.
 */
This function deletes records of STO receivers above/equal to a specific block from the STO database.
Returns the number of records changed.
This function deletes records of STO receivers above / equal to a specific block from the STO database . Returns the number of records changed .
int CMPSTOList::deleteAboveBlock(int blockNum)
{
    unsigned int n_found = 0;
    std::vector<std::string> vecSTORecords;
    leveldb::Iterator* it = NewIterator();
    for (it->SeekToFirst(); it->Valid(); it->Next()) {
        std::string newValue;
        std::string oldValue = it->value().ToString();
        bool needsUpdate = false;
        boost::split(vecSTORecords, oldValue, boost::is_any_of(","), boost::token_compress_on);
        for (uint32_t i = 0; i < vecSTORecords.size(); i++) {
            std::vector<std::string> vecSTORecordFields;
            boost::split(vecSTORecordFields, vecSTORecords[i], boost::is_any_of(":"), boost::token_compress_on);
            if (4 != vecSTORecordFields.size()) continue;
            if (atoi(vecSTORecordFields[1]) < blockNum) {
                newValue += vecSTORecords[i].append(","); 
            } else {
                needsUpdate = true;
            }
        }
        if (needsUpdate) { 
            ++n_found;
            leveldb::Status status = pdb->Put(writeoptions, it->key().ToString(), newValue);
            PrintToLog("DEBUG STO - rewriting STO data after reorg\n");
            PrintToLog("STODBDEBUG : %s(): %s, line %d, file: %s\n", __FUNCTION__, status.ToString(), __LINE__, __FILE__);
        }
    }
    PrintToLog("%s(%d); stodb updated records= %d\n", __FUNCTION__, blockNum, n_found);
    delete it;
    return (n_found);
}
int CMPSTOList :: deleteAboveBlock ( int blockNum ) { unsigned int n_found = 0 ; std :: vector < std :: string > vecSTORecords ; leveldb :: Iterator * it = NewIterator ( ) ; for ( it -> SeekToFirst ( ) ; it -> Valid ( ) ; it -> Next ( ) ) { std :: string newValue ; std :: string oldValue = it -> value ( ) . ToString ( ) ; bool needsUpdate = false ; boost :: split ( vecSTORecords , oldValue , boost :: is_any_of ( " " ) , boost :: token_compress_on ) ; for ( uint32_t i = 0 ; i < vecSTORecords . size ( ) ; i ++ ) { std :: vector < std :: string > vecSTORecordFields ; boost :: split ( vecSTORecordFields , vecSTORecords [ i ] , boost :: is_any_of ( " " ) , boost :: token_compress_on ) ; if ( 4 != vecSTORecordFields . size ( ) ) continue ; if ( atoi ( vecSTORecordFields [ 1 ] ) < blockNum ) { newValue += vecSTORecords [ i ] . append ( " " ) ; } else { needsUpdate = true ; } } if ( needsUpdate ) { ++ n_found ; leveldb :: Status status = pdb -> Put ( writeoptions , it -> key ( ) . ToString ( ) , newValue ) ; PrintToLog ( " \n " ) ; PrintToLog ( " \n " , __FUNCTION__ , status . ToString ( ) , __LINE__ , __FILE__ ) ; } } PrintToLog ( " \n " , __FUNCTION__ , blockNum , n_found ) ; delete it ; return ( n_found ) ; }
This function deletes records of STO receivers above/equal to a specific block from the STO database.
This function deletes records of STO receivers above / equal to a specific block from the STO database .
// STO before the reorg, add data back to new value string // rewrite record with existing key and new value