rippled
flags.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_TEST_JTX_FLAGS_H_INCLUDED
21 #define RIPPLE_TEST_JTX_FLAGS_H_INCLUDED
22 
23 #include <ripple/basics/contract.h>
24 #include <ripple/protocol/LedgerFormats.h>
25 #include <ripple/protocol/TxFlags.h>
26 #include <test/jtx/Env.h>
27 
28 namespace ripple {
29 namespace test {
30 namespace jtx {
31 
32 // JSON generators
33 
36 fset(Account const& account, std::uint32_t on, std::uint32_t off = 0);
37 
39 inline Json::Value
40 fclear(Account const& account, std::uint32_t off)
41 {
42  return fset(account, 0, off);
43 }
44 
45 namespace detail {
46 
48 {
49 protected:
51 
52 private:
53  void
55  {
56  switch (flag)
57  {
58  case asfRequireDest:
60  break;
61  case asfRequireAuth:
63  break;
64  case asfDisallowXRP:
66  break;
67  case asfDisableMaster:
69  break;
70  // case asfAccountTxnID: // ???
71  case asfNoFreeze:
72  mask_ |= lsfNoFreeze;
73  break;
74  case asfGlobalFreeze:
76  break;
77  case asfDefaultRipple:
79  break;
80  case asfDepositAuth:
82  break;
83  default:
84  Throw<std::runtime_error>("unknown flag");
85  }
86  }
87 
88  template <class Flag, class... Args>
89  void
90  set_args(std::uint32_t flag, Args... args)
91  {
92  set_args(flag);
93  if constexpr (sizeof...(args))
94  set_args(args...);
95  }
96 
97 protected:
98  template <class... Args>
99  flags_helper(Args... args) : mask_(0)
100  {
101  set_args(args...);
102  }
103 };
104 
105 } // namespace detail
106 
109 {
110 private:
112 
113 public:
114  template <class... Args>
115  flags(Account const& account, Args... args)
116  : flags_helper(args...), account_(account)
117  {
118  }
119 
120  void
121  operator()(Env& env) const;
122 };
123 
126 {
127 private:
129 
130 public:
131  template <class... Args>
132  nflags(Account const& account, Args... args)
133  : flags_helper(args...), account_(account)
134  {
135  }
136 
137  void
138  operator()(Env& env) const;
139 };
140 
141 } // namespace jtx
142 } // namespace test
143 } // namespace ripple
144 
145 #endif
ripple::test::jtx::detail::flags_helper::flags_helper
flags_helper(Args... args)
Definition: flags.h:99
ripple::test::jtx::nflags::operator()
void operator()(Env &env) const
Definition: flags.cpp:51
ripple::test::jtx::flags::account_
Account account_
Definition: flags.h:111
ripple::test::jtx::detail::flags_helper::set_args
void set_args(std::uint32_t flag)
Definition: flags.h:54
ripple::asfDisallowXRP
constexpr std::uint32_t asfDisallowXRP
Definition: TxFlags.h:76
ripple::asfDepositAuth
constexpr std::uint32_t asfDepositAuth
Definition: TxFlags.h:82
ripple::lsfGlobalFreeze
@ lsfGlobalFreeze
Definition: LedgerFormats.h:231
ripple::lsfDisableMaster
@ lsfDisableMaster
Definition: LedgerFormats.h:229
ripple::test::jtx::detail::flags_helper::mask_
std::uint32_t mask_
Definition: flags.h:50
ripple::asfNoFreeze
constexpr std::uint32_t asfNoFreeze
Definition: TxFlags.h:79
ripple::test::jtx::detail::flags_helper::set_args
void set_args(std::uint32_t flag, Args... args)
Definition: flags.h:90
ripple::lsfDepositAuth
@ lsfDepositAuth
Definition: LedgerFormats.h:234
ripple::test::jtx::flags::flags
flags(Account const &account, Args... args)
Definition: flags.h:115
ripple::test::jtx::nflags::nflags
nflags(Account const &account, Args... args)
Definition: flags.h:132
ripple::test::jtx::nflags::account_
Account account_
Definition: flags.h:128
ripple::lsfRequireAuth
@ lsfRequireAuth
Definition: LedgerFormats.h:226
ripple::lsfDefaultRipple
@ lsfDefaultRipple
Definition: LedgerFormats.h:232
ripple::asfDisableMaster
constexpr std::uint32_t asfDisableMaster
Definition: TxFlags.h:77
ripple::test::jtx::fset
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:28
std::uint32_t
ripple::test::jtx::fclear
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Definition: flags.h:40
ripple::lsfRequireDestTag
@ lsfRequireDestTag
Definition: LedgerFormats.h:224
ripple::test::jtx::flags::operator()
void operator()(Env &env) const
Definition: flags.cpp:41
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::detail::flags_helper
Definition: flags.h:47
ripple::test::jtx::flags
Match set account flags.
Definition: flags.h:108
ripple::lsfNoFreeze
@ lsfNoFreeze
Definition: LedgerFormats.h:230
ripple::asfRequireAuth
constexpr std::uint32_t asfRequireAuth
Definition: TxFlags.h:75
ripple::asfDefaultRipple
constexpr std::uint32_t asfDefaultRipple
Definition: TxFlags.h:81
ripple::asfRequireDest
constexpr std::uint32_t asfRequireDest
Definition: TxFlags.h:74
ripple::test::jtx::nflags
Match clear account flags.
Definition: flags.h:125
ripple::asfGlobalFreeze
constexpr std::uint32_t asfGlobalFreeze
Definition: TxFlags.h:80
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::lsfDisallowXRP
@ lsfDisallowXRP
Definition: LedgerFormats.h:228
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
Json::Value
Represents a JSON value.
Definition: json_value.h:145