Levelization, improve structure of source files:

Source files are moved between modules, includes changed and added,
and some code rewritten, with the goal of reducing cross-module dependencies
and eliminating cycles in the dependency graph of classes.

* Remove RippleAddress dependency in CKey_test
* ByteOrder.h, Blob.h, and strHex.h are moved to basics/. This makes
  the basics/ module fully independent of other ripple sources.
* types/ is merged into protocol/. The protocol module now contains
  all primitive types specific to the Ripple protocol.
* Move ErrorCodes to protocol/
* Move base_uint to basics/
* Move Base58 to crypto/
* Remove dependence on Serializer in GenerateDeterministicKey
* Eliminate unity header json.h
* Remove obsolete unity headers
* Remove unnecessary includes
This commit is contained in:
Vinnie Falco
2014-12-19 08:57:30 -08:00
parent e3fbb83ad0
commit 60f27178b8
109 changed files with 859 additions and 493 deletions

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_TYPES_BLOB_H_INCLUDED
#define RIPPLE_TYPES_BLOB_H_INCLUDED
#include <vector>
namespace ripple {
/** Storage for linear binary data.
Blocks of binary data appear often in various idioms and structures.
*/
typedef std::vector <unsigned char> Blob;
}
#endif

245
src/ripple/protocol/Book.h Normal file
View File

@@ -0,0 +1,245 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_BOOK_H_INCLUDED
#define RIPPLE_PROTOCOL_BOOK_H_INCLUDED
#include <ripple/protocol/Issue.h>
#include <boost/utility/base_from_member.hpp>
namespace ripple {
/** Specifies an order book.
The order book is a pair of Issues called in and out.
@see Issue.
*/
template <bool ByValue>
class BookType
{
public:
typedef IssueType <ByValue> Issue;
Issue in;
Issue out;
BookType ()
{
}
BookType (Issue const& in_, Issue const& out_)
: in (in_)
, out (out_)
{
}
template <bool OtherByValue>
BookType (BookType <OtherByValue> const& other)
: in (other.in)
, out (other.out)
{
}
/** Assignment.
This is only valid when ByValue == `true`
*/
template <bool OtherByValue>
BookType& operator= (BookType <OtherByValue> const& other)
{
in = other.in;
out = other.out;
return *this;
}
};
template <bool ByValue>
bool isConsistent(BookType<ByValue> const& book)
{
return isConsistent(book.in) && isConsistent (book.out)
&& book.in != book.out;
}
template <bool ByValue>
std::string to_string (BookType<ByValue> const& book)
{
return to_string(book.in) + "->" + to_string(book.out);
}
template <bool ByValue>
std::ostream& operator<<(std::ostream& os, BookType<ByValue> const& x)
{
os << to_string (x);
return os;
}
template <bool ByValue, class Hasher>
void hash_append (Hasher& h, BookType<ByValue> const& b)
{
using beast::hash_append;
hash_append (h, b.in, b.out);
}
/** Ordered comparison. */
template <bool LhsByValue, bool RhsByValue>
int compare (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
int const diff (compare (lhs.in, rhs.in));
if (diff != 0)
return diff;
return compare (lhs.out, rhs.out);
}
/** Equality comparison. */
/** @{ */
template <bool LhsByValue, bool RhsByValue>
bool operator== (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return (lhs.in == rhs.in) &&
(lhs.out == rhs.out);
}
template <bool LhsByValue, bool RhsByValue>
bool operator!= (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return (lhs.in != rhs.in) ||
(lhs.out != rhs.out);
}
/** @} */
/** Strict weak ordering. */
/** @{ */
template <bool LhsByValue, bool RhsByValue>
bool operator< (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
int const diff (compare (lhs.in, rhs.in));
if (diff != 0)
return diff < 0;
return lhs.out < rhs.out;
}
template <bool LhsByValue, bool RhsByValue>
bool operator> (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return rhs < lhs;
}
template <bool LhsByValue, bool RhsByValue>
bool operator>= (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return ! (lhs < rhs);
}
template <bool LhsByValue, bool RhsByValue>
bool operator<= (BookType <LhsByValue> const& lhs,
BookType <RhsByValue> const& rhs)
{
return ! (rhs < lhs);
}
/** @} */
//------------------------------------------------------------------------------
typedef BookType <true> Book;
typedef BookType <false> BookRef;
}
//------------------------------------------------------------------------------
namespace std {
template <bool ByValue>
struct hash <ripple::IssueType <ByValue>>
: private boost::base_from_member <std::hash <ripple::Currency>, 0>
, private boost::base_from_member <std::hash <ripple::Account>, 1>
{
private:
typedef boost::base_from_member <
std::hash <ripple::Currency>, 0> currency_hash_type;
typedef boost::base_from_member <
std::hash <ripple::Account>, 1> issuer_hash_type;
public:
typedef std::size_t value_type;
typedef ripple::IssueType <ByValue> argument_type;
value_type operator() (argument_type const& value) const
{
value_type result (currency_hash_type::member (value.currency));
if (!isXRP (value.currency))
boost::hash_combine (result,
issuer_hash_type::member (value.account));
return result;
}
};
//------------------------------------------------------------------------------
template <bool ByValue>
struct hash <ripple::BookType <ByValue>>
{
private:
typedef std::hash <ripple::IssueType <ByValue>> hasher;
hasher m_hasher;
public:
typedef std::size_t value_type;
typedef ripple::BookType <ByValue> argument_type;
value_type operator() (argument_type const& value) const
{
value_type result (m_hasher (value.in));
boost::hash_combine (result, m_hasher (value.out));
return result;
}
};
}
//------------------------------------------------------------------------------
namespace boost {
template <bool ByValue>
struct hash <ripple::IssueType <ByValue>>
: std::hash <ripple::IssueType <ByValue>>
{
typedef std::hash <ripple::IssueType <ByValue>> Base;
// VFALCO NOTE broken in vs2012
//using Base::Base; // inherit ctors
};
template <bool ByValue>
struct hash <ripple::BookType <ByValue>>
: std::hash <ripple::BookType <ByValue>>
{
typedef std::hash <ripple::BookType <ByValue>> Base;
// VFALCO NOTE broken in vs2012
//using Base::Base; // inherit ctors
};
}
#endif

View File

@@ -0,0 +1,234 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ERRORCODES_H_INCLUDED
#define RIPPLE_PROTOCOL_ERRORCODES_H_INCLUDED
#include <ripple/protocol/JsonFields.h>
#include <ripple/json/json_value.h>
namespace ripple {
// VFALCO NOTE These are outside the RPC namespace
enum error_code_i
{
rpcUNKNOWN = -1, // Represents codes not listed in this enumeration
rpcSUCCESS = 0,
rpcBAD_SYNTAX, // Must be 1 to print usage to command line.
rpcJSON_RPC,
rpcFORBIDDEN,
// Error numbers beyond this line are not stable between versions.
// Programs should use error tokens.
// Misc failure
rpcGENERAL,
rpcLOAD_FAILED,
rpcNO_PERMISSION,
rpcNO_EVENTS,
rpcNOT_STANDALONE,
rpcTOO_BUSY,
rpcSLOW_DOWN,
rpcHIGH_FEE,
rpcNOT_ENABLED,
rpcNOT_READY,
// Networking
rpcNO_CLOSED,
rpcNO_CURRENT,
rpcNO_NETWORK,
// Ledger state
rpcACT_EXISTS,
rpcACT_NOT_FOUND,
rpcINSUF_FUNDS,
rpcLGR_NOT_FOUND,
rpcMASTER_DISABLED,
rpcNO_ACCOUNT,
rpcNO_PATH,
rpcPASSWD_CHANGED,
rpcSRC_MISSING,
rpcSRC_UNCLAIMED,
rpcTXN_NOT_FOUND,
rpcWRONG_SEED,
// Malformed command
rpcINVALID_PARAMS,
rpcUNKNOWN_COMMAND,
rpcNO_PF_REQUEST,
// Bad parameter
rpcACT_BITCOIN,
rpcACT_MALFORMED,
rpcQUALITY_MALFORMED,
rpcBAD_BLOB,
rpcBAD_FEATURE,
rpcBAD_ISSUER,
rpcBAD_MARKET,
rpcBAD_SECRET,
rpcBAD_SEED,
rpcCOMMAND_MISSING,
rpcDST_ACT_MALFORMED,
rpcDST_ACT_MISSING,
rpcDST_AMT_MALFORMED,
rpcDST_ISR_MALFORMED,
rpcGETS_ACT_MALFORMED,
rpcGETS_AMT_MALFORMED,
rpcHOST_IP_MALFORMED,
rpcLGR_IDXS_INVALID,
rpcLGR_IDX_MALFORMED,
rpcPAYS_ACT_MALFORMED,
rpcPAYS_AMT_MALFORMED,
rpcPORT_MALFORMED,
rpcPUBLIC_MALFORMED,
rpcSRC_ACT_MALFORMED,
rpcSRC_ACT_MISSING,
rpcSRC_ACT_NOT_FOUND,
rpcSRC_AMT_MALFORMED,
rpcSRC_CUR_MALFORMED,
rpcSRC_ISR_MALFORMED,
rpcATX_DEPRECATED,
// Internal error (should never happen)
rpcINTERNAL, // Generic internal error.
rpcFAIL_GEN_DECRYPT,
rpcNOT_IMPL,
rpcNOT_SUPPORTED,
rpcNO_GEN_DECRYPT,
};
//------------------------------------------------------------------------------
namespace RPC {
/** Maps an rpc error code to its token and default message. */
struct ErrorInfo
{
ErrorInfo (error_code_i code_, std::string const& token_,
std::string const& message_)
: code (code_)
, token (token_)
, message (message_)
{ }
error_code_i code;
std::string token;
std::string message;
};
/** Returns an ErrorInfo that reflects the error code. */
ErrorInfo const& get_error_info (error_code_i code);
/** Add or update the json update to reflect the error code. */
/** @{ */
template <class JsonValue>
void inject_error (error_code_i code, JsonValue& json)
{
ErrorInfo const& info (get_error_info (code));
json [jss::error] = info.token;
json [jss::error_code] = info.code;
json [jss::error_message] = info.message;
}
template <class JsonValue>
void inject_error (int code, JsonValue& json)
{
inject_error (error_code_i (code), json);
}
template <class JsonValue>
void inject_error (
error_code_i code, std::string const& message, JsonValue& json)
{
ErrorInfo const& info (get_error_info (code));
json [jss::error] = info.token;
json [jss::error_code] = info.code;
json [jss::error_message] = message;
}
/** @} */
/** Returns a new json object that reflects the error code. */
/** @{ */
Json::Value make_error (error_code_i code);
Json::Value make_error (error_code_i code, std::string const& message);
/** @} */
/** Returns a new json object that indicates invalid parameters. */
/** @{ */
inline Json::Value make_param_error (std::string const& message)
{
return make_error (rpcINVALID_PARAMS, message);
}
inline std::string missing_field_message (std::string const& name)
{
return "Missing field '" + name + "'.";
}
inline Json::Value missing_field_error (std::string const& name)
{
return make_param_error (missing_field_message (name));
}
inline std::string object_field_message (std::string const& name)
{
return "Invalid field '" + name + "', not object.";
}
inline Json::Value object_field_error (std::string const& name)
{
return make_param_error (object_field_message (name));
}
inline std::string invalid_field_message (std::string const& name)
{
return "Invalid field '" + name + "'.";
}
inline Json::Value invalid_field_error (std::string const& name)
{
return make_param_error (invalid_field_message (name));
}
inline std::string expected_field_message (
std::string const& name, std::string const& type)
{
return "Invalid field '" + name + "', not " + type + ".";
}
inline Json::Value expected_field_error (
std::string const& name, std::string const& type)
{
return make_param_error (expected_field_message (name, type));
}
/** @} */
/** Returns `true` if the json contains an rpc error specification. */
bool contains_error (Json::Value const& json);
}
}
#endif

View File

@@ -24,8 +24,8 @@
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/UintTypes.h>
#include <ripple/types/base_uint.h>
#include <ripple/types/Book.h>
#include <ripple/basics/base_uint.h>
#include <ripple/protocol/Book.h>
namespace ripple {

194
src/ripple/protocol/Issue.h Normal file
View File

@@ -0,0 +1,194 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ISSUE_INCLUDED
#define RIPPLE_PROTOCOL_ISSUE_INCLUDED
#include <cassert>
#include <functional>
#include <type_traits>
#include <ripple/protocol/UintTypes.h>
namespace ripple {
/** A currency issued by an account.
When ByValue is `false`, this only stores references, and the caller
is responsible for managing object lifetime.
@see Currency, Account, Issue, IssueRef, Book
*/
template <bool ByValue>
class IssueType
{
public:
typedef typename
std::conditional <ByValue, Currency, Currency const&>::type
IssueCurrency;
typedef typename
std::conditional <ByValue, Account, Account const&>::type
IssueAccount;
IssueCurrency currency;
IssueAccount account;
IssueType ()
{
}
IssueType (Currency const& c, Account const& a)
: currency (c), account (a)
{
}
template <bool OtherByValue>
IssueType (IssueType <OtherByValue> const& other)
: currency (other.currency)
, account (other.account)
{
}
/** Assignment. */
template <bool MaybeByValue = ByValue, bool OtherByValue>
std::enable_if_t <MaybeByValue, IssueType&>
operator= (IssueType <OtherByValue> const& other)
{
currency = other.currency;
account = other.account;
return *this;
}
};
template <bool ByValue>
bool isConsistent(IssueType<ByValue> const& ac)
{
return isXRP (ac.currency) == isXRP (ac.account);
}
template <bool ByValue>
std::string to_string (IssueType<ByValue> const& ac)
{
return to_string(ac.account) + "/" + to_string(ac.currency);
}
template <bool ByValue>
std::ostream& operator<< (
std::ostream& os, IssueType<ByValue> const& x)
{
os << to_string (x);
return os;
}
template <bool ByValue, class Hasher>
void hash_append (Hasher& h, IssueType<ByValue> const& r)
{
using beast::hash_append;
hash_append (h, r.currency, r.account);
}
/** Ordered comparison.
The assets are ordered first by currency and then by account,
if the currency is not XRP.
*/
template <bool LhsByValue, bool RhsByValue>
int compare (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
int diff = compare (lhs.currency, rhs.currency);
if (diff != 0)
return diff;
if (isXRP (lhs.currency))
return 0;
return compare (lhs.account, rhs.account);
}
/** Equality comparison. */
/** @{ */
template <bool LhsByValue, bool RhsByValue>
bool operator== (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return compare (lhs, rhs) == 0;
}
template <bool LhsByValue, bool RhsByValue>
bool operator!= (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return ! (lhs == rhs);
}
/** @} */
/** Strict weak ordering. */
/** @{ */
template <bool LhsByValue, bool RhsByValue>
bool operator< (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return compare (lhs, rhs) < 0;
}
template <bool LhsByValue, bool RhsByValue>
bool operator> (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return rhs < lhs;
}
template <bool LhsByValue, bool RhsByValue>
bool operator>= (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return ! (lhs < rhs);
}
template <bool LhsByValue, bool RhsByValue>
bool operator<= (IssueType <LhsByValue> const& lhs,
IssueType <RhsByValue> const& rhs)
{
return ! (rhs < lhs);
}
/** @} */
//------------------------------------------------------------------------------
typedef IssueType <true> Issue;
typedef IssueType <false> IssueRef;
//------------------------------------------------------------------------------
/** Returns an asset specifier that represents XRP. */
inline Issue const& xrpIssue ()
{
static Issue issue {xrpCurrency(), xrpAccount()};
return issue;
}
/** Returns an asset specifier that represents no account and currency. */
inline Issue const& noIssue ()
{
static Issue issue {noCurrency(), noAccount()};
return issue;
}
}
#endif

View File

@@ -20,6 +20,8 @@
#ifndef RIPPLE_PROTOCOL_JSONFIELDS_H_INCLUDED
#define RIPPLE_PROTOCOL_JSONFIELDS_H_INCLUDED
#include <ripple/json/json_value.h>
namespace ripple {
namespace jss {

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_PROTOCOL_PROTOCOL_H_INCLUDED
#define RIPPLE_PROTOCOL_PROTOCOL_H_INCLUDED
#include <ripple/types/base_uint.h>
#include <ripple/basics/base_uint.h>
#include <cstdint>
namespace ripple {

View File

@@ -22,8 +22,8 @@
#include <ripple/crypto/Base58Data.h>
#include <ripple/crypto/ECDSACanonical.h>
#include <ripple/types/RipplePublicKey.h>
#include <ripple/types/UInt160.h>
#include <ripple/protocol/RipplePublicKey.h>
#include <ripple/protocol/UInt160.h>
#include <ripple/protocol/UintTypes.h>
namespace ripple {

View File

@@ -0,0 +1,31 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_RIPPLELEDGERHASH_H_INCLUDED
#define RIPPLE_PROTOCOL_RIPPLELEDGERHASH_H_INCLUDED
#include <ripple/basics/base_uint.h>
namespace ripple {
using LedgerHash = uint256;
}
#endif

View File

@@ -0,0 +1,100 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_RIPPLEPUBLICKEY_H_INCLUDED
#define RIPPLE_PROTOCOL_RIPPLEPUBLICKEY_H_INCLUDED
#include <ripple/crypto/Base58.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <iterator>
#include <ostream>
#include <stdexcept>
#include <beast/cxx14/type_traits.h> // <type_traits>
namespace ripple {
// Simplified public key that avoids the complexities of RippleAddress
class RipplePublicKey
{
private:
std::array<std::uint8_t, 33> data_;
public:
/** Construct from a range of unsigned char. */
template <class FwdIt, class = std::enable_if_t<std::is_same<unsigned char,
typename std::iterator_traits<FwdIt>::value_type>::value>>
RipplePublicKey (FwdIt first, FwdIt last);
template <class = void>
std::string
to_string() const;
friend
bool
operator< (RipplePublicKey const& lhs, RipplePublicKey const& rhs)
{
return lhs.data_ < rhs.data_;
}
friend
bool
operator== (RipplePublicKey const& lhs, RipplePublicKey const& rhs)
{
return lhs.data_ == rhs.data_;
}
};
template <class FwdIt, class>
RipplePublicKey::RipplePublicKey (FwdIt first, FwdIt last)
{
assert(std::distance(first, last) == data_.size());
// VFALCO TODO Use 4-arg copy from C++14
std::copy (first, last, data_.begin());
}
template <class>
std::string
RipplePublicKey::to_string() const
{
// The expanded form of the key is:
// <type> <key> <checksum>
std::array <std::uint8_t, 1 + 33 + 4> e;
e[0] = 28; // node public key type
std::copy (data_.begin(), data_.end(), e.begin() + 1);
Base58::fourbyte_hash256 (&*(e.begin() + 34), e.data(), 34);
// Convert key + checksum to little endian with an extra pad byte
std::array <std::uint8_t, 4 + 33 + 1 + 1> le;
std::reverse_copy (e.begin(), e.end(), le.begin());
le.back() = 0; // make BIGNUM positive
return Base58::raw_encode (le.data(),
le.data() + le.size(), Base58::getRippleAlphabet());
}
inline
std::ostream&
operator<< (std::ostream& os, RipplePublicKey const& k)
{
return os << k.to_string();
}
}
#endif

View File

@@ -23,7 +23,7 @@
#include <ripple/protocol/SField.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/STBase.h>
#include <ripple/types/Issue.h>
#include <ripple/protocol/Issue.h>
#include <beast/cxx14/memory.h> // <memory>
namespace ripple {

View File

@@ -22,7 +22,7 @@
#include <ripple/basics/byte_view.h>
#include <ripple/protocol/SField.h>
#include <ripple/types/base_uint.h>
#include <ripple/basics/base_uint.h>
#include <iomanip>
#include <sstream>

View File

@@ -0,0 +1,67 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_CORE_SYSTEMPARAMETERS_H_INCLUDED
#define RIPPLE_CORE_SYSTEMPARAMETERS_H_INCLUDED
#include <cstdint>
namespace ripple {
/** Various protocol and system specific constant globals. */
/* The name of the system. */
static inline
std::string const&
systemName ()
{
static std::string const name = "ripple";
return name;
}
/** Configure the native currency. */
static
std::uint64_t const
SYSTEM_CURRENCY_GIFT = 1000;
static
std::uint64_t const
SYSTEM_CURRENCY_USERS = 100000000;
static
std::uint64_t const
SYSTEM_CURRENCY_PARTS = 1000000;
/** Calculate the amount of native currency created at genesis. */
static
std::uint64_t const
SYSTEM_CURRENCY_START = SYSTEM_CURRENCY_GIFT * SYSTEM_CURRENCY_USERS * SYSTEM_CURRENCY_PARTS;
/* The currency code for the native currency. */
static inline
std::string const&
systemCurrencyCode ()
{
static std::string const code = "XRP";
return code;
}
} // ripple
#endif

View File

@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2011 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef RIPPLE_PROTOCOL_UINT160_H_INCLUDED
#define RIPPLE_PROTOCOL_UINT160_H_INCLUDED
#include <ripple/basics/base_uint.h>
#include <ripple/basics/strHex.h>
#include <boost/functional/hash.hpp>
#include <functional>
namespace ripple {
template <class Tag>
uint256 to256 (base_uint<160, Tag> const& a)
{
uint256 m;
memcpy (m.begin (), a.begin (), a.size ());
return m;
}
}
//------------------------------------------------------------------------------
namespace std {
template <>
struct hash <ripple::uint160> : ripple::uint160::hasher
{
// VFALCO NOTE broken in vs2012
//using ripple::uint160::hasher::hasher; // inherit ctors
};
}
//------------------------------------------------------------------------------
namespace boost {
template <>
struct hash <ripple::uint160> : ripple::uint160::hasher
{
// VFALCO NOTE broken in vs2012
//using ripple::uint160::hasher::hasher; // inherit ctors
};
}
#endif

View File

@@ -17,11 +17,11 @@
*/
//==============================================================================
#ifndef RIPPLE_TYPES_BASICS
#define RIPPLE_TYPES_BASICS
#ifndef RIPPLE_PROTOCOL_BASICS
#define RIPPLE_PROTOCOL_BASICS
#include <ripple/basics/UnorderedContainers.h>
#include <ripple/types/base_uint.h>
#include <ripple/basics/base_uint.h>
namespace ripple {
namespace detail {

View File

@@ -0,0 +1,541 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2011 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef RIPPLE_BASICS_BASE_UINT_H_INCLUDED
#define RIPPLE_BASICS_BASE_UINT_H_INCLUDED
#include <ripple/basics/ByteOrder.h>
#include <ripple/basics/Blob.h>
#include <ripple/basics/strHex.h>
#include <beast/container/hardened_hash.h>
#include <beast/utility/Zero.h>
#include <boost/functional/hash.hpp>
#include <functional>
using beast::zero;
using beast::Zero;
namespace ripple {
// This class stores its values internally in big-endian form
template <std::size_t Bits, class Tag = void>
class base_uint
{
static_assert ((Bits % 32) == 0,
"The length of a base_uint in bits must be a multiple of 32.");
static_assert (Bits >= 64,
"The length of a base_uint in bits must be at least 64.");
protected:
enum { WIDTH = Bits / 32 };
// This is really big-endian in byte order.
// We sometimes use unsigned int for speed.
// NIKB TODO: migrate to std::array
unsigned int pn[WIDTH];
public:
//--------------------------------------------------------------------------
//
// STL Container Interface
//
static std::size_t const bytes = Bits / 8;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef unsigned char value_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef value_type const* const_pointer;
typedef value_type const& const_reference;
typedef pointer iterator;
typedef const_pointer const_iterator;
typedef std::reverse_iterator
<iterator> reverse_iterator;
typedef std::reverse_iterator
<const_iterator> const_reverse_iterator;
typedef Tag tag_type;
pointer data() { return reinterpret_cast<pointer>(pn); }
const_pointer data() const { return reinterpret_cast<const_pointer>(pn); }
iterator begin() { return data(); }
iterator end() { return data()+bytes; }
const_iterator begin() const { return data(); }
const_iterator end() const { return data()+bytes; }
const_iterator cbegin() const { return data(); }
const_iterator cend() const { return data()+bytes; }
/** Value hashing function.
The seed prevents crafted inputs from causing degenarate parent containers.
*/
typedef beast::hardened_hash <> hasher;
/** Container equality testing function. */
class key_equal
{
public:
bool operator() (base_uint const& lhs, base_uint const& rhs) const
{
return lhs == rhs;
}
};
//--------------------------------------------------------------------------
private:
/** Construct from a raw pointer.
The buffer pointed to by `data` must be at least Bits/8 bytes.
@note the structure is used to disambiguate this from the std::uint64_t
constructor: something like base_uint(0) is ambiguous.
*/
// NIKB TODO Remove the need for this constructor.
struct VoidHelper {};
explicit base_uint (void const* data, VoidHelper)
{
memcpy (&pn [0], data, bytes);
}
public:
base_uint () { *this = beast::zero; }
explicit base_uint (Blob const& vch)
{
assert (vch.size () == size ());
if (vch.size () == size ())
memcpy (pn, &vch[0], size ());
else
*this = beast::zero;
}
explicit base_uint (std::uint64_t b)
{
*this = b;
}
// NIKB TODO remove the need for this constructor - have a free function
// to handle the hex string parsing.
explicit base_uint (std::string const& str)
{
SetHex (str);
}
base_uint (base_uint<Bits, Tag> const& other) = default;
template <class OtherTag>
void copyFrom (base_uint<Bits, OtherTag> const& other)
{
memcpy (&pn [0], other.data(), bytes);
}
/* Construct from a raw pointer.
The buffer pointed to by `data` must be at least Bits/8 bytes.
*/
static base_uint
fromVoid (void const* data)
{
return base_uint (data, VoidHelper ());
}
int signum() const
{
for (int i = 0; i < WIDTH; i++)
if (pn[i] != 0)
return 1;
return 0;
}
bool operator! () const
{
return *this == beast::zero;
}
const base_uint operator~ () const
{
base_uint ret;
for (int i = 0; i < WIDTH; i++)
ret.pn[i] = ~pn[i];
return ret;
}
base_uint& operator= (const base_uint& b)
{
for (int i = 0; i < WIDTH; i++)
pn[i] = b.pn[i];
return *this;
}
base_uint& operator= (std::uint64_t uHost)
{
*this = beast::zero;
// Put in least significant bits.
((std::uint64_t*) end ())[-1] = htobe64 (uHost);
return *this;
}
base_uint& operator^= (const base_uint& b)
{
for (int i = 0; i < WIDTH; i++)
pn[i] ^= b.pn[i];
return *this;
}
base_uint& operator&= (const base_uint& b)
{
for (int i = 0; i < WIDTH; i++)
pn[i] &= b.pn[i];
return *this;
}
base_uint& operator|= (const base_uint& b)
{
for (int i = 0; i < WIDTH; i++)
pn[i] |= b.pn[i];
return *this;
}
base_uint& operator++ ()
{
// prefix operator
for (int i = WIDTH - 1; i >= 0; --i)
{
pn[i] = htobe32 (be32toh (pn[i]) + 1);
if (pn[i] != 0)
break;
}
return *this;
}
const base_uint operator++ (int)
{
// postfix operator
const base_uint ret = *this;
++ (*this);
return ret;
}
base_uint& operator-- ()
{
for (int i = WIDTH - 1; i >= 0; --i)
{
std::uint32_t prev = pn[i];
pn[i] = htobe32 (be32toh (pn[i]) - 1);
if (prev != 0)
break;
}
return *this;
}
const base_uint operator-- (int)
{
// postfix operator
const base_uint ret = *this;
-- (*this);
return ret;
}
base_uint& operator+= (const base_uint& b)
{
std::uint64_t carry = 0;
for (int i = WIDTH; i--;)
{
std::uint64_t n = carry + be32toh (pn[i]) + be32toh (b.pn[i]);
pn[i] = htobe32 (n & 0xffffffff);
carry = n >> 32;
}
return *this;
}
template <class Hasher>
friend void hash_append(Hasher& h, base_uint const& a) noexcept
{
using beast::hash_append;
hash_append (h, a.pn);
}
bool SetHexExact (const char* psz)
{
// must be precisely the correct number of hex digits
unsigned char* pOut = begin ();
for (int i = 0; i < sizeof (pn); ++i)
{
auto cHigh = charUnHex(*psz++);
auto cLow = charUnHex(*psz++);
if (cHigh == -1 || cLow == -1)
return false;
*pOut++ = (cHigh << 4) | cLow;
}
assert (*psz == 0);
assert (pOut == end ());
return true;
}
// Allow leading whitespace.
// Allow leading "0x".
// To be valid must be '\0' terminated.
bool SetHex (const char* psz, bool bStrict = false)
{
// skip leading spaces
if (!bStrict)
while (isspace (*psz))
psz++;
// skip 0x
if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x')
psz += 2;
const unsigned char* pEnd = reinterpret_cast<const unsigned char*> (psz);
const unsigned char* pBegin = pEnd;
// Find end.
while (charUnHex(*pEnd) != -1)
pEnd++;
// Take only last digits of over long string.
if ((unsigned int) (pEnd - pBegin) > 2 * size ())
pBegin = pEnd - 2 * size ();
unsigned char* pOut = end () - ((pEnd - pBegin + 1) / 2);
*this = beast::zero;
if ((pEnd - pBegin) & 1)
*pOut++ = charUnHex(*pBegin++);
while (pBegin != pEnd)
{
auto cHigh = charUnHex(*pBegin++);
auto cLow = pBegin == pEnd
? 0
: charUnHex(*pBegin++);
if (cHigh == -1 || cLow == -1)
return false;
*pOut++ = (cHigh << 4) | cLow;
}
return !*pEnd;
}
bool SetHex (std::string const& str, bool bStrict = false)
{
return SetHex (str.c_str (), bStrict);
}
void SetHexExact (std::string const& str)
{
SetHexExact (str.c_str ());
}
unsigned int size () const
{
return sizeof (pn);
}
base_uint<Bits, Tag>& operator=(Zero)
{
memset (&pn[0], 0, sizeof (pn));
return *this;
}
// Deprecated.
bool isZero () const { return *this == beast::zero; }
bool isNonZero () const { return *this != beast::zero; }
void zero () { *this = beast::zero; }
};
typedef base_uint<128> uint128;
typedef base_uint<160> uint160;
typedef base_uint<256> uint256;
template <std::size_t Bits, class Tag>
inline int compare (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
auto ret = std::mismatch (a.cbegin (), a.cend (), b.cbegin ());
if (ret.first == a.cend ())
return 0;
// a > b
if (*ret.first > *ret.second)
return 1;
// a < b
return -1;
}
template <std::size_t Bits, class Tag>
inline bool operator< (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare (a, b) < 0;
}
template <std::size_t Bits, class Tag>
inline bool operator<= (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare (a, b) <= 0;
}
template <std::size_t Bits, class Tag>
inline bool operator> (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare (a, b) > 0;
}
template <std::size_t Bits, class Tag>
inline bool operator>= (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare (a, b) >= 0;
}
template <std::size_t Bits, class Tag>
inline bool operator== (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare (a, b) == 0;
}
template <std::size_t Bits, class Tag>
inline bool operator!= (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return compare (a, b) != 0;
}
//------------------------------------------------------------------------------
template <std::size_t Bits, class Tag>
inline bool operator== (base_uint<Bits, Tag> const& a, std::uint64_t b)
{
return a == base_uint<Bits, Tag>(b);
}
template <std::size_t Bits, class Tag>
inline bool operator!= (base_uint<Bits, Tag> const& a, std::uint64_t b)
{
return !(a == b);
}
//------------------------------------------------------------------------------
template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag> operator^ (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag> (a) ^= b;
}
template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag> operator& (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag> (a) &= b;
}
template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag> operator| (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag> (a) |= b;
}
template <std::size_t Bits, class Tag>
inline const base_uint<Bits, Tag> operator+ (
base_uint<Bits, Tag> const& a, base_uint<Bits, Tag> const& b)
{
return base_uint<Bits, Tag> (a) += b;
}
//------------------------------------------------------------------------------
template <std::size_t Bits, class Tag>
inline std::string to_string (base_uint<Bits, Tag> const& a)
{
return strHex (a.begin (), a.size ());
}
template <std::size_t Bits, class Tag>
inline std::ostream& operator<< (
std::ostream& out, base_uint<Bits, Tag> const& u)
{
return out << to_string (u);
}
} // rippled
namespace boost
{
template <std::size_t Bits, class Tag>
struct hash<ripple::base_uint<Bits, Tag>>
{
using argument_type = ripple::base_uint<Bits, Tag>;
std::size_t
operator()(argument_type const& u) const
{
return beast::hardened_hash<>{}(u);
}
};
} // boost
#endif

View File

@@ -0,0 +1,72 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifdef BEAST_WIN32
#include <Winsock2.h>
// <Winsock2.h> defines min, max and does other stupid things
# ifdef max
# undef max
# endif
# ifdef min
# undef min
# endif
#endif
namespace ripple {
#if BEAST_WIN32
// from: http://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c
// but we don't need to check the endianness
std::uint64_t htobe64 (uint64_t value)
{
// The answer is 42
//static const int num = 42;
// Check the endianness
//if (*reinterpret_cast<const char*>(&num) == num)
//{
const uint32_t high_part = htonl (static_cast<uint32_t> (value >> 32));
const uint32_t low_part = htonl (static_cast<uint32_t> (value & 0xFFFFFFFFLL));
return (static_cast<uint64_t> (low_part) << 32) | high_part;
//} else
//{
// return value;
//}
}
std::uint64_t be64toh (uint64_t value)
{
return (_byteswap_uint64 (value));
}
std::uint32_t htobe32 (uint32_t value)
{
return (htonl (value));
}
std::uint32_t be32toh (uint32_t value)
{
return ( _byteswap_ulong (value));
}
#endif
}

View File

@@ -0,0 +1,174 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/ErrorCodes.h>
#include <unordered_map>
#include <utility>
namespace std {
template <>
struct hash <ripple::error_code_i>
{
std::size_t operator() (ripple::error_code_i value) const
{
return value;
}
};
}
namespace ripple {
namespace RPC {
namespace detail {
class ErrorCategory
{
public:
using Map = std::unordered_map <error_code_i, ErrorInfo> ;
ErrorCategory ()
: m_unknown (rpcUNKNOWN, "unknown", "An unknown error code.")
{
add (rpcACT_BITCOIN, "actBitcoin", "Account is bitcoin address.");
add (rpcACT_EXISTS, "actExists", "Account already exists.");
add (rpcACT_MALFORMED, "actMalformed", "Account malformed.");
add (rpcACT_NOT_FOUND, "actNotFound", "Account not found.");
add (rpcATX_DEPRECATED, "deprecated", "Use the new API or specify a ledger range.");
add (rpcBAD_BLOB, "badBlob", "Blob must be a non-empty hex string.");
add (rpcBAD_FEATURE, "badFeature", "Feature unknown or invalid.");
add (rpcBAD_ISSUER, "badIssuer", "Issuer account malformed.");
add (rpcBAD_MARKET, "badMarket", "No such market.");
add (rpcBAD_SECRET, "badSecret", "Secret does not match account.");
add (rpcBAD_SEED, "badSeed", "Disallowed seed.");
add (rpcBAD_SYNTAX, "badSyntax", "Syntax error.");
add (rpcCOMMAND_MISSING, "commandMissing", "Missing command entry.");
add (rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed.");
add (rpcDST_ACT_MISSING, "dstActMissing", "Destination account does not exist.");
add (rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed.");
add (rpcDST_ISR_MALFORMED, "dstIsrMalformed", "Destination issuer is malformed.");
add (rpcFAIL_GEN_DECRYPT, "failGenDecrypt", "Failed to decrypt generator.");
add (rpcFORBIDDEN, "forbidden", "Bad credentials.");
add (rpcGENERAL, "general", "Generic error reason.");
add (rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed.");
add (rpcGETS_AMT_MALFORMED, "getsAmtMalformed", "Gets amount malformed.");
add (rpcHIGH_FEE, "highFee", "Current transaction fee exceeds your limit.");
add (rpcHOST_IP_MALFORMED, "hostIpMalformed", "Host IP is malformed.");
add (rpcINSUF_FUNDS, "insufFunds", "Insufficient funds.");
add (rpcINTERNAL, "internal", "Internal error.");
add (rpcINVALID_PARAMS, "invalidParams", "Invalid parameters.");
add (rpcJSON_RPC, "json_rpc", "JSON-RPC transport error.");
add (rpcLGR_IDXS_INVALID, "lgrIdxsInvalid", "Ledger indexes invalid.");
add (rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed.");
add (rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found.");
add (rpcLOAD_FAILED, "loadFailed", "Load failed");
add (rpcMASTER_DISABLED, "masterDisabled", "Master key is disabled.");
add (rpcNOT_ENABLED, "notEnabled", "Not enabled in configuration.");
add (rpcNOT_IMPL, "notImpl", "Not implemented.");
add (rpcNOT_READY, "notReady", "Not ready to handle this request.");
add (rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only.");
add (rpcNOT_SUPPORTED, "notSupported", "Operation not supported.");
add (rpcNO_ACCOUNT, "noAccount", "No such account.");
add (rpcNO_CLOSED, "noClosed", "Closed ledger is unavailable.");
add (rpcNO_CURRENT, "noCurrent", "Current ledger is unavailable.");
add (rpcNO_EVENTS, "noEvents", "Current transport does not support events.");
add (rpcNO_GEN_DECRYPT, "noGenDecrypt", "Password failed to decrypt master public generator.");
add (rpcNO_NETWORK, "noNetwork", "Not synced to Ripple network.");
add (rpcNO_PATH, "noPath", "Unable to find a ripple path.");
add (rpcNO_PERMISSION, "noPermission", "You don't have permission for this command.");
add (rpcNO_PF_REQUEST, "noPathRequest", "No pathfinding request in progress.");
add (rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed.");
add (rpcPAYS_ACT_MALFORMED, "paysActMalformed", "Pays account malformed.");
add (rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed.");
add (rpcPORT_MALFORMED, "portMalformed", "Port is malformed.");
add (rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed.");
add (rpcQUALITY_MALFORMED, "qualityMalformed", "Quality malformed.");
add (rpcSLOW_DOWN, "slowDown", "You are placing too much load on the server.");
add (rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed.");
add (rpcSRC_ACT_MISSING, "srcActMissing", "Source account not provided.");
add (rpcSRC_ACT_NOT_FOUND, "srcActNotFound", "Source account not found.");
add (rpcSRC_AMT_MALFORMED, "srcAmtMalformed", "Source amount/currency/issuer is malformed.");
add (rpcSRC_CUR_MALFORMED, "srcCurMalformed", "Source currency is malformed.");
add (rpcSRC_ISR_MALFORMED, "srcIsrMalformed", "Source issuer is malformed.");
add (rpcSRC_MISSING, "srcMissing", "Source is missing.");
add (rpcSRC_UNCLAIMED, "srcUnclaimed", "Source account is not claimed.");
add (rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now.");
add (rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found.");
add (rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method.");
add (rpcWRONG_SEED, "wrongSeed", "The regular key does not point as the master key.");
}
ErrorInfo const& get (error_code_i code) const
{
Map::const_iterator const iter (m_map.find (code));
if (iter != m_map.end())
return iter->second;
return m_unknown;
}
private:
void add (error_code_i code, std::string const& token,
std::string const& message)
{
std::pair <Map::iterator, bool> result (
m_map.emplace (std::piecewise_construct,
std::forward_as_tuple (code), std::forward_as_tuple (
code, token, message)));
if (! result.second)
throw std::invalid_argument ("duplicate error code");
}
private:
Map m_map;
ErrorInfo m_unknown;
};
}
//------------------------------------------------------------------------------
ErrorInfo const& get_error_info (error_code_i code)
{
static detail::ErrorCategory category;
return category.get (code);
}
Json::Value make_error (error_code_i code)
{
Json::Value json;
inject_error (code, json);
return json;
}
Json::Value make_error (error_code_i code, std::string const& message)
{
Json::Value json;
inject_error (code, message, json);
return json;
}
bool contains_error (Json::Value const& json)
{
if (json.isObject() && json.isMember ("error"))
return true;
return false;
}
}
}

View File

@@ -0,0 +1,493 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/basics/UnorderedContainers.h>
#include <ripple/protocol/Book.h>
#include <ripple/protocol/Issue.h>
#include <beast/unit_test/suite.h>
#include <map>
#include <set>
#include <typeinfo>
#include <unordered_set>
#if BEAST_MSVC
# define STL_SET_HAS_EMPLACE 1
#else
# define STL_SET_HAS_EMPLACE 0
#endif
#ifndef RIPPLE_ASSETS_ENABLE_STD_HASH
# if BEAST_MAC || BEAST_IOS
# define RIPPLE_ASSETS_ENABLE_STD_HASH 0
# else
# define RIPPLE_ASSETS_ENABLE_STD_HASH 1
# endif
#endif
namespace ripple {
class Issue_test : public beast::unit_test::suite
{
public:
// Comparison, hash tests for uint60 (via base_uint)
template <typename Unsigned>
void testUnsigned ()
{
Unsigned const u1 (1);
Unsigned const u2 (2);
Unsigned const u3 (3);
expect (u1 != u2);
expect (u1 < u2);
expect (u1 <= u2);
expect (u2 <= u2);
expect (u2 == u2);
expect (u2 >= u2);
expect (u3 >= u2);
expect (u3 > u2);
std::hash <Unsigned> hash;
expect (hash (u1) == hash (u1));
expect (hash (u2) == hash (u2));
expect (hash (u3) == hash (u3));
expect (hash (u1) != hash (u2));
expect (hash (u1) != hash (u3));
expect (hash (u2) != hash (u3));
}
//--------------------------------------------------------------------------
// Comparison, hash tests for IssueType
template <class Issue>
void testIssueType ()
{
Currency const c1 (1); Account const i1 (1);
Currency const c2 (2); Account const i2 (2);
Currency const c3 (3); Account const i3 (3);
expect (Issue (c1, i1) != Issue (c2, i1));
expect (Issue (c1, i1) < Issue (c2, i1));
expect (Issue (c1, i1) <= Issue (c2, i1));
expect (Issue (c2, i1) <= Issue (c2, i1));
expect (Issue (c2, i1) == Issue (c2, i1));
expect (Issue (c2, i1) >= Issue (c2, i1));
expect (Issue (c3, i1) >= Issue (c2, i1));
expect (Issue (c3, i1) > Issue (c2, i1));
expect (Issue (c1, i1) != Issue (c1, i2));
expect (Issue (c1, i1) < Issue (c1, i2));
expect (Issue (c1, i1) <= Issue (c1, i2));
expect (Issue (c1, i2) <= Issue (c1, i2));
expect (Issue (c1, i2) == Issue (c1, i2));
expect (Issue (c1, i2) >= Issue (c1, i2));
expect (Issue (c1, i3) >= Issue (c1, i2));
expect (Issue (c1, i3) > Issue (c1, i2));
std::hash <Issue> hash;
expect (hash (Issue (c1, i1)) == hash (Issue (c1, i1)));
expect (hash (Issue (c1, i2)) == hash (Issue (c1, i2)));
expect (hash (Issue (c1, i3)) == hash (Issue (c1, i3)));
expect (hash (Issue (c2, i1)) == hash (Issue (c2, i1)));
expect (hash (Issue (c2, i2)) == hash (Issue (c2, i2)));
expect (hash (Issue (c2, i3)) == hash (Issue (c2, i3)));
expect (hash (Issue (c3, i1)) == hash (Issue (c3, i1)));
expect (hash (Issue (c3, i2)) == hash (Issue (c3, i2)));
expect (hash (Issue (c3, i3)) == hash (Issue (c3, i3)));
expect (hash (Issue (c1, i1)) != hash (Issue (c1, i2)));
expect (hash (Issue (c1, i1)) != hash (Issue (c1, i3)));
expect (hash (Issue (c1, i1)) != hash (Issue (c2, i1)));
expect (hash (Issue (c1, i1)) != hash (Issue (c2, i2)));
expect (hash (Issue (c1, i1)) != hash (Issue (c2, i3)));
expect (hash (Issue (c1, i1)) != hash (Issue (c3, i1)));
expect (hash (Issue (c1, i1)) != hash (Issue (c3, i2)));
expect (hash (Issue (c1, i1)) != hash (Issue (c3, i3)));
}
template <class Set>
void testIssueSet ()
{
Currency const c1 (1);
Account const i1 (1);
Currency const c2 (2);
Account const i2 (2);
IssueRef const a1 (c1, i1);
IssueRef const a2 (c2, i2);
{
Set c;
c.insert (a1);
if (! expect (c.size () == 1)) return;
c.insert (a2);
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
if (! expect (c.empty ())) return;
}
{
Set c;
c.insert (a1);
if (! expect (c.size () == 1)) return;
c.insert (a2);
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return;
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return;
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return;
if (! expect (c.empty ())) return;
#if STL_SET_HAS_EMPLACE
c.emplace (c1, i1);
if (! expect (c.size() == 1)) return;
c.emplace (c2, i2);
if (! expect (c.size() == 2)) return;
#endif
}
}
template <class Map>
void testIssueMap ()
{
Currency const c1 (1);
Account const i1 (1);
Currency const c2 (2);
Account const i2 (2);
IssueRef const a1 (c1, i1);
IssueRef const a2 (c2, i2);
{
Map c;
c.insert (std::make_pair (a1, 1));
if (! expect (c.size () == 1)) return;
c.insert (std::make_pair (a2, 2));
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
if (! expect (c.empty ())) return;
}
{
Map c;
c.insert (std::make_pair (a1, 1));
if (! expect (c.size () == 1)) return;
c.insert (std::make_pair (a2, 2));
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return;
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return;
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return;
if (! expect (c.empty ())) return;
}
}
void testIssueSets ()
{
testcase ("std::set <Issue>");
testIssueSet <std::set <Issue>> ();
testcase ("std::set <IssueRef>");
testIssueSet <std::set <IssueRef>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_set <Issue>");
testIssueSet <std::unordered_set <Issue>> ();
testcase ("std::unordered_set <IssueRef>");
testIssueSet <std::unordered_set <IssueRef>> ();
#endif
testcase ("hash_set <Issue>");
testIssueSet <hash_set <Issue>> ();
testcase ("hash_set <IssueRef>");
testIssueSet <hash_set <IssueRef>> ();
}
void testIssueMaps ()
{
testcase ("std::map <Issue, int>");
testIssueMap <std::map <Issue, int>> ();
testcase ("std::map <IssueRef, int>");
testIssueMap <std::map <IssueRef, int>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_map <Issue, int>");
testIssueMap <std::unordered_map <Issue, int>> ();
testcase ("std::unordered_map <IssueRef, int>");
testIssueMap <std::unordered_map <IssueRef, int>> ();
testcase ("hash_map <Issue, int>");
testIssueMap <hash_map <Issue, int>> ();
testcase ("hash_map <IssueRef, int>");
testIssueMap <hash_map <IssueRef, int>> ();
#endif
}
//--------------------------------------------------------------------------
// Comparison, hash tests for BookType
template <class Book>
void testBook ()
{
Currency const c1 (1); Account const i1 (1);
Currency const c2 (2); Account const i2 (2);
Currency const c3 (3); Account const i3 (3);
Issue a1 (c1, i1);
Issue a2 (c1, i2);
Issue a3 (c2, i2);
Issue a4 (c3, i2);
expect (Book (a1, a2) != Book (a2, a3));
expect (Book (a1, a2) < Book (a2, a3));
expect (Book (a1, a2) <= Book (a2, a3));
expect (Book (a2, a3) <= Book (a2, a3));
expect (Book (a2, a3) == Book (a2, a3));
expect (Book (a2, a3) >= Book (a2, a3));
expect (Book (a3, a4) >= Book (a2, a3));
expect (Book (a3, a4) > Book (a2, a3));
std::hash <Book> hash;
// log << std::hex << hash (Book (a1, a2));
// log << std::hex << hash (Book (a1, a2));
//
// log << std::hex << hash (Book (a1, a3));
// log << std::hex << hash (Book (a1, a3));
//
// log << std::hex << hash (Book (a1, a4));
// log << std::hex << hash (Book (a1, a4));
//
// log << std::hex << hash (Book (a2, a3));
// log << std::hex << hash (Book (a2, a3));
//
// log << std::hex << hash (Book (a2, a4));
// log << std::hex << hash (Book (a2, a4));
//
// log << std::hex << hash (Book (a3, a4));
// log << std::hex << hash (Book (a3, a4));
expect (hash (Book (a1, a2)) == hash (Book (a1, a2)));
expect (hash (Book (a1, a3)) == hash (Book (a1, a3)));
expect (hash (Book (a1, a4)) == hash (Book (a1, a4)));
expect (hash (Book (a2, a3)) == hash (Book (a2, a3)));
expect (hash (Book (a2, a4)) == hash (Book (a2, a4)));
expect (hash (Book (a3, a4)) == hash (Book (a3, a4)));
expect (hash (Book (a1, a2)) != hash (Book (a1, a3)));
expect (hash (Book (a1, a2)) != hash (Book (a1, a4)));
expect (hash (Book (a1, a2)) != hash (Book (a2, a3)));
expect (hash (Book (a1, a2)) != hash (Book (a2, a4)));
expect (hash (Book (a1, a2)) != hash (Book (a3, a4)));
}
//--------------------------------------------------------------------------
template <class Set>
void testBookSet ()
{
Currency const c1 (1);
Account const i1 (1);
Currency const c2 (2);
Account const i2 (2);
IssueRef const a1 (c1, i1);
IssueRef const a2 (c2, i2);
BookRef const b1 (a1, a2);
BookRef const b2 (a2, a1);
{
Set c;
c.insert (b1);
if (! expect (c.size () == 1)) return;
c.insert (b2);
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (Book (a1, a1)) == 0)) return;
if (! expect (c.erase (Book (a1, a2)) == 1)) return;
if (! expect (c.erase (Book (a2, a1)) == 1)) return;
if (! expect (c.empty ())) return;
}
{
Set c;
c.insert (b1);
if (! expect (c.size () == 1)) return;
c.insert (b2);
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return;
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return;
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return;
if (! expect (c.empty ())) return;
#if STL_SET_HAS_EMPLACE
c.emplace (a1, a2);
if (! expect (c.size() == 1)) return;
c.emplace (a2, a1);
if (! expect (c.size() == 2)) return;
#endif
}
}
template <class Map>
void testBookMap ()
{
Currency const c1 (1);
Account const i1 (1);
Currency const c2 (2);
Account const i2 (2);
IssueRef const a1 (c1, i1);
IssueRef const a2 (c2, i2);
BookRef const b1 (a1, a2);
BookRef const b2 (a2, a1);
//typename Map::value_type value_type;
//std::pair <BookRef const, int> value_type;
{
Map c;
//c.insert (value_type (b1, 1));
c.insert (std::make_pair (b1, 1));
if (! expect (c.size () == 1)) return;
//c.insert (value_type (b2, 2));
c.insert (std::make_pair (b2, 1));
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (Book (a1, a1)) == 0)) return;
if (! expect (c.erase (Book (a1, a2)) == 1)) return;
if (! expect (c.erase (Book (a2, a1)) == 1)) return;
if (! expect (c.empty ())) return;
}
{
Map c;
//c.insert (value_type (b1, 1));
c.insert (std::make_pair (b1, 1));
if (! expect (c.size () == 1)) return;
//c.insert (value_type (b2, 2));
c.insert (std::make_pair (b2, 1));
if (! expect (c.size () == 2)) return;
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return;
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return;
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return;
if (! expect (c.empty ())) return;
}
}
void testBookSets ()
{
testcase ("std::set <Book>");
testBookSet <std::set <Book>> ();
testcase ("std::set <BookRef>");
testBookSet <std::set <BookRef>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_set <Book>");
testBookSet <std::unordered_set <Book>> ();
testcase ("std::unordered_set <BookRef>");
testBookSet <std::unordered_set <BookRef>> ();
#endif
testcase ("hash_set <Book>");
testBookSet <hash_set <Book>> ();
testcase ("hash_set <BookRef>");
testBookSet <hash_set <BookRef>> ();
}
void testBookMaps ()
{
testcase ("std::map <Book, int>");
testBookMap <std::map <Book, int>> ();
testcase ("std::map <BookRef, int>");
testBookMap <std::map <BookRef, int>> ();
#if RIPPLE_ASSETS_ENABLE_STD_HASH
testcase ("std::unordered_map <Book, int>");
testBookMap <std::unordered_map <Book, int>> ();
testcase ("std::unordered_map <BookRef, int>");
testBookMap <std::unordered_map <BookRef, int>> ();
testcase ("hash_map <Book, int>");
testBookMap <hash_map <Book, int>> ();
testcase ("hash_map <BookRef, int>");
testBookMap <hash_map <BookRef, int>> ();
#endif
}
//--------------------------------------------------------------------------
void run()
{
testcase ("Currency");
testUnsigned <Currency> ();
testcase ("Account");
testUnsigned <Account> ();
// ---
testcase ("Issue");
testIssueType <Issue> ();
testcase ("IssueRef");
testIssueType <IssueRef> ();
testIssueSets ();
testIssueMaps ();
// ---
testcase ("Book");
testBook <Book> ();
testcase ("BookRef");
testBook <BookRef> ();
testBookSets ();
testBookMaps ();
}
};
BEAST_DEFINE_TESTSUITE(Issue,types,ripple);
}

View File

@@ -26,7 +26,7 @@
#include <ripple/crypto/RFC1751.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/types/RipplePublicKey.h>
#include <ripple/protocol/RipplePublicKey.h>
#include <beast/unit_test/suite.h>
#include <openssl/ripemd.h>
#include <openssl/bn.h>
@@ -957,6 +957,17 @@ public:
= naAccountPrivate1.accountPrivateDecrypt (naAccountPublic0, vucTextCipher);
expect (vucTextSrc == vucTextRecovered, "Encrypt-decrypt failed.");
{
RippleAddress nSeed;
uint128 seed1, seed2;
seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26");
nSeed.setSeed (seed1);
expect (nSeed.humanSeed() == "shHM53KPZ87Gwdqarm1bAmPeXg8Tn",
"Incorrect human seed");
expect (nSeed.humanSeed1751() == "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH",
"Incorrect 1751 seed");
}
}
};

View File

@@ -20,7 +20,7 @@
#include <ripple/basics/Log.h>
#include <ripple/protocol/JsonFields.h>
#include <ripple/crypto/CBigNum.h>
#include <ripple/core/SystemParameters.h>
#include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/STAmount.h>
#include <ripple/protocol/UintTypes.h>
#include <beast/module/core/text/LexicalCast.h>

View File

@@ -19,7 +19,7 @@
#include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/STInteger.h>
#include <ripple/rpc/ErrorCodes.h> // VFALCO Questionable dependency
#include <ripple/protocol/ErrorCodes.h>
#include <beast/module/core/text/LexicalCast.h>
#include <cassert>

View File

@@ -17,7 +17,6 @@
*/
//==============================================================================
#include <ripple/core/Config.h>
#include <ripple/protocol/STValidation.h>
#include <ripple/protocol/HashPrefix.h>

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/core/SystemParameters.h>
#include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/UintTypes.h>

View File

@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
namespace ripple {
char charHex (int iDigit)
{
if (iDigit >= 0)
{
if(iDigit < 10)
return '0' + iDigit;
if(iDigit < 16)
return 'A' - 10 + iDigit;
}
return 0;
}
int charUnHex (unsigned char c)
{
struct HexTab
{
int hex[256];
HexTab ()
{
std::fill (std::begin (hex), std::end (hex), -1);
for (int i = 0; i < 10; ++i)
hex ['0'+i] = i;
for (int i = 0; i < 6; ++i)
{
hex ['A'+i] = 10 + i;
hex ['a'+i] = 10 + i;
}
}
int operator[] (unsigned char c) const
{
return hex[c];
}
};
static HexTab xtab;
return xtab[c];
}
}