Alphabet class for base58 conversions, Validators work

This commit is contained in:
Vinnie Falco
2013-10-03 18:29:30 -07:00
parent 7d089561c3
commit 66a272debd
21 changed files with 468 additions and 220 deletions

View File

@@ -24,22 +24,25 @@ struct Utilities::Helpers
{
// Matches a validator info line.
//
static boost::regex& reInfo ()
static boost::regex const& reInfo ()
{
// e.g.
//
// n9KorY8QtTdRx7TVDpwnG9NvyxsDwHUKUEeDLY3AkiGncVaSXZi5 Comment Text
//
static boost::regex re (
"^" // start of line
"(?:\\h*)" // horiz-white (optional)
"([^\\h\\v]+)" // [1] non-white run
"(?:\\h*)" // horiz-white (optional)
"([^\\h\\v]*)" // [2] any text (optional)
"$" // end of line
"\\G" // end of last match (or start)
"(?:[\\v\\h]*)" // white (optional)
"([^\\h\\v]+)" // [1] non-white run
"(?:\\h*)" // horiz-white (optional)
"([^\\v]*?)" // [2] non vert-white text (optional)
"(?:\\h*)" // white run (optional)
"(?:\\v*)" // vert-white (optional)
, boost::regex::perl |
boost::regex_constants::match_flags::match_not_dot_null
//"(?:\\')" // buffer boundary
, boost::regex::perl
//| boost::regex_constants::match_flags::match_not_dot_newline
);
return re;
@@ -47,7 +50,7 @@ struct Utilities::Helpers
// Matches a comment or whitespace line.
//
static boost::regex& reComment ()
static boost::regex const& reComment ()
{
// e.g.
//
@@ -87,23 +90,18 @@ bool Utilities::parseInfoLine (
RippleAddress deprecatedPublicKey;
// VFALCO NOTE These bool return values are poorlydocumented
//
if (deprecatedPublicKey.setSeedGeneric (encodedKey))
{
// expected a domain or public key but got a generic seed?
// log?
}
else if (deprecatedPublicKey.setNodePublic (encodedKey))
if (deprecatedPublicKey.setNodePublic (encodedKey))
{
// We got a public key.
RipplePublicKey publicKey (deprecatedPublicKey);
info.label = commentText;
info.publicKey = publicKey;
success = true;
}
else
{
// Some other junk.
// log?
journal.error << "Invalid RipplePublicKey: '" << encodedKey << "'";
}
}
else if (boost::regex_match (line, match, Helpers::reComment ()))
@@ -113,54 +111,9 @@ bool Utilities::parseInfoLine (
else
{
// Log a warning about a parsing error
journal.error << "Invalid Validators source line:" << std::endl << line;
}
#if 0
static boost::regex reReferral ("\\`\\s*(\\S+)(?:\\s+(.+))?\\s*\\'");
if (!boost::regex_match (strReferral, smMatch, reReferral))
{
WriteLog (lsWARNING, UniqueNodeList) << str (boost::format ("Bad validator: syntax error: %s: %s") % strSite % strReferral);
}
else
{
std::string strRefered = smMatch[1];
std::string strComment = smMatch[2];
RippleAddress naValidator;
if (naValidator.setSeedGeneric (strRefered))
{
WriteLog (lsWARNING, UniqueNodeList) << str (boost::format ("Bad validator: domain or public key required: %s %s") % strRefered % strComment);
}
else if (naValidator.setNodePublic (strRefered))
{
// A public key.
// XXX Schedule for CAS lookup.
nodeAddPublic (naValidator, vsWhy, strComment);
WriteLog (lsINFO, UniqueNodeList) << str (boost::format ("Node Public: %s %s") % strRefered % strComment);
if (naNodePublic.isValid ())
vstrValues.push_back (str (boost::format ("('%s',%d,'%s')") % strNodePublic % iValues % naValidator.humanNodePublic ()));
iValues++;
}
else
{
// A domain: need to look it up.
nodeAddDomain (strRefered, vsWhy, strComment);
WriteLog (lsINFO, UniqueNodeList) << str (boost::format ("Node Domain: %s %s") % strRefered % strComment);
if (naNodePublic.isValid ())
vstrValues.push_back (str (boost::format ("('%s',%d,%s)") % strNodePublic % iValues % sqlEscape (strRefered)));
iValues++;
}
}
#endif
return success;
}
@@ -171,15 +124,13 @@ void Utilities::parseResultLine (
std::string const& line,
Journal journal)
{
bool success = false;
Source::Info info;
if (! success)
bool success = parseInfoLine (info, line, journal);
if (success)
{
Source::Info info;
success = parseInfoLine (info, line, journal);
if (success)
result.list.add (info);
result.list.push_back (info);
result.success = true;
}
}
@@ -249,19 +200,6 @@ Time Utilities::stringToTime (String s)
return Time (0);
}
std::string Utilities::publicKeyToString (RipplePublicKey const& publicKey)
{
std::string s (RipplePublicKey::size, ' ');
std::copy (publicKey.cbegin(), publicKey.cend(), s.begin());
return s;
}
RipplePublicKey Utilities::stringToPublicKey (std::string const& s)
{
bassert (s.size() == RipplePublicKey::size);
return RipplePublicKey ();
}
//------------------------------------------------------------------------------
}