mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
NewcoinAddress fixes and work towards unls.
This commit is contained in:
@@ -111,3 +111,4 @@ Application::~Application()
|
|||||||
delete mHashNodeDB;
|
delete mHashNodeDB;
|
||||||
delete mNetNodeDB;
|
delete mNetNodeDB;
|
||||||
}
|
}
|
||||||
|
// vim:ts=4
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ const char *TxnDBInit[] = {
|
|||||||
"CREATE TABLE PubKeys ( \
|
"CREATE TABLE PubKeys ( \
|
||||||
ID CHARACTER(35) PRIMARY KEY, \
|
ID CHARACTER(35) PRIMARY KEY, \
|
||||||
PubKey BLOB \
|
PubKey BLOB \
|
||||||
);" };
|
);"
|
||||||
|
};
|
||||||
|
|
||||||
int TxnDBCount=sizeof(TxnDBInit)/sizeof(const char *);
|
int TxnDBCount=sizeof(TxnDBInit)/sizeof(const char *);
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ const char *LedgerDBInit[] = {
|
|||||||
"CREATE INDEX LedgerConfByHash ON \
|
"CREATE INDEX LedgerConfByHash ON \
|
||||||
LedgerConfirmations(LedgerHash)"
|
LedgerConfirmations(LedgerHash)"
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
int LedgerDBCount=sizeof(LedgerDBInit)/sizeof(const char *);
|
int LedgerDBCount=sizeof(LedgerDBInit)/sizeof(const char *);
|
||||||
|
|
||||||
@@ -56,11 +57,16 @@ const char *WalletDBInit[] = {
|
|||||||
Seq BIGINT UNSIGNED, \
|
Seq BIGINT UNSIGNED, \
|
||||||
Comment TEXT \
|
Comment TEXT \
|
||||||
);",
|
);",
|
||||||
|
"CREATE TABLE NodeIdentity ( \
|
||||||
|
PublicKey CHARACTER(53), \
|
||||||
|
PrivateKey CHARACTER(52) \
|
||||||
|
);"
|
||||||
"CREATE TABLE TrustedNodes ( \
|
"CREATE TABLE TrustedNodes ( \
|
||||||
Hanko CHARACTER(35) PRIMARY KEY, \
|
Hanko CHARACTER(35) PRIMARY KEY, \
|
||||||
PubKey CHARACTER(53), \
|
PublicKey CHARACTER(53), \
|
||||||
Comment TEXT \
|
Comment TEXT \
|
||||||
);" };
|
);"
|
||||||
|
};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
"CREATE TABLE LocalAccounts ( \
|
"CREATE TABLE LocalAccounts ( \
|
||||||
@@ -97,7 +103,7 @@ const char *NetNodeDBInit[] = {
|
|||||||
HaveContactInfo CHARACTER(1), \
|
HaveContactInfo CHARACTER(1), \
|
||||||
ContactObject BLOB \
|
ContactObject BLOB \
|
||||||
);"
|
);"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int NetNodeDBCount=sizeof(NetNodeDBInit)/sizeof(const char *);
|
int NetNodeDBCount=sizeof(NetNodeDBInit)/sizeof(const char *);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LocalAccountFamily(const NewcoinAddress& family);
|
LocalAccountFamily(const NewcoinAddress& familyGenerator);
|
||||||
~LocalAccountFamily();
|
~LocalAccountFamily();
|
||||||
|
|
||||||
const NewcoinAddress& getFamily() const { return mFamily; }
|
const NewcoinAddress& getFamily() const { return mFamily; }
|
||||||
@@ -106,3 +106,4 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
// vim:ts=4
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#include "key.h"
|
#include "key.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "BitcoinUtil.h"
|
#include "BitcoinUtil.h"
|
||||||
#include "openssl/ec.h"
|
|
||||||
|
#include "openssl/rand.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -73,6 +74,10 @@ void NewcoinAddress::setHanko(const uint160& hash160)
|
|||||||
SetData(VER_HANKO, hash160.begin(), 20);
|
SetData(VER_HANKO, hash160.begin(), 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewcoinAddress::setHanko(const NewcoinAddress& nodePublic) {
|
||||||
|
setHanko(nodePublic.getHanko());
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// NodePublic
|
// NodePublic
|
||||||
//
|
//
|
||||||
@@ -158,6 +163,10 @@ bool NewcoinAddress::setNodePrivate(const std::string& strPrivate)
|
|||||||
return SetString(strPrivate.c_str(), VER_NODE_PRIVATE);
|
return SetString(strPrivate.c_str(), VER_NODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewcoinAddress::setNodePrivate(const std::vector<unsigned char>& vPrivate) {
|
||||||
|
SetData(VER_NODE_PRIVATE, vPrivate);
|
||||||
|
}
|
||||||
|
|
||||||
void NewcoinAddress::setNodePrivate(uint256 hash256)
|
void NewcoinAddress::setNodePrivate(uint256 hash256)
|
||||||
{
|
{
|
||||||
SetData(VER_NODE_PRIVATE, hash256.begin(), 32);
|
SetData(VER_NODE_PRIVATE, hash256.begin(), 32);
|
||||||
@@ -311,6 +320,11 @@ bool NewcoinAddress::setAccountPrivate(const std::string& strPrivate)
|
|||||||
return SetString(strPrivate.c_str(), VER_ACCOUNT_PRIVATE);
|
return SetString(strPrivate.c_str(), VER_ACCOUNT_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewcoinAddress::setAccountPrivate(const std::vector<unsigned char>& vPrivate)
|
||||||
|
{
|
||||||
|
SetData(VER_ACCOUNT_PRIVATE, vPrivate);
|
||||||
|
}
|
||||||
|
|
||||||
void NewcoinAddress::setAccountPrivate(uint256 hash256)
|
void NewcoinAddress::setAccountPrivate(uint256 hash256)
|
||||||
{
|
{
|
||||||
SetData(VER_ACCOUNT_PRIVATE, hash256.begin(), 32);
|
SetData(VER_ACCOUNT_PRIVATE, hash256.begin(), 32);
|
||||||
@@ -446,4 +460,13 @@ bool NewcoinAddress::setFamilySeed(const std::string& strSeed)
|
|||||||
void NewcoinAddress::setFamilySeed(uint128 hash128) {
|
void NewcoinAddress::setFamilySeed(uint128 hash128) {
|
||||||
SetData(VER_FAMILY_SEED, hash128.begin(), 16);
|
SetData(VER_FAMILY_SEED, hash128.begin(), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewcoinAddress::setFamilySeedRandom()
|
||||||
|
{
|
||||||
|
uint128 key;
|
||||||
|
|
||||||
|
RAND_bytes((unsigned char *) &key, sizeof(key));
|
||||||
|
|
||||||
|
NewcoinAddress::setFamilySeed(key);
|
||||||
|
}
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
|
|
||||||
bool setHanko(const std::string& strHanko);
|
bool setHanko(const std::string& strHanko);
|
||||||
void setHanko(const uint160& hash160);
|
void setHanko(const uint160& hash160);
|
||||||
|
void setHanko(const NewcoinAddress& nodePublic);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Node Public
|
// Node Public
|
||||||
@@ -57,6 +58,7 @@ public:
|
|||||||
std::string humanNodePrivate() const;
|
std::string humanNodePrivate() const;
|
||||||
|
|
||||||
bool setNodePrivate(const std::string& strPrivate);
|
bool setNodePrivate(const std::string& strPrivate);
|
||||||
|
void setNodePrivate(const std::vector<unsigned char>& vPrivate);
|
||||||
void setNodePrivate(uint256 hash256);
|
void setNodePrivate(uint256 hash256);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -88,6 +90,7 @@ public:
|
|||||||
std::string humanAccountPrivate() const;
|
std::string humanAccountPrivate() const;
|
||||||
|
|
||||||
bool setAccountPrivate(const std::string& strPrivate);
|
bool setAccountPrivate(const std::string& strPrivate);
|
||||||
|
void setAccountPrivate(const std::vector<unsigned char>& vPrivate);
|
||||||
void setAccountPrivate(uint256 hash256);
|
void setAccountPrivate(uint256 hash256);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -112,6 +115,7 @@ public:
|
|||||||
|
|
||||||
bool setFamilySeed(const std::string& strSeed);
|
bool setFamilySeed(const std::string& strSeed);
|
||||||
void setFamilySeed(uint128 hash128);
|
void setFamilySeed(uint128 hash128);
|
||||||
|
void setFamilySeedRandom();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#include "../json/value.h"
|
|
||||||
#include "../json/reader.h"
|
#include "../json/reader.h"
|
||||||
#include "../json/writer.h"
|
#include "../json/writer.h"
|
||||||
|
|
||||||
@@ -498,9 +497,9 @@ Json::Value RPCServer::doLedger(Json::Value& params)
|
|||||||
return "not implemented";
|
return "not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RPCServer::doAddUnl(Json::Value& params) {
|
Json::Value RPCServer::doUnlAdd(Json::Value& params) {
|
||||||
// addUNL <node_public>
|
// unl_add <node_public>
|
||||||
// addUNL <node_public> <comment>
|
// unl_add <node_public> <comment>
|
||||||
if(params.size()==1 || params.size()==2)
|
if(params.size()==1 || params.size()==2)
|
||||||
{
|
{
|
||||||
std::string pubKey=params[0u].asString();
|
std::string pubKey=params[0u].asString();
|
||||||
@@ -524,23 +523,43 @@ Json::Value RPCServer::doAddUnl(Json::Value& params) {
|
|||||||
else return "invalid params";
|
else return "invalid params";
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RPCServer::doGetUnl(Json::Value& params) {
|
Json::Value RPCServer::doUnlDefault(Json::Value& params) {
|
||||||
std::string str;
|
return "not implemented";
|
||||||
theApp->getUNL().dumpUNL(str);
|
}
|
||||||
|
|
||||||
return str.c_str();
|
Json::Value RPCServer::doUnlDelete(Json::Value& params) {
|
||||||
|
return "not implemented";
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value RPCServer::doUnlFetch(Json::Value& params) {
|
||||||
|
return "not implemented";
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value RPCServer::doUnlList(Json::Value& params) {
|
||||||
|
return theApp->getUNL().getUnlJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value RPCServer::doUnlReset(Json::Value& params) {
|
||||||
|
return "not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
|
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
|
||||||
{
|
{
|
||||||
std::cerr << "RPC:" << command << std::endl;
|
std::cerr << "RPC:" << command << std::endl;
|
||||||
|
|
||||||
if(command== "stop")
|
if(command== "stop")
|
||||||
{
|
{
|
||||||
mSocket.get_io_service().stop();
|
mSocket.get_io_service().stop();
|
||||||
return "newcoin server stopping";
|
return "newcoin server stopping";
|
||||||
}
|
}
|
||||||
if(command=="addUNL") return doAddUnl(params);
|
|
||||||
if(command=="getUNL") return doGetUnl(params);
|
if(command=="unl_add") return doUnlAdd(params);
|
||||||
|
if(command=="unl_default") return doUnlDefault(params);
|
||||||
|
if(command=="unl_delete") return doUnlDelete(params);
|
||||||
|
if(command=="unl_fetch") return doUnlFetch(params);
|
||||||
|
if(command=="unl_list") return doUnlList(params);
|
||||||
|
if(command=="unl_reset") return doUnlReset(params);
|
||||||
|
|
||||||
if(command=="createfamily") return doCreateFamily(params);
|
if(command=="createfamily") return doCreateFamily(params);
|
||||||
if(command=="familyinfo") return doFamilyInfo(params);
|
if(command=="familyinfo") return doFamilyInfo(params);
|
||||||
if(command=="accountinfo") return doAccountInfo(params);
|
if(command=="accountinfo") return doAccountInfo(params);
|
||||||
|
|||||||
@@ -45,8 +45,13 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
|||||||
Json::Value doTx(Json::Value& params);
|
Json::Value doTx(Json::Value& params);
|
||||||
Json::Value doLedger(Json::Value& params);
|
Json::Value doLedger(Json::Value& params);
|
||||||
Json::Value doAccount(Json::Value& params);
|
Json::Value doAccount(Json::Value& params);
|
||||||
Json::Value doAddUnl(Json::Value& params);
|
|
||||||
Json::Value doGetUnl(Json::Value& params);
|
Json::Value doUnlAdd(Json::Value& params);
|
||||||
|
Json::Value doUnlDefault(Json::Value& params);
|
||||||
|
Json::Value doUnlDelete(Json::Value& params);
|
||||||
|
Json::Value doUnlFetch(Json::Value& params);
|
||||||
|
Json::Value doUnlList(Json::Value& params);
|
||||||
|
Json::Value doUnlReset(Json::Value& params);
|
||||||
|
|
||||||
// Parses a string account name into a local or remote NewcoinAddress.
|
// Parses a string account name into a local or remote NewcoinAddress.
|
||||||
NewcoinAddress parseAccount(const std::string& account);
|
NewcoinAddress parseAccount(const std::string& account);
|
||||||
|
|||||||
@@ -2,41 +2,42 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Conversion.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();
|
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 strSql="INSERT INTO TrustedNodes (Hanko,PublicKey,Comment) values (";
|
||||||
std::string publicKey = address.humanNodePublic();
|
db->escape(reinterpret_cast<const unsigned char*>(strHanko.c_str()), strHanko.size(), strTmp);
|
||||||
|
strSql.append(strTmp);
|
||||||
std::string sql="INSERT INTO TrustedNodes (Hanko,PubKey,Comment) values (";
|
strSql.append(",");
|
||||||
std::string tmpStr;
|
db->escape(reinterpret_cast<const unsigned char*>(strPublicKey.c_str()), strPublicKey.size(), strTmp);
|
||||||
db->escape(reinterpret_cast<const unsigned char*>(hanko.c_str()), hanko.size(), tmpStr);
|
strSql.append(strTmp);
|
||||||
sql.append(tmpStr);
|
strSql.append(",");
|
||||||
sql.append(",");
|
db->escape(reinterpret_cast<const unsigned char*>(strComment.c_str()), strComment.size(), strTmp);
|
||||||
db->escape(reinterpret_cast<const unsigned char*>(publicKey.c_str()), publicKey.size(), tmpStr);
|
strSql.append(strTmp);
|
||||||
sql.append(tmpStr);
|
strSql.append(")");
|
||||||
sql.append(",");
|
|
||||||
db->escape(reinterpret_cast<const unsigned char*>(comment.c_str()), comment.size(), tmpStr);
|
|
||||||
sql.append(tmpStr);
|
|
||||||
sql.append(")");
|
|
||||||
|
|
||||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
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();
|
Database* db=theApp->getWalletDB()->getDB();
|
||||||
std::string sql="DELETE FROM TrustedNodes where hanko=";
|
|
||||||
std::string hashStr;
|
std::string strHanko = hanko.humanHanko();
|
||||||
db->escape(hanko.begin(), hanko.GetSerializeSize(), hashStr);
|
std::string strTmp;
|
||||||
sql.append(hashStr);
|
|
||||||
|
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());
|
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
|
// 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)
|
int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
||||||
{
|
{
|
||||||
Database* db=theApp->getWalletDB()->getDB();
|
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;
|
std::string hashStr;
|
||||||
db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr);
|
db->escape((unsigned char*) &(valid.hanko()[0]),valid.hanko().size(),hashStr);
|
||||||
sql.append(hashStr);
|
strSql.append(hashStr);
|
||||||
|
|
||||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
if( db->executeSQL(sql.c_str()) )
|
if( db->executeSQL(strSql.c_str()) )
|
||||||
{
|
{
|
||||||
if(db->startIterRows() && db->getNextRow())
|
if(db->startIterRows() && db->getNextRow())
|
||||||
{
|
{
|
||||||
@@ -66,28 +67,41 @@ int UniqueNodeList::checkValid(newcoin::Validation& valid)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void UniqueNodeList::dumpUNL(std::string& retStr)
|
Json::Value UniqueNodeList::getUnlJson()
|
||||||
{
|
{
|
||||||
Database* db=theApp->getWalletDB()->getDB();
|
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());
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
if( db->executeSQL(sql.c_str()) )
|
if( db->executeSQL(strSql.c_str()) )
|
||||||
{
|
{
|
||||||
db->startIterRows();
|
bool more = db->startIterRows();
|
||||||
while(db->getNextRow())
|
while (more)
|
||||||
{
|
{
|
||||||
uint160 hanko;
|
std::string strHanko;
|
||||||
db->getBinary("Hanko", hanko.begin(), hanko.GetSerializeSize());
|
std::string strPublicKey;
|
||||||
std::string tstr;
|
std::string strComment;
|
||||||
u160ToHuman(hanko, tstr);
|
|
||||||
|
|
||||||
retStr.append(tstr);
|
db->getStr("Hanko", strHanko);
|
||||||
retStr.append("\n");
|
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();
|
db->endIterRows();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
// vim:ts=4
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef __UNIQUE_NODE_LIST__
|
#ifndef __UNIQUE_NODE_LIST__
|
||||||
#define __UNIQUE_NODE_LIST__
|
#define __UNIQUE_NODE_LIST__
|
||||||
#include "../obj/src/newcoin.pb.h"
|
|
||||||
|
#include "../json/value.h"
|
||||||
|
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
#include "NewcoinAddress.h"
|
#include "NewcoinAddress.h"
|
||||||
|
|
||||||
@@ -12,13 +14,13 @@ public:
|
|||||||
//void load();
|
//void load();
|
||||||
//void save();
|
//void save();
|
||||||
|
|
||||||
void addNode(NewcoinAddress address,std::string comment);
|
void addNode(NewcoinAddress nodePublic, std::string strComment);
|
||||||
void removeNode(uint160& hanko);
|
void removeNode(NewcoinAddress hanko);
|
||||||
|
|
||||||
// 0- we don't care, 1- we care and is valid, 2-invalid signature
|
// 0- we don't care, 1- we care and is valid, 2-invalid signature
|
||||||
// int checkValid(newcoin::Validation& valid);
|
// int checkValid(newcoin::Validation& valid);
|
||||||
|
|
||||||
void dumpUNL(std::string& retStr);
|
Json::Value getUnlJson();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
217
src/Wallet.cpp
217
src/Wallet.cpp
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "openssl/rand.h"
|
|
||||||
#include "openssl/ec.h"
|
#include "openssl/ec.h"
|
||||||
|
|
||||||
#include "boost/foreach.hpp"
|
#include "boost/foreach.hpp"
|
||||||
@@ -10,7 +9,6 @@
|
|||||||
#include "boost/interprocess/sync/scoped_lock.hpp"
|
#include "boost/interprocess/sync/scoped_lock.hpp"
|
||||||
#include "boost/make_shared.hpp"
|
#include "boost/make_shared.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include "Wallet.h"
|
#include "Wallet.h"
|
||||||
#include "Ledger.h"
|
#include "Ledger.h"
|
||||||
#include "NewcoinAddress.h"
|
#include "NewcoinAddress.h"
|
||||||
@@ -29,17 +27,64 @@ LocalAccount::LocalAccount(boost::shared_ptr<LocalAccountFamily> family, int fam
|
|||||||
mPublicKey(family->getPublicKey(familySeq)), mFamily(family), mAccountFSeq(familySeq),
|
mPublicKey(family->getPublicKey(familySeq)), mFamily(family), mAccountFSeq(familySeq),
|
||||||
mLgrBalance(0), mTxnDelta(0), mTxnSeq(0)
|
mLgrBalance(0), mTxnDelta(0), mTxnSeq(0)
|
||||||
{
|
{
|
||||||
mAcctID=mPublicKey->GetAddress();
|
mAcctID.setAccountPublic(mPublicKey->GetPubKey());
|
||||||
|
|
||||||
if(theApp!=NULL) mPublicKey=theApp->getPubKeyCache().store(mAcctID, mPublicKey);
|
if(theApp!=NULL) mPublicKey=theApp->getPubKeyCache().store(mAcctID, mPublicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LocalAccount::getFullName() const
|
||||||
|
{
|
||||||
|
std::string ret(mFamily->getFamily().humanFamilyGenerator());
|
||||||
|
ret.append(":");
|
||||||
|
ret.append(boost::lexical_cast<std::string>(mAccountFSeq));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalAccount::isLocked() const
|
||||||
|
{
|
||||||
|
return mFamily->isLocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string LocalAccount::getFamilyName() const
|
||||||
|
{
|
||||||
|
return mFamily->getFamily().humanFamilyGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value LocalAccount::getJson() const
|
||||||
|
{
|
||||||
|
Json::Value ret(Json::objectValue);
|
||||||
|
ret["Family"]=getFamilyName();
|
||||||
|
ret["AccountID"]=getAddress().humanAccountID();
|
||||||
|
ret["AccountPublic"]=getAddress().humanAccountPublic();
|
||||||
|
ret["FullName"]=getFullName();
|
||||||
|
ret["Issued"]=Json::Value(isIssued());
|
||||||
|
ret["IsLocked"]=mFamily->isLocked();
|
||||||
|
|
||||||
|
uint64 eb=getEffectiveBalance();
|
||||||
|
if(eb!=0) ret["Balance"]=boost::lexical_cast<std::string>(eb);
|
||||||
|
|
||||||
|
uint32 sq=getTxnSeq();
|
||||||
|
if(sq!=0) ret["TxnSeq"]=boost::lexical_cast<std::string>(sq);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalAccount::isIssued() const
|
||||||
|
{
|
||||||
|
return mAccountFSeq < mFamily->getSeq();
|
||||||
|
}
|
||||||
|
|
||||||
|
CKey::pointer LocalAccount::getPrivateKey()
|
||||||
|
{
|
||||||
|
return mFamily->getPrivateKey(mAccountFSeq);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// LocalAccountFamily - a sequences of accounts
|
// LocalAccountFamily - a sequences of accounts
|
||||||
//
|
//
|
||||||
|
|
||||||
LocalAccountFamily::LocalAccountFamily(const NewcoinAddress& family) :
|
LocalAccountFamily::LocalAccountFamily(const NewcoinAddress& familyGenerator) :
|
||||||
mFamily(family), mLastSeq(0), mRootPrivateKey(NULL)
|
mFamily(familyGenerator), mLastSeq(0), mRootPrivateKey(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +254,7 @@ NewcoinAddress Wallet::addFamily(const NewcoinAddress& familySeed, bool lock)
|
|||||||
// Create a family. Return the family public generator and the seed.
|
// Create a family. Return the family public generator and the seed.
|
||||||
NewcoinAddress Wallet::addRandomFamily(NewcoinAddress& familySeed)
|
NewcoinAddress Wallet::addRandomFamily(NewcoinAddress& familySeed)
|
||||||
{
|
{
|
||||||
uint128 key;
|
familySeed.setFamilySeedRandom();
|
||||||
|
|
||||||
RAND_bytes((unsigned char *) &key, sizeof(key));
|
|
||||||
|
|
||||||
familySeed.setFamilySeed(key);
|
|
||||||
|
|
||||||
return addFamily(familySeed, false);
|
return addFamily(familySeed, false);
|
||||||
}
|
}
|
||||||
@@ -241,54 +282,6 @@ NewcoinAddress Wallet::findFamilyPK(const NewcoinAddress& familyGenerator)
|
|||||||
return fam ? fam->getFamily() : NewcoinAddress();
|
return fam ? fam->getFamily() : NewcoinAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LocalAccount::getFullName() const
|
|
||||||
{
|
|
||||||
std::string ret(mFamily->getFamily().humanFamilyGenerator());
|
|
||||||
ret.append(":");
|
|
||||||
ret.append(boost::lexical_cast<std::string>(mAccountFSeq));
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalAccount::isLocked() const
|
|
||||||
{
|
|
||||||
return mFamily->isLocked();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string LocalAccount::getFamilyName() const
|
|
||||||
{
|
|
||||||
return mFamily->getFamily().humanFamilyGenerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
Json::Value LocalAccount::getJson() const
|
|
||||||
{
|
|
||||||
Json::Value ret(Json::objectValue);
|
|
||||||
ret["Family"]=getFamilyName();
|
|
||||||
ret["AccountID"]=getAddress().humanAccountID();
|
|
||||||
ret["AccountPublic"]=getAddress().humanAccountPublic();
|
|
||||||
ret["FullName"]=getFullName();
|
|
||||||
ret["Issued"]=Json::Value(isIssued());
|
|
||||||
ret["IsLocked"]=mFamily->isLocked();
|
|
||||||
|
|
||||||
uint64 eb=getEffectiveBalance();
|
|
||||||
if(eb!=0) ret["Balance"]=boost::lexical_cast<std::string>(eb);
|
|
||||||
|
|
||||||
uint32 sq=getTxnSeq();
|
|
||||||
if(sq!=0) ret["TxnSeq"]=boost::lexical_cast<std::string>(sq);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalAccount::isIssued() const
|
|
||||||
{
|
|
||||||
return mAccountFSeq < mFamily->getSeq();
|
|
||||||
}
|
|
||||||
|
|
||||||
CKey::pointer LocalAccount::getPrivateKey()
|
|
||||||
{
|
|
||||||
return mFamily->getPrivateKey(mAccountFSeq);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wallet::getFamilies(std::vector<NewcoinAddress>& familyIDs)
|
void Wallet::getFamilies(std::vector<NewcoinAddress>& familyIDs)
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
@@ -337,8 +330,89 @@ Json::Value Wallet::getFamilyJson(const NewcoinAddress& family)
|
|||||||
return fit->second->getJson();
|
return fit->second->getJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Wallet::nodeIdentityLoad()
|
||||||
|
{
|
||||||
|
std::string strSql("SELECT * FROM NodeIdentity;");
|
||||||
|
|
||||||
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
|
Database *db=theApp->getWalletDB()->getDB();
|
||||||
|
|
||||||
|
if(!db->executeSQL(strSql.c_str())) return false;
|
||||||
|
if(!db->startIterRows()) return false;
|
||||||
|
|
||||||
|
std::string strPublicKey, strPrivateKey;
|
||||||
|
|
||||||
|
db->getStr("PublicKey", strPublicKey);
|
||||||
|
db->getStr("PrivateKey", strPrivateKey);
|
||||||
|
|
||||||
|
mNodePublicKey.setNodePublic(strPublicKey);
|
||||||
|
mNodePrivateKey.setNodePrivate(strPrivateKey);
|
||||||
|
|
||||||
|
db->endIterRows();
|
||||||
|
|
||||||
|
// Derive hanko from public key.
|
||||||
|
mNodeHanko.setHanko(mNodePublicKey);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wallet::nodeIdentityCreate() {
|
||||||
|
//
|
||||||
|
// Generate the public and private key
|
||||||
|
//
|
||||||
|
NewcoinAddress familySeed;
|
||||||
|
NewcoinAddress familyGenerator;
|
||||||
|
NewcoinAddress nodePublicKey;
|
||||||
|
NewcoinAddress nodePrivateKey;
|
||||||
|
|
||||||
|
familySeed.setFamilySeedRandom(); // Get a random seed.
|
||||||
|
familyGenerator.setFamilyGenerator(familySeed); // Derive generator from seed.
|
||||||
|
|
||||||
|
// The node public and private is 0th of the sequence.
|
||||||
|
nodePublicKey.setNodePublic(CKey(familyGenerator, 0).GetPubKey());
|
||||||
|
nodePrivateKey.setNodePrivate(CKey(familyGenerator, familySeed.getFamilyPrivateKey(), 0).GetSecret());
|
||||||
|
|
||||||
|
std::cerr << "New NodeIdentity:" << std::endl;
|
||||||
|
fprintf(stderr, "public: %s\n", nodePublicKey.humanNodePublic().c_str());
|
||||||
|
fprintf(stderr, "private: %s\n", nodePrivateKey.humanNodePrivate().c_str());
|
||||||
|
|
||||||
|
//
|
||||||
|
// Store the node information
|
||||||
|
//
|
||||||
|
Database* db = theApp->getWalletDB()->getDB();
|
||||||
|
|
||||||
|
std::string strTmp;
|
||||||
|
|
||||||
|
std::string strPublicKey = nodePublicKey.humanNodePublic();
|
||||||
|
std::string strPrivateKey = nodePrivateKey.humanNodePrivate();
|
||||||
|
|
||||||
|
std::string strSql = "INSERT INTO NodeIdentity (PublicKey,PrivateKey) VALUES (";
|
||||||
|
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*>(strPrivateKey.c_str()), strPrivateKey.size(), strTmp);
|
||||||
|
strSql.append(strTmp);
|
||||||
|
strSql.append(");");
|
||||||
|
|
||||||
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
|
db->executeSQL(strSql.c_str());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Wallet::load()
|
void Wallet::load()
|
||||||
{
|
{
|
||||||
|
if (!nodeIdentityLoad()) {
|
||||||
|
nodeIdentityCreate();
|
||||||
|
if (!nodeIdentityLoad())
|
||||||
|
throw std::runtime_error("unable to retrieve new node identity.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "NodeIdentity:" << std::endl;
|
||||||
|
fprintf(stderr, "hanko: %s\n", mNodeHanko.humanHanko().c_str());
|
||||||
|
fprintf(stderr, "public: %s\n", mNodePublicKey.humanNodePublic().c_str());
|
||||||
|
fprintf(stderr, "private: %s\n", mNodePrivateKey.humanNodePrivate().c_str());
|
||||||
|
|
||||||
std::string sql("SELECT * FROM LocalAcctFamilies;");
|
std::string sql("SELECT * FROM LocalAcctFamilies;");
|
||||||
|
|
||||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
@@ -350,24 +424,27 @@ void Wallet::load()
|
|||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!db->startIterRows()) return;
|
if(!db->startIterRows()) return;
|
||||||
|
|
||||||
while(db->getNextRow())
|
while(db->getNextRow())
|
||||||
{
|
{
|
||||||
std::string generator, comment;
|
std::string strGenerator, strComment;
|
||||||
db->getStr("FamilyGenerator", generator);
|
|
||||||
db->getStr("Comment", comment);
|
db->getStr("FamilyGenerator", strGenerator);
|
||||||
|
db->getStr("Comment", strComment);
|
||||||
int seq=db->getBigInt("Seq");
|
int seq=db->getBigInt("Seq");
|
||||||
|
|
||||||
NewcoinAddress familyGenerator;
|
NewcoinAddress familyGenerator;
|
||||||
|
|
||||||
familyGenerator.setFamilyGenerator(generator);
|
familyGenerator.setFamilyGenerator(strGenerator);
|
||||||
|
|
||||||
LocalAccountFamily::pointer f(doPublic(familyGenerator, true, false));
|
LocalAccountFamily::pointer f(doPublic(familyGenerator, true, false));
|
||||||
if(f)
|
if(f)
|
||||||
{
|
{
|
||||||
assert(f->getFamily().getFamilyGenerator()==familyGenerator.getFamilyGenerator());
|
assert(f->getFamily().getFamilyGenerator()==familyGenerator.getFamilyGenerator());
|
||||||
f->setSeq(seq);
|
f->setSeq(seq);
|
||||||
f->setComment(comment);
|
f->setComment(strComment);
|
||||||
}
|
}
|
||||||
else assert(false);
|
else assert(false);
|
||||||
}
|
}
|
||||||
@@ -503,6 +580,7 @@ void Wallet::delFamily(const NewcoinAddress& familyName)
|
|||||||
mFamilies.erase(familyName);
|
mFamilies.erase(familyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Look for and possible create a family based on its generator.
|
||||||
// --> pubKey: hex
|
// --> pubKey: hex
|
||||||
// --> do_create: Add to mFamilies
|
// --> do_create: Add to mFamilies
|
||||||
// --> do_db: write out db
|
// --> do_db: write out db
|
||||||
@@ -537,25 +615,26 @@ LocalAccountFamily::pointer Wallet::doPublic(const NewcoinAddress& familyGenerat
|
|||||||
return fam;
|
return fam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Look for and possible create a family based on its seed.
|
||||||
LocalAccountFamily::pointer Wallet::doPrivate(const NewcoinAddress& familySeed, bool do_create, bool do_unlock)
|
LocalAccountFamily::pointer Wallet::doPrivate(const NewcoinAddress& familySeed, bool do_create, bool do_unlock)
|
||||||
{
|
{
|
||||||
NewcoinAddress family;
|
NewcoinAddress familyGenerator;
|
||||||
family.setFamilyGenerator(familySeed);
|
familyGenerator.setFamilyGenerator(familySeed);
|
||||||
|
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
LocalAccountFamily::pointer fam;
|
LocalAccountFamily::pointer fam;
|
||||||
std::map<NewcoinAddress, LocalAccountFamily::pointer>::iterator it=mFamilies.find(family);
|
std::map<NewcoinAddress, LocalAccountFamily::pointer>::iterator it=mFamilies.find(familyGenerator);
|
||||||
if(it==mFamilies.end())
|
if(it==mFamilies.end())
|
||||||
{ // family not found
|
{ // family not found
|
||||||
fam=LocalAccountFamily::readFamily(family);
|
fam=LocalAccountFamily::readFamily(familyGenerator);
|
||||||
if(!fam)
|
if(!fam)
|
||||||
{
|
{
|
||||||
if(!do_create)
|
if(!do_create)
|
||||||
{
|
{
|
||||||
return LocalAccountFamily::pointer();
|
return LocalAccountFamily::pointer();
|
||||||
}
|
}
|
||||||
fam=boost::make_shared<LocalAccountFamily>(family);
|
fam=boost::make_shared<LocalAccountFamily>(familyGenerator);
|
||||||
mFamilies.insert(std::make_pair(family, fam));
|
mFamilies.insert(std::make_pair(familyGenerator, fam));
|
||||||
fam->write(true);
|
fam->write(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,17 @@ class Ledger;
|
|||||||
|
|
||||||
class Wallet
|
class Wallet
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
bool nodeIdentityLoad();
|
||||||
|
bool nodeIdentityCreate();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
boost::recursive_mutex mLock;
|
boost::recursive_mutex mLock;
|
||||||
|
|
||||||
|
NewcoinAddress mNodeHanko;
|
||||||
|
NewcoinAddress mNodePublicKey;
|
||||||
|
NewcoinAddress mNodePrivateKey;
|
||||||
|
|
||||||
std::map<NewcoinAddress, LocalAccountFamily::pointer> mFamilies;
|
std::map<NewcoinAddress, LocalAccountFamily::pointer> mFamilies;
|
||||||
std::map<NewcoinAddress, LocalAccount::pointer> mAccounts;
|
std::map<NewcoinAddress, LocalAccount::pointer> mAccounts;
|
||||||
std::map<uint256, LocalTransaction::pointer> mTransactions;
|
std::map<uint256, LocalTransaction::pointer> mTransactions;
|
||||||
|
|||||||
Reference in New Issue
Block a user