Rework addresses.

This commit is contained in:
Arthur Britto
2012-03-17 20:19:09 -07:00
parent 6e8421dd99
commit 73ff9b95ad
33 changed files with 1287 additions and 708 deletions

View File

@@ -2,31 +2,40 @@
#include "Application.h"
#include "Conversion.h"
void UniqueNodeList::addNode(uint160& hanko, std::vector<unsigned char>& publicKey)
void UniqueNodeList::addNode(NewcoinAddress address,std::string comment)
{
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);
Database* db=theApp->getWalletDB()->getDB();
// void UniqueNodeList::addNode(uint160& hanko, std::vector<unsigned char>& publicKey,std::string comment)
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(&(publicKey[0]), publicKey.size(), hashStr);
sql.append(hashStr);
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(")");
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
ScopedLock sl(theApp->getWalletDB()->getDBLock());
db->executeSQL(sql.c_str());
}
void UniqueNodeList::removeNode(uint160& hanko)
{
Database* db=theApp->getNetNodeDB()->getDB();
std::string sql="DELETE FROM UNL where 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);
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
ScopedLock sl(theApp->getWalletDB()->getDBLock());
db->executeSQL(sql.c_str());
}
@@ -34,13 +43,13 @@ void UniqueNodeList::removeNode(uint160& hanko)
#if 0
int UniqueNodeList::checkValid(newcoin::Validation& valid)
{
Database* db=theApp->getNetNodeDB()->getDB();
std::string sql="SELECT pubkey from UNL where hanko=";
Database* db=theApp->getWalletDB()->getDB();
std::string sql="SELECT pubkey from TrustedNodes where hanko=";
std::string hashStr;
db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr);
sql.append(hashStr);
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
ScopedLock sl(theApp->getWalletDB()->getDBLock());
if( db->executeSQL(sql.c_str()) )
{
if(db->startIterRows() && db->getNextRow())
@@ -59,10 +68,12 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
void UniqueNodeList::dumpUNL(std::string& retStr)
{
Database* db=theApp->getNetNodeDB()->getDB();
std::string sql="SELECT * FROM UNL;";
Database* db=theApp->getWalletDB()->getDB();
std::string sql="SELECT * FROM TrustedNodes;";
ScopedLock sl(theApp->getNetNodeDB()->getDBLock());
retStr.append("hello\n");
ScopedLock sl(theApp->getWalletDB()->getDBLock());
if( db->executeSQL(sql.c_str()) )
{
db->startIterRows();