mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Missing pieces.
This commit is contained in:
92
Wallet.cpp
92
Wallet.cpp
@@ -103,6 +103,83 @@ static bool isHex(char j)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalAccountFamily::pointer LocalAccountFamily::readFamily(const uint160& family)
|
||||||
|
{
|
||||||
|
std::string sql="SELECT * from LocalAcctFamilies WHERE FamilyName='";
|
||||||
|
sql.append(family.GetHex());
|
||||||
|
sql.append("';");
|
||||||
|
|
||||||
|
std::string rootPubKey, name, comment;
|
||||||
|
uint32 seq;
|
||||||
|
|
||||||
|
if(1)
|
||||||
|
{
|
||||||
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
|
Database *db=theApp->getWalletDB()->getDB();
|
||||||
|
|
||||||
|
if(!db->executeSQL(sql.c_str()) || !db->getNextRow())
|
||||||
|
return LocalAccountFamily::pointer();
|
||||||
|
|
||||||
|
db->getStr("RootPubKey", rootPubKey);
|
||||||
|
db->getStr("Name", name);
|
||||||
|
db->getStr("Comment", comment);
|
||||||
|
seq=db->getBigInt("Seq");
|
||||||
|
|
||||||
|
db->endIterRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
EC_GROUP *grp=EC_GROUP_new_by_curve_name(NID_secp256k1);
|
||||||
|
if(!grp) return LocalAccountFamily::pointer();
|
||||||
|
|
||||||
|
EC_POINT *pubKey=EC_POINT_hex2point(grp, rootPubKey.c_str(), NULL, NULL);
|
||||||
|
if(!pubKey)
|
||||||
|
{
|
||||||
|
EC_GROUP_free(grp);
|
||||||
|
assert(false);
|
||||||
|
return LocalAccountFamily::pointer();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalAccountFamily::pointer fam(new LocalAccountFamily(family, grp, pubKey));
|
||||||
|
EC_GROUP_free(grp);
|
||||||
|
EC_POINT_free(pubKey);
|
||||||
|
|
||||||
|
fam->setName(name);
|
||||||
|
fam->setComment(comment);
|
||||||
|
fam->setSeq(seq);
|
||||||
|
return fam;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalAccountFamily::write(bool is_new)
|
||||||
|
{
|
||||||
|
std::string sql="INSERT INTO LocalAcctFamilies (FamilyName,RootPubKey,Seq,Name,Comment) VALUES ('";
|
||||||
|
sql.append(mFamily.GetHex());
|
||||||
|
sql.append("','");
|
||||||
|
|
||||||
|
EC_GROUP* grp=EC_GROUP_new_by_curve_name(NID_secp256k1);
|
||||||
|
if(!grp) return;
|
||||||
|
char *rpk=EC_POINT_point2hex(grp, mRootPubKey, POINT_CONVERSION_COMPRESSED, NULL);
|
||||||
|
EC_GROUP_free(grp);
|
||||||
|
if(!rpk) return;
|
||||||
|
sql.append(rpk);
|
||||||
|
OPENSSL_free(rpk);
|
||||||
|
|
||||||
|
sql.append("','");
|
||||||
|
sql.append(boost::lexical_cast<std::string>(mLastSeq));
|
||||||
|
sql.append("',");
|
||||||
|
|
||||||
|
std::string f;
|
||||||
|
theApp->getWalletDB()->getDB()->escape((const unsigned char *) mName.c_str(), mName.size(), f);
|
||||||
|
sql.append(f);
|
||||||
|
sql.append(",");
|
||||||
|
theApp->getWalletDB()->getDB()->escape((const unsigned char *) mComment.c_str(), mComment.size(), f);
|
||||||
|
sql.append(f);
|
||||||
|
|
||||||
|
sql.append(");");
|
||||||
|
|
||||||
|
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||||
|
theApp->getWalletDB()->getDB()->executeSQL(sql.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
bool LocalAccountFamily::isHexPrivateKey(const std::string& s)
|
bool LocalAccountFamily::isHexPrivateKey(const std::string& s)
|
||||||
{ // 64 characters, all legal hex
|
{ // 64 characters, all legal hex
|
||||||
if(s.size()!=64) return false;
|
if(s.size()!=64) return false;
|
||||||
@@ -311,10 +388,16 @@ LocalAccountFamily::pointer Wallet::doPublic(const std::string& pubKey)
|
|||||||
return fit->second;
|
return fit->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalAccountFamily::pointer fam(new LocalAccountFamily(family,
|
LocalAccountFamily::pointer fam=LocalAccountFamily::readFamily(family);
|
||||||
|
if(!fam)
|
||||||
|
{
|
||||||
|
fam=LocalAccountFamily::pointer(new LocalAccountFamily(family,
|
||||||
EC_KEY_get0_group(pkey), EC_KEY_get0_public_key(pkey)));
|
EC_KEY_get0_group(pkey), EC_KEY_get0_public_key(pkey)));
|
||||||
EC_KEY_free(pkey);
|
|
||||||
families.insert(std::make_pair(family, fam));
|
families.insert(std::make_pair(family, fam));
|
||||||
|
fam->write(true);
|
||||||
|
}
|
||||||
|
EC_KEY_free(pkey);
|
||||||
|
|
||||||
return fam;
|
return fam;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,6 +417,9 @@ LocalAccountFamily::pointer Wallet::doPrivate(const uint256& passPhrase, bool do
|
|||||||
std::map<uint160, LocalAccountFamily::pointer>::iterator it=families.find(family);
|
std::map<uint160, LocalAccountFamily::pointer>::iterator it=families.find(family);
|
||||||
if(it==families.end())
|
if(it==families.end())
|
||||||
{ // family not found
|
{ // family not found
|
||||||
|
fam=LocalAccountFamily::readFamily(family);
|
||||||
|
if(!fam)
|
||||||
|
{
|
||||||
if(!do_create)
|
if(!do_create)
|
||||||
{
|
{
|
||||||
EC_KEY_free(base);
|
EC_KEY_free(base);
|
||||||
@@ -342,6 +428,8 @@ LocalAccountFamily::pointer Wallet::doPrivate(const uint256& passPhrase, bool do
|
|||||||
fam=LocalAccountFamily::pointer(new LocalAccountFamily(family,
|
fam=LocalAccountFamily::pointer(new LocalAccountFamily(family,
|
||||||
EC_KEY_get0_group(base), EC_KEY_get0_public_key(base)));
|
EC_KEY_get0_group(base), EC_KEY_get0_public_key(base)));
|
||||||
families.insert(std::make_pair(family, fam));
|
families.insert(std::make_pair(family, fam));
|
||||||
|
fam->write(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else fam=it->second;
|
else fam=it->second;
|
||||||
|
|
||||||
|
|||||||
2
Wallet.h
2
Wallet.h
@@ -97,6 +97,8 @@ public:
|
|||||||
|
|
||||||
static std::string getSQLFields();
|
static std::string getSQLFields();
|
||||||
std::string getSQL() const;
|
std::string getSQL() const;
|
||||||
|
static LocalAccountFamily::pointer readFamily(const uint160& family);
|
||||||
|
void write(bool is_new);
|
||||||
|
|
||||||
static bool isHexPrivateKey(const std::string&);
|
static bool isHexPrivateKey(const std::string&);
|
||||||
static bool isHexPublicKey(const std::string&);
|
static bool isHexPublicKey(const std::string&);
|
||||||
|
|||||||
Reference in New Issue
Block a user