mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
NewcoinAddress fixes and work towards unls.
This commit is contained in:
@@ -2,41 +2,42 @@
|
||||
#include "Application.h"
|
||||
#include "Conversion.h"
|
||||
|
||||
void UniqueNodeList::addNode(NewcoinAddress address,std::string comment)
|
||||
void UniqueNodeList::addNode(NewcoinAddress nodePublic, std::string strComment)
|
||||
{
|
||||
Database* db=theApp->getWalletDB()->getDB();
|
||||
|
||||
// void UniqueNodeList::addNode(uint160& hanko, std::vector<unsigned char>& publicKey,std::string comment)
|
||||
std::string strHanko = nodePublic.humanHanko();
|
||||
std::string strPublicKey = nodePublic.humanNodePublic();
|
||||
std::string strTmp;
|
||||
|
||||
std::string hanko = address.humanHanko();
|
||||
std::string publicKey = address.humanNodePublic();
|
||||
|
||||
std::string sql="INSERT INTO TrustedNodes (Hanko,PubKey,Comment) values (";
|
||||
std::string tmpStr;
|
||||
db->escape(reinterpret_cast<const unsigned char*>(hanko.c_str()), hanko.size(), tmpStr);
|
||||
sql.append(tmpStr);
|
||||
sql.append(",");
|
||||
db->escape(reinterpret_cast<const unsigned char*>(publicKey.c_str()), publicKey.size(), tmpStr);
|
||||
sql.append(tmpStr);
|
||||
sql.append(",");
|
||||
db->escape(reinterpret_cast<const unsigned char*>(comment.c_str()), comment.size(), tmpStr);
|
||||
sql.append(tmpStr);
|
||||
sql.append(")");
|
||||
std::string strSql="INSERT INTO TrustedNodes (Hanko,PublicKey,Comment) values (";
|
||||
db->escape(reinterpret_cast<const unsigned char*>(strHanko.c_str()), strHanko.size(), strTmp);
|
||||
strSql.append(strTmp);
|
||||
strSql.append(",");
|
||||
db->escape(reinterpret_cast<const unsigned char*>(strPublicKey.c_str()), strPublicKey.size(), strTmp);
|
||||
strSql.append(strTmp);
|
||||
strSql.append(",");
|
||||
db->escape(reinterpret_cast<const unsigned char*>(strComment.c_str()), strComment.size(), strTmp);
|
||||
strSql.append(strTmp);
|
||||
strSql.append(")");
|
||||
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
db->executeSQL(sql.c_str());
|
||||
db->executeSQL(strSql.c_str());
|
||||
}
|
||||
|
||||
void UniqueNodeList::removeNode(uint160& hanko)
|
||||
void UniqueNodeList::removeNode(NewcoinAddress hanko)
|
||||
{
|
||||
Database* db=theApp->getWalletDB()->getDB();
|
||||
std::string sql="DELETE FROM TrustedNodes where hanko=";
|
||||
std::string hashStr;
|
||||
db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr);
|
||||
sql.append(hashStr);
|
||||
|
||||
std::string strHanko = hanko.humanHanko();
|
||||
std::string strTmp;
|
||||
|
||||
std::string strSql = "DELETE FROM TrustedNodes where Hanko=";
|
||||
db->escape(reinterpret_cast<const unsigned char*>(strHanko.c_str()), strHanko.size(), strTmp);
|
||||
strSql.append(strTmp);
|
||||
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
db->executeSQL(sql.c_str());
|
||||
db->executeSQL(strSql.c_str());
|
||||
}
|
||||
|
||||
// 0- we don't care, 1- we care and is valid, 2-invalid signature
|
||||
@@ -44,13 +45,13 @@ void UniqueNodeList::removeNode(uint160& hanko)
|
||||
int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
||||
{
|
||||
Database* db=theApp->getWalletDB()->getDB();
|
||||
std::string sql="SELECT pubkey from TrustedNodes where hanko=";
|
||||
std::string strSql="SELECT pubkey from TrustedNodes where hanko=";
|
||||
std::string hashStr;
|
||||
db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr);
|
||||
sql.append(hashStr);
|
||||
strSql.append(hashStr);
|
||||
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
if( db->executeSQL(sql.c_str()) )
|
||||
if( db->executeSQL(strSql.c_str()) )
|
||||
{
|
||||
if(db->startIterRows() && db->getNextRow())
|
||||
{
|
||||
@@ -66,28 +67,41 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
||||
}
|
||||
#endif
|
||||
|
||||
void UniqueNodeList::dumpUNL(std::string& retStr)
|
||||
Json::Value UniqueNodeList::getUnlJson()
|
||||
{
|
||||
Database* db=theApp->getWalletDB()->getDB();
|
||||
std::string sql="SELECT * FROM TrustedNodes;";
|
||||
std::string strSql="SELECT * FROM TrustedNodes;";
|
||||
|
||||
retStr.append("hello\n");
|
||||
Json::Value ret(Json::arrayValue);
|
||||
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
if( db->executeSQL(sql.c_str()) )
|
||||
if( db->executeSQL(strSql.c_str()) )
|
||||
{
|
||||
db->startIterRows();
|
||||
while(db->getNextRow())
|
||||
bool more = db->startIterRows();
|
||||
while (more)
|
||||
{
|
||||
uint160 hanko;
|
||||
db->getBinary("Hanko", hanko.begin(), hanko.GetSerializeSize());
|
||||
std::string tstr;
|
||||
u160ToHuman(hanko, tstr);
|
||||
std::string strHanko;
|
||||
std::string strPublicKey;
|
||||
std::string strComment;
|
||||
|
||||
retStr.append(tstr);
|
||||
retStr.append("\n");
|
||||
db->getStr("Hanko", strHanko);
|
||||
db->getStr("PublicKey", strPublicKey);
|
||||
db->getStr("Comment", strComment);
|
||||
|
||||
Json::Value node(Json::objectValue);
|
||||
|
||||
node["Hanko"] = strHanko;
|
||||
node["PublicKey"] = strPublicKey;
|
||||
node["Comment"] = strComment;
|
||||
|
||||
ret.append(node);
|
||||
|
||||
more = db->getNextRow();
|
||||
}
|
||||
|
||||
db->endIterRows();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user