mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Add some LocalAccount helper functions. Add parseAccount.
This commit is contained in:
61
Wallet.cpp
61
Wallet.cpp
@@ -333,6 +333,27 @@ uint160 LocalAccount::getAddress() const
|
||||
return la->getAccountID();
|
||||
}
|
||||
|
||||
std::string LocalAccount::getShortName() const
|
||||
{
|
||||
std::string ret(mFamily->getShortName());
|
||||
ret.append(":");
|
||||
ret.append(boost::lexical_cast<std::string>(mSeq));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string LocalAccount::getFullName() const
|
||||
{
|
||||
std::string ret(mFamily->getFamily().GetHex());
|
||||
ret.append(":");
|
||||
ret.append(boost::lexical_cast<std::string>(mSeq));
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool LocalAccount::isIssued() const
|
||||
{
|
||||
return mSeq < mFamily->getSeq();
|
||||
}
|
||||
|
||||
uint32 LocalAccount::getAcctSeq() const
|
||||
{
|
||||
LocalAccountEntry::pointer la(mFamily->get(mSeq));
|
||||
@@ -458,6 +479,46 @@ LocalAccount::pointer Wallet::getLocalAccount(const uint160& family, int seq)
|
||||
return lac;
|
||||
}
|
||||
|
||||
LocalAccount::pointer Wallet::getLocalAccount(const uint160& acctID)
|
||||
{
|
||||
std::map<uint160, LocalAccount::pointer>::iterator ait=accounts.find(acctID);
|
||||
if(ait==accounts.end()) return LocalAccount::pointer();
|
||||
return ait->second;
|
||||
}
|
||||
|
||||
LocalAccount::pointer Wallet::parseAccount(const std::string& specifier)
|
||||
{ // <family>:<seq> or <acct_id>
|
||||
|
||||
std::cerr << "Parse(" << specifier << ")" << std::endl;
|
||||
|
||||
size_t colon=specifier.find(':');
|
||||
if(colon == std::string::npos)
|
||||
{
|
||||
std::cerr << "nocolon" << std::endl;
|
||||
NewcoinAddress na(specifier);
|
||||
if(!na.IsValid()) return LocalAccount::pointer();
|
||||
return getLocalAccount(na.GetHash160());
|
||||
}
|
||||
|
||||
if (colon==0) return LocalAccount::pointer();
|
||||
|
||||
std::string family=specifier.substr(0, colon);
|
||||
std::string seq=specifier.substr(colon+1);
|
||||
if(seq.empty()) return LocalAccount::pointer();
|
||||
|
||||
std::cerr << "family(" << family << "), seq(" << seq << ")" << std::endl;
|
||||
|
||||
uint160 f;
|
||||
if(isHexFamily(family))
|
||||
f.SetHex(family);
|
||||
else if(isHexPublicKey(family))
|
||||
f=findFamilyPK(family);
|
||||
else
|
||||
f=findFamilySN(family);
|
||||
if(!f) return LocalAccount::pointer();
|
||||
return getLocalAccount(f, boost::lexical_cast<int>(seq));
|
||||
}
|
||||
|
||||
uint160 Wallet::peekKey(const uint160& family, int seq)
|
||||
{
|
||||
std::map<uint160, LocalAccountFamily::pointer>::iterator fit=families.find(family);
|
||||
|
||||
6
Wallet.h
6
Wallet.h
@@ -85,6 +85,7 @@ public:
|
||||
bool isLocked() const { return mRootPrivateKey==NULL; }
|
||||
|
||||
void setSeq(uint32 s) { mLastSeq=s; }
|
||||
uint32 getSeq(void) { return mLastSeq; }
|
||||
void setName(const std::string& n) { mName=n; }
|
||||
void setComment(const std::string& c) { mComment=c; }
|
||||
|
||||
@@ -117,6 +118,10 @@ public:
|
||||
uint160 getAddress() const;
|
||||
bool isLocked() const;
|
||||
|
||||
std::string getShortName() const;
|
||||
std::string getFullName() const;
|
||||
bool isIssued() const;
|
||||
|
||||
bool signRaw(Serializer::pointer);
|
||||
bool signRaw(Serializer::pointer, std::vector<unsigned char>& signature);
|
||||
bool checkSignRaw(Serializer::pointer data, std::vector<unsigned char>& signature);
|
||||
@@ -161,6 +166,7 @@ public:
|
||||
|
||||
void load(void);
|
||||
|
||||
LocalAccount::pointer parseAccount(const std::string& accountSpecifier);
|
||||
LocalAccount::pointer getLocalAccount(const uint160& famBase, int seq);
|
||||
LocalAccount::pointer getLocalAccount(const uint160& acctID);
|
||||
uint160 peekKey(const uint160& family, int seq);
|
||||
|
||||
Reference in New Issue
Block a user