Files
xahaud/src/test/jtx/flags.h
Scott Schurr 259394029a Support for lsfDepositAuth (RIPD-1487):
The DepositAuth feature allows an account to require that
it signs for any funds that are deposited to the account.
For the time being this limits the account to accepting
only XRP, although there are plans to allow IOU payments
in the future.

The lsfDepositAuth protections are not extended to offers.
If an account creates an offer it is in effect saying, “I
will accept funds from anyone who takes this offer.”
Therefore, the typical user of the lsfDepositAuth flag
will choose never to create any offers.  But they can if
they so choose.

The DepositAuth feature leaves a small gap in its
protections.  An XRP payment is allowed to a destination
account with the lsfDepositAuth flag set if:

- The Destination XRP balance is less than or equal to
  the base reserve and

- The value of the XRP Payment is less than or equal to
  the base reserve.

This exception is intended to make it impossible for an
account to wedge itself by spending all of its XRP on fees
and leave itself unable to pay the fee to get more XRP.

This commit

- adds featureDepositAuth,

- adds the lsfDepositAuth flag,

- adds support for lsfDepositAuth in SetAccount.cpp

- adds support in Payment.cpp for rejecting payments that
  don't meet the lsfDepositAuth requirements,

- adds unit tests for Payment transactions to an an account
  with lsfDepositAuth set.

- adds Escrow and PayChan support for lsfDepositAuth along
  with as unit tests.
2018-01-10 00:12:23 -08:00

145 lines
3.4 KiB
C++

//------------------------------------------------------------------------------
/*
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_TEST_JTX_FLAGS_H_INCLUDED
#define RIPPLE_TEST_JTX_FLAGS_H_INCLUDED
#include <test/jtx/Env.h>
#include <ripple/protocol/LedgerFormats.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/basics/contract.h>
namespace ripple {
namespace test {
namespace jtx {
// JSON generators
/** Add and/or remove flag. */
Json::Value
fset (Account const& account,
std::uint32_t on, std::uint32_t off = 0);
/** Remove account flag. */
inline
Json::Value
fclear (Account const& account,
std::uint32_t off)
{
return fset(account, 0, off);
}
namespace detail {
class flags_helper
{
protected:
std::uint32_t mask_;
private:
inline
void
set_args()
{
}
void
set_args (std::uint32_t flag)
{
switch(flag)
{
case asfRequireDest: mask_ |= lsfRequireDestTag; break;
case asfRequireAuth: mask_ |= lsfRequireAuth; break;
case asfDisallowXRP: mask_ |= lsfDisallowXRP; break;
case asfDisableMaster: mask_ |= lsfDisableMaster; break;
//case asfAccountTxnID: // ???
case asfNoFreeze: mask_ |= lsfNoFreeze; break;
case asfGlobalFreeze: mask_ |= lsfGlobalFreeze; break;
case asfDefaultRipple: mask_ |= lsfDefaultRipple; break;
case asfDepositAuth: mask_ |= lsfDepositAuth; break;
default:
Throw<std::runtime_error> (
"unknown flag");
}
}
template <class Flag,
class... Args>
void
set_args (std::uint32_t flag,
Args... args)
{
set_args(flag, args...);
}
protected:
template <class... Args>
flags_helper (Args... args)
: mask_(0)
{
set_args(args...);
}
};
} // detail
/** Match set account flags */
class flags : private detail::flags_helper
{
private:
Account account_;
public:
template <class... Args>
flags (Account const& account,
Args... args)
: flags_helper(args...)
, account_(account)
{
}
void
operator()(Env& env) const;
};
/** Match clear account flags */
class nflags : private detail::flags_helper
{
private:
Account account_;
public:
template <class... Args>
nflags (Account const& account,
Args... args)
: flags_helper(args...)
, account_(account)
{
}
void
operator()(Env& env) const;
};
} // jtx
} // test
} // ripple
#endif