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 mNetNodeDB;
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -19,7 +19,8 @@ const char *TxnDBInit[] = {
|
||||
"CREATE TABLE PubKeys ( \
|
||||
ID CHARACTER(35) PRIMARY KEY, \
|
||||
PubKey BLOB \
|
||||
);" };
|
||||
);"
|
||||
};
|
||||
|
||||
int TxnDBCount=sizeof(TxnDBInit)/sizeof(const char *);
|
||||
|
||||
@@ -45,7 +46,7 @@ const char *LedgerDBInit[] = {
|
||||
"CREATE INDEX LedgerConfByHash ON \
|
||||
LedgerConfirmations(LedgerHash)"
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
int LedgerDBCount=sizeof(LedgerDBInit)/sizeof(const char *);
|
||||
|
||||
@@ -56,11 +57,16 @@ const char *WalletDBInit[] = {
|
||||
Seq BIGINT UNSIGNED, \
|
||||
Comment TEXT \
|
||||
);",
|
||||
"CREATE TABLE NodeIdentity ( \
|
||||
PublicKey CHARACTER(53), \
|
||||
PrivateKey CHARACTER(52) \
|
||||
);"
|
||||
"CREATE TABLE TrustedNodes ( \
|
||||
Hanko CHARACTER(35) PRIMARY KEY, \
|
||||
PubKey CHARACTER(53), \
|
||||
Comment TEXT \
|
||||
);" };
|
||||
Hanko CHARACTER(35) PRIMARY KEY, \
|
||||
PublicKey CHARACTER(53), \
|
||||
Comment TEXT \
|
||||
);"
|
||||
};
|
||||
|
||||
#if 0
|
||||
"CREATE TABLE LocalAccounts ( \
|
||||
@@ -97,7 +103,7 @@ const char *NetNodeDBInit[] = {
|
||||
HaveContactInfo CHARACTER(1), \
|
||||
ContactObject BLOB \
|
||||
);"
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
int NetNodeDBCount=sizeof(NetNodeDBInit)/sizeof(const char *);
|
||||
|
||||
@@ -77,7 +77,7 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
LocalAccountFamily(const NewcoinAddress& family);
|
||||
LocalAccountFamily(const NewcoinAddress& familyGenerator);
|
||||
~LocalAccountFamily();
|
||||
|
||||
const NewcoinAddress& getFamily() const { return mFamily; }
|
||||
@@ -106,3 +106,4 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
// vim:ts=4
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#include "key.h"
|
||||
#include "Config.h"
|
||||
#include "BitcoinUtil.h"
|
||||
#include "openssl/ec.h"
|
||||
|
||||
#include "openssl/rand.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
@@ -73,6 +74,10 @@ void NewcoinAddress::setHanko(const uint160& hash160)
|
||||
SetData(VER_HANKO, hash160.begin(), 20);
|
||||
}
|
||||
|
||||
void NewcoinAddress::setHanko(const NewcoinAddress& nodePublic) {
|
||||
setHanko(nodePublic.getHanko());
|
||||
}
|
||||
|
||||
//
|
||||
// NodePublic
|
||||
//
|
||||
@@ -158,6 +163,10 @@ bool NewcoinAddress::setNodePrivate(const std::string& strPrivate)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void NewcoinAddress::setAccountPrivate(const std::vector<unsigned char>& vPrivate)
|
||||
{
|
||||
SetData(VER_ACCOUNT_PRIVATE, vPrivate);
|
||||
}
|
||||
|
||||
void NewcoinAddress::setAccountPrivate(uint256 hash256)
|
||||
{
|
||||
SetData(VER_ACCOUNT_PRIVATE, hash256.begin(), 32);
|
||||
@@ -446,4 +460,13 @@ bool NewcoinAddress::setFamilySeed(const std::string& strSeed)
|
||||
void NewcoinAddress::setFamilySeed(uint128 hash128) {
|
||||
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
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
|
||||
bool setHanko(const std::string& strHanko);
|
||||
void setHanko(const uint160& hash160);
|
||||
void setHanko(const NewcoinAddress& nodePublic);
|
||||
|
||||
//
|
||||
// Node Public
|
||||
@@ -57,6 +58,7 @@ public:
|
||||
std::string humanNodePrivate() const;
|
||||
|
||||
bool setNodePrivate(const std::string& strPrivate);
|
||||
void setNodePrivate(const std::vector<unsigned char>& vPrivate);
|
||||
void setNodePrivate(uint256 hash256);
|
||||
|
||||
//
|
||||
@@ -88,6 +90,7 @@ public:
|
||||
std::string humanAccountPrivate() const;
|
||||
|
||||
bool setAccountPrivate(const std::string& strPrivate);
|
||||
void setAccountPrivate(const std::vector<unsigned char>& vPrivate);
|
||||
void setAccountPrivate(uint256 hash256);
|
||||
|
||||
//
|
||||
@@ -112,6 +115,7 @@ public:
|
||||
|
||||
bool setFamilySeed(const std::string& strSeed);
|
||||
void setFamilySeed(uint128 hash128);
|
||||
void setFamilySeedRandom();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "../json/value.h"
|
||||
#include "../json/reader.h"
|
||||
#include "../json/writer.h"
|
||||
|
||||
@@ -498,9 +497,9 @@ Json::Value RPCServer::doLedger(Json::Value& params)
|
||||
return "not implemented";
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doAddUnl(Json::Value& params) {
|
||||
// addUNL <node_public>
|
||||
// addUNL <node_public> <comment>
|
||||
Json::Value RPCServer::doUnlAdd(Json::Value& params) {
|
||||
// unl_add <node_public>
|
||||
// unl_add <node_public> <comment>
|
||||
if(params.size()==1 || params.size()==2)
|
||||
{
|
||||
std::string pubKey=params[0u].asString();
|
||||
@@ -524,23 +523,43 @@ Json::Value RPCServer::doAddUnl(Json::Value& params) {
|
||||
else return "invalid params";
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doGetUnl(Json::Value& params) {
|
||||
std::string str;
|
||||
theApp->getUNL().dumpUNL(str);
|
||||
Json::Value RPCServer::doUnlDefault(Json::Value& params) {
|
||||
return "not implemented";
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::cerr << "RPC:" << command << std::endl;
|
||||
|
||||
if(command== "stop")
|
||||
{
|
||||
mSocket.get_io_service().stop();
|
||||
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=="familyinfo") return doFamilyInfo(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 doLedger(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.
|
||||
NewcoinAddress parseAccount(const std::string& account);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef __UNIQUE_NODE_LIST__
|
||||
#define __UNIQUE_NODE_LIST__
|
||||
#include "../obj/src/newcoin.pb.h"
|
||||
|
||||
#include "../json/value.h"
|
||||
|
||||
#include "uint256.h"
|
||||
#include "NewcoinAddress.h"
|
||||
|
||||
@@ -12,13 +14,13 @@ public:
|
||||
//void load();
|
||||
//void save();
|
||||
|
||||
void addNode(NewcoinAddress address,std::string comment);
|
||||
void removeNode(uint160& hanko);
|
||||
void addNode(NewcoinAddress nodePublic, std::string strComment);
|
||||
void removeNode(NewcoinAddress hanko);
|
||||
|
||||
// 0- we don't care, 1- we care and is valid, 2-invalid signature
|
||||
// int checkValid(newcoin::Validation& valid);
|
||||
|
||||
void dumpUNL(std::string& retStr);
|
||||
Json::Value getUnlJson();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
217
src/Wallet.cpp
217
src/Wallet.cpp
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "openssl/rand.h"
|
||||
#include "openssl/ec.h"
|
||||
|
||||
#include "boost/foreach.hpp"
|
||||
@@ -10,7 +9,6 @@
|
||||
#include "boost/interprocess/sync/scoped_lock.hpp"
|
||||
#include "boost/make_shared.hpp"
|
||||
|
||||
|
||||
#include "Wallet.h"
|
||||
#include "Ledger.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),
|
||||
mLgrBalance(0), mTxnDelta(0), mTxnSeq(0)
|
||||
{
|
||||
mAcctID=mPublicKey->GetAddress();
|
||||
mAcctID.setAccountPublic(mPublicKey->GetPubKey());
|
||||
|
||||
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::LocalAccountFamily(const NewcoinAddress& family) :
|
||||
mFamily(family), mLastSeq(0), mRootPrivateKey(NULL)
|
||||
LocalAccountFamily::LocalAccountFamily(const NewcoinAddress& familyGenerator) :
|
||||
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.
|
||||
NewcoinAddress Wallet::addRandomFamily(NewcoinAddress& familySeed)
|
||||
{
|
||||
uint128 key;
|
||||
|
||||
RAND_bytes((unsigned char *) &key, sizeof(key));
|
||||
|
||||
familySeed.setFamilySeed(key);
|
||||
familySeed.setFamilySeedRandom();
|
||||
|
||||
return addFamily(familySeed, false);
|
||||
}
|
||||
@@ -241,54 +282,6 @@ NewcoinAddress Wallet::findFamilyPK(const NewcoinAddress& familyGenerator)
|
||||
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)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
@@ -337,8 +330,89 @@ Json::Value Wallet::getFamilyJson(const NewcoinAddress& family)
|
||||
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()
|
||||
{
|
||||
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;");
|
||||
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
@@ -350,24 +424,27 @@ void Wallet::load()
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
if(!db->startIterRows()) return;
|
||||
|
||||
while(db->getNextRow())
|
||||
{
|
||||
std::string generator, comment;
|
||||
db->getStr("FamilyGenerator", generator);
|
||||
db->getStr("Comment", comment);
|
||||
std::string strGenerator, strComment;
|
||||
|
||||
db->getStr("FamilyGenerator", strGenerator);
|
||||
db->getStr("Comment", strComment);
|
||||
int seq=db->getBigInt("Seq");
|
||||
|
||||
NewcoinAddress familyGenerator;
|
||||
|
||||
familyGenerator.setFamilyGenerator(generator);
|
||||
familyGenerator.setFamilyGenerator(strGenerator);
|
||||
|
||||
LocalAccountFamily::pointer f(doPublic(familyGenerator, true, false));
|
||||
if(f)
|
||||
{
|
||||
assert(f->getFamily().getFamilyGenerator()==familyGenerator.getFamilyGenerator());
|
||||
f->setSeq(seq);
|
||||
f->setComment(comment);
|
||||
f->setComment(strComment);
|
||||
}
|
||||
else assert(false);
|
||||
}
|
||||
@@ -503,6 +580,7 @@ void Wallet::delFamily(const NewcoinAddress& familyName)
|
||||
mFamilies.erase(familyName);
|
||||
}
|
||||
|
||||
// Look for and possible create a family based on its generator.
|
||||
// --> pubKey: hex
|
||||
// --> do_create: Add to mFamilies
|
||||
// --> do_db: write out db
|
||||
@@ -537,25 +615,26 @@ LocalAccountFamily::pointer Wallet::doPublic(const NewcoinAddress& familyGenerat
|
||||
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)
|
||||
{
|
||||
NewcoinAddress family;
|
||||
family.setFamilyGenerator(familySeed);
|
||||
NewcoinAddress familyGenerator;
|
||||
familyGenerator.setFamilyGenerator(familySeed);
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
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())
|
||||
{ // family not found
|
||||
fam=LocalAccountFamily::readFamily(family);
|
||||
fam=LocalAccountFamily::readFamily(familyGenerator);
|
||||
if(!fam)
|
||||
{
|
||||
if(!do_create)
|
||||
{
|
||||
return LocalAccountFamily::pointer();
|
||||
}
|
||||
fam=boost::make_shared<LocalAccountFamily>(family);
|
||||
mFamilies.insert(std::make_pair(family, fam));
|
||||
fam=boost::make_shared<LocalAccountFamily>(familyGenerator);
|
||||
mFamilies.insert(std::make_pair(familyGenerator, fam));
|
||||
fam->write(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,17 @@ class Ledger;
|
||||
|
||||
class Wallet
|
||||
{
|
||||
private:
|
||||
bool nodeIdentityLoad();
|
||||
bool nodeIdentityCreate();
|
||||
|
||||
protected:
|
||||
boost::recursive_mutex mLock;
|
||||
|
||||
NewcoinAddress mNodeHanko;
|
||||
NewcoinAddress mNodePublicKey;
|
||||
NewcoinAddress mNodePrivateKey;
|
||||
|
||||
std::map<NewcoinAddress, LocalAccountFamily::pointer> mFamilies;
|
||||
std::map<NewcoinAddress, LocalAccount::pointer> mAccounts;
|
||||
std::map<uint256, LocalTransaction::pointer> mTransactions;
|
||||
|
||||
Reference in New Issue
Block a user