fix for unl_add

This commit is contained in:
jed
2012-06-13 10:50:02 -07:00
parent e6464e2832
commit f1277325ff
4 changed files with 23 additions and 9 deletions

View File

@@ -54,7 +54,7 @@ int LedgerDBCount = sizeof(LedgerDBInit) / sizeof(const char *);
// Wallet database holds local accounts and trusted nodes
const char *WalletDBInit[] = {
// Node identity must be persisted for CAS routing and responsibilites.
// Node identity must be persisted for CAS routing and responsibilities.
"CREATE TABLE NodeIdentity ( \
PublicKey CHARACTER(53), \
PrivateKey CHARACTER(52), \
@@ -148,7 +148,8 @@ const char *WalletDBInit[] = {
"CREATE TABLE TrustedNodes ( \
PublicKey CHARACTER(53) PRIMARY KEY NOT NULL, \
Score INTEGER DEFAULT 0 NOT NULL, \
Seen DATETIME \
Seen DATETIME, \
Comment TEXT \
);",
// List of referrals.

View File

@@ -688,6 +688,7 @@ void Peer::recvGetContacts(newcoin::TMGetContacts& packet)
// return a list of your favorite people
// TODO: filter out all the LAN peers
// TODO: filter out the peer you are talking to
void Peer::recvGetPeers(newcoin::TMGetPeers& packet)
{
std::vector<std::string> addrs;

View File

@@ -1466,7 +1466,7 @@ Json::Value RPCServer::doAccountTransactions(Json::Value& params)
Json::Value RPCServer::doUnlAdd(Json::Value& params)
{
std::string strNode = params[0u].asString();
std::string strComment = (params.size() == 2) ? "" : params[1u].asString();
std::string strComment = (params.size() == 2) ? params[1u].asString() : "";
NewcoinAddress nodePublic;
@@ -1988,7 +1988,8 @@ Json::Value RPCServer::doUnlDefault(Json::Value& params) {
}
// unl_delete <public_key>
Json::Value RPCServer::doUnlDelete(Json::Value& params) {
Json::Value RPCServer::doUnlDelete(Json::Value& params)
{
std::string strNodePublic = params[0u].asString();
NewcoinAddress naNodePublic;
@@ -2005,8 +2006,11 @@ Json::Value RPCServer::doUnlDelete(Json::Value& params) {
}
}
Json::Value RPCServer::doUnlList(Json::Value& params) {
return theApp->getUNL().getUnlJson();
Json::Value RPCServer::doUnlList(Json::Value& params)
{
Json::Value obj(Json::objectValue);
obj["unl"]=theApp->getUNL().getUnlJson();
return obj;
}
// unl_reset

View File

@@ -1195,7 +1195,6 @@ void UniqueNodeList::setSeedDomains(const seedDomain& sdSource, bool bNext)
}
// Add a trusted node. Called by RPC or other source.
// XXX allow update of comment.
// XXX Broken should operate on seeds.
void UniqueNodeList::nodeAddPublic(const NewcoinAddress& naNodePublic, const std::string& strComment)
{
@@ -1205,8 +1204,17 @@ void UniqueNodeList::nodeAddPublic(const NewcoinAddress& naNodePublic, const std
Database* db=theApp->getWalletDB()->getDB();
ScopedLock sl(theApp->getWalletDB()->getDBLock());
db->executeSQL(str(boost::format("INSERT INTO TrustedNodes (PublicKey,Comment) values (%s,%s);")
% db->escape(strPublicKey) % db->escape(strComment)));
if( db->executeSQL(str(boost::format("SELECT count(*) from TrustedNodes where PublicKey=%s;") % db->escape(strPublicKey))) &&
db->startIterRows() && db->getInt(0)==1 )
{ // exists. update the comment
db->executeSQL(str(boost::format("UPDATE TrustedNodes set Comment=%s where PublicKey=%s;") % db->escape(strComment) % db->escape(strPublicKey) ));
}else
{ // new node
db->executeSQL(str(boost::format("INSERT INTO TrustedNodes (PublicKey,Comment) values (%s,%s);")
% db->escape(strPublicKey) % db->escape(strComment)));
}
}
{