Arguments passed to jtx Env::operator() must be invocable:

Before this patch, jtx allowed non-invocable functions to be passed to
operator(). However, these arguments are ignored. This caused erronious code
code such as:

```
env (offer (account_to_test, BTC (250), XRP (1000)),
         offers (account_to_test, 1));
```

While it looks like the number of offers are checked, they are not. The `offers`
funclet is never run. While we could modify jtx to make the above code correct,
a cleaner solution is to run post conditions in a `require` statement after a
transasction runs.
This commit is contained in:
seelabs
2019-03-23 14:01:06 -04:00
committed by Nik Bougalis
parent 64b55c0f88
commit 80e535a13c
2 changed files with 19 additions and 67 deletions

View File

@@ -667,73 +667,25 @@ protected:
std::shared_ptr<STTx const>
st (JTx const& jt);
inline
void
invoke (STTx& stx)
{
}
template <class F>
inline
void
maybe_invoke (STTx& stx, F const& f,
std::false_type)
{
}
template <class F>
void
maybe_invoke (STTx& stx, F const& f,
std::true_type)
{
f(*this, stx);
}
// Invoke funclets on stx
// Note: The STTx may not be modified
template <class F, class... FN>
template <class... FN>
void
invoke (STTx& stx, F const& f,
FN const&... fN)
invoke (STTx& stx, FN const&... fN)
{
maybe_invoke(stx, f,
std::is_invocable<F,
void(Env&, STTx const&)>());
invoke(stx, fN...);
}
inline
void
invoke (JTx&)
{
}
template <class F>
inline
void
maybe_invoke (JTx& jt, F const& f,
std::false_type)
{
}
template <class F>
void
maybe_invoke (JTx& jt, F const& f,
std::true_type)
{
f(*this, jt);
// Sean Parent for_each_argument trick (C++ fold expressions would be
// nice here)
(void)std::array<int, sizeof...(fN)>{{((fN(*this, stx)), 0)...}};
}
// Invoke funclets on jt
template <class F, class... FN>
template <class... FN>
void
invoke (JTx& jt, F const& f,
FN const&... fN)
invoke (JTx& jt, FN const&... fN)
{
maybe_invoke(jt, f,
std::is_invocable<F,
void(Env&, JTx&)>());
invoke(jt, fN...);
// Sean Parent for_each_argument trick (C++ fold expressions would be
// nice here)
(void)std::array<int, sizeof...(fN)>{{((fN(*this, jt)), 0)...}};
}
// Map of account IDs to Account