mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Separate the databases, give them their own connections and locks.
This commit is contained in:
@@ -2,13 +2,11 @@
|
||||
#include "Application.h"
|
||||
#include "Conversion.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void UniqueNodeList::addNode(uint160& hanko, vector<unsigned char>& publicKey)
|
||||
void UniqueNodeList::addNode(uint160& hanko, std::vector<unsigned char>& publicKey)
|
||||
{
|
||||
Database* db=theApp->getDB();
|
||||
string sql="INSERT INTO UNL (Hanko,PubKey) values (";
|
||||
string hashStr;
|
||||
Database* db=theApp->getNetNodeDB()->getDB();
|
||||
std::string sql="INSERT INTO UNL (Hanko,PubKey) values (";
|
||||
std::string hashStr;
|
||||
db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr);
|
||||
sql.append(hashStr);
|
||||
sql.append(",");
|
||||
@@ -16,19 +14,19 @@ void UniqueNodeList::addNode(uint160& hanko, vector<unsigned char>& publicKey)
|
||||
sql.append(hashStr);
|
||||
sql.append(")");
|
||||
|
||||
ScopedLock sl(theApp->getDBLock());
|
||||
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
|
||||
db->executeSQL(sql.c_str());
|
||||
}
|
||||
|
||||
void UniqueNodeList::removeNode(uint160& hanko)
|
||||
{
|
||||
Database* db=theApp->getDB();
|
||||
string sql="DELETE FROM UNL where hanko=";
|
||||
string hashStr;
|
||||
Database* db=theApp->getNetNodeDB()->getDB();
|
||||
std::string sql="DELETE FROM UNL where hanko=";
|
||||
std::string hashStr;
|
||||
db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr);
|
||||
sql.append(hashStr);
|
||||
|
||||
ScopedLock sl(theApp->getDBLock());
|
||||
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
|
||||
db->executeSQL(sql.c_str());
|
||||
}
|
||||
|
||||
@@ -36,13 +34,13 @@ void UniqueNodeList::removeNode(uint160& hanko)
|
||||
#if 0
|
||||
int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
||||
{
|
||||
Database* db=theApp->getDB();
|
||||
string sql="SELECT pubkey from UNL where hanko=";
|
||||
string hashStr;
|
||||
Database* db=theApp->getNetNodeDB()->getDB();
|
||||
std::string sql="SELECT pubkey from UNL where hanko=";
|
||||
std::string hashStr;
|
||||
db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr);
|
||||
sql.append(hashStr);
|
||||
|
||||
ScopedLock sl(theApp->getDBLock());
|
||||
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
|
||||
if( db->executeSQL(sql.c_str()) )
|
||||
{
|
||||
if(db->startIterRows() && db->getNextRow())
|
||||
@@ -52,11 +50,8 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
||||
// TODO: check that the public key makes the correct signature of the validation
|
||||
db->endIterRows();
|
||||
return(1);
|
||||
}else
|
||||
{
|
||||
db->endIterRows();
|
||||
|
||||
}
|
||||
else db->endIterRows();
|
||||
}
|
||||
return(0); // not on our list
|
||||
}
|
||||
@@ -64,10 +59,10 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
||||
|
||||
void UniqueNodeList::dumpUNL(std::string& retStr)
|
||||
{
|
||||
Database* db=theApp->getDB();
|
||||
string sql="SELECT * FROM UNL";
|
||||
Database* db=theApp->getNetNodeDB()->getDB();
|
||||
std::string sql="SELECT * FROM UNL";
|
||||
|
||||
ScopedLock sl(theApp->getDBLock());
|
||||
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
|
||||
if( db->executeSQL(sql.c_str()) )
|
||||
{
|
||||
db->startIterRows();
|
||||
@@ -75,7 +70,7 @@ void UniqueNodeList::dumpUNL(std::string& retStr)
|
||||
{
|
||||
uint160 hanko;
|
||||
int size=db->getBinary("Hanko", hanko.begin(), hanko.GetSerializeSize());
|
||||
string tstr;
|
||||
std::string tstr;
|
||||
u160ToHuman(hanko, tstr);
|
||||
|
||||
retStr.append(tstr);
|
||||
|
||||
Reference in New Issue
Block a user