From d5208e6d9242340cd808f63a2d574e73b5e55b5f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 3 Jan 2012 20:30:36 -0800 Subject: [PATCH] Add some LocalAccount helper functions. Add parseAccount. --- Wallet.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Wallet.h | 6 ++++++ 2 files changed, 67 insertions(+) diff --git a/Wallet.cpp b/Wallet.cpp index e86e129a7f..2bff331858 100644 --- a/Wallet.cpp +++ b/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(mSeq)); + return ret; +} + +std::string LocalAccount::getFullName() const +{ + std::string ret(mFamily->getFamily().GetHex()); + ret.append(":"); + ret.append(boost::lexical_cast(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::iterator ait=accounts.find(acctID); + if(ait==accounts.end()) return LocalAccount::pointer(); + return ait->second; +} + +LocalAccount::pointer Wallet::parseAccount(const std::string& specifier) +{ // : or + + 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(seq)); +} + uint160 Wallet::peekKey(const uint160& family, int seq) { std::map::iterator fit=families.find(family); diff --git a/Wallet.h b/Wallet.h index 8fcf28370b..ca5dc8cdad 100644 --- a/Wallet.h +++ b/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& signature); bool checkSignRaw(Serializer::pointer data, std::vector& 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);