mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Tidy up jtx:
* Tidy declaration order * Remove AccountInfo * Remove Env autofill settings
This commit is contained in:
committed by
Nik Bougalis
parent
9dd08e4dab
commit
eb709f415b
@@ -67,16 +67,6 @@ Env::memoize (Account const& account)
|
||||
map_.emplace(account.id(), account);
|
||||
}
|
||||
|
||||
Account const&
|
||||
Env::lookup (std::string const& base58ID) const
|
||||
{
|
||||
RippleAddress ra;
|
||||
if (! ra.setAccountID(base58ID))
|
||||
throw std::runtime_error(
|
||||
"Env::lookup: invalid account ID");
|
||||
return lookup(ra.getAccountID());
|
||||
}
|
||||
|
||||
Account const&
|
||||
Env::lookup (AccountID const& id) const
|
||||
{
|
||||
@@ -87,6 +77,16 @@ Env::lookup (AccountID const& id) const
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
Account const&
|
||||
Env::lookup (std::string const& base58ID) const
|
||||
{
|
||||
RippleAddress ra;
|
||||
if (! ra.setAccountID(base58ID))
|
||||
throw std::runtime_error(
|
||||
"Env::lookup: invalid account ID");
|
||||
return lookup(ra.getAccountID());
|
||||
}
|
||||
|
||||
PrettyAmount
|
||||
Env::balance (Account const& account) const
|
||||
{
|
||||
@@ -130,24 +130,14 @@ Env::seq (Account const& account) const
|
||||
std::shared_ptr<SLE const>
|
||||
Env::le (Account const& account) const
|
||||
{
|
||||
// VFALCO NOTE This hack should be removed
|
||||
// when fetch returns shared_ptr again
|
||||
auto const st = ledger->fetch(
|
||||
return ledger->fetch(
|
||||
getAccountRootIndex(account.id()));
|
||||
if (! st)
|
||||
return nullptr;
|
||||
return std::make_shared<SLE const>(*st);
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
Env::le (uint256 const& key) const
|
||||
{
|
||||
// VFALCO NOTE This hack should be removed
|
||||
// when fetch returns shared_ptr again
|
||||
auto const st = ledger->fetch(key);
|
||||
if (! st)
|
||||
return nullptr;
|
||||
return std::make_shared<SLE const>(*st);
|
||||
return ledger->fetch(key);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -229,21 +219,13 @@ void
|
||||
Env::autofill_sig (JTx& jt)
|
||||
{
|
||||
auto& jv = jt.jv;
|
||||
auto const should = [](boost::tribool v, bool b)
|
||||
{
|
||||
if (boost::indeterminate(v))
|
||||
return b;
|
||||
return bool(v);
|
||||
};
|
||||
|
||||
if (jt.signer)
|
||||
jt.signer(*this, jt);
|
||||
else if(should(jt.fill_sig, fill_sig_))
|
||||
else if(jt.fill_sig)
|
||||
{
|
||||
auto const account =
|
||||
lookup(jv[jss::Account].asString());
|
||||
auto const ar =
|
||||
ledger->fetch(getAccountRootIndex(account));
|
||||
auto const ar = le(account);
|
||||
if (ar->isFieldPresent(sfRegularKey))
|
||||
jtx::sign(jv, lookup(
|
||||
ar->getFieldAccount160(sfRegularKey)));
|
||||
@@ -256,19 +238,10 @@ void
|
||||
Env::autofill (JTx& jt)
|
||||
{
|
||||
auto& jv = jt.jv;
|
||||
auto const should = [](boost::tribool v, bool b)
|
||||
{
|
||||
if (boost::indeterminate(v))
|
||||
return b;
|
||||
return bool(v);
|
||||
};
|
||||
|
||||
if(should(jt.fill_fee, fill_fee_))
|
||||
if(jt.fill_fee)
|
||||
jtx::fill_fee(jv, *ledger);
|
||||
|
||||
if(should(jt.fill_seq, fill_seq_))
|
||||
if(jt.fill_seq)
|
||||
jtx::fill_seq(jv, *ledger);
|
||||
|
||||
// Must come last
|
||||
autofill_sig(jt);
|
||||
}
|
||||
|
||||
@@ -165,13 +165,6 @@ public:
|
||||
env.require(nflags("xavier", asfDefaultRipple));
|
||||
env.fund(n, "yana");
|
||||
env.require(flags("yana", asfDefaultRipple));
|
||||
|
||||
// fund always autofills
|
||||
env.auto_fee(false);
|
||||
env.auto_seq(false);
|
||||
env.auto_sig(false);
|
||||
env.fund(n, "zeke");
|
||||
env.require(balance("zeke", n));
|
||||
}
|
||||
|
||||
// trust
|
||||
@@ -179,13 +172,6 @@ public:
|
||||
Env env(*this);
|
||||
env.fund(n, "alice", "bob", gw);
|
||||
env(trust("alice", USD(100)), require(lines("alice", 1)));
|
||||
|
||||
// trust always autofills
|
||||
env.auto_fee(false);
|
||||
env.auto_seq(false);
|
||||
env.auto_sig(false);
|
||||
env.trust(USD(100), "bob");
|
||||
env.require(lines("bob", 1));
|
||||
}
|
||||
|
||||
// balance
|
||||
@@ -215,7 +201,6 @@ public:
|
||||
{
|
||||
Env env(*this);
|
||||
env.fund(n, "alice");
|
||||
env.auto_fee(false);
|
||||
env.require(balance("alice", n));
|
||||
env(noop("alice"), fee(1), ter(telINSUF_FEE_P));
|
||||
env(noop("alice"), seq(none), ter(temMALFORMED));
|
||||
@@ -223,9 +208,7 @@ public:
|
||||
env(noop("alice"), fee(none), ter(temMALFORMED));
|
||||
env(noop("alice"), sig(none), ter(temMALFORMED));
|
||||
env(noop("alice"), fee(autofill));
|
||||
env.auto_seq(false);
|
||||
env(noop("alice"), fee(autofill), seq(autofill));
|
||||
env.auto_sig(false);
|
||||
env(noop("alice"), fee(autofill), seq(autofill), sig(autofill));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,12 @@ namespace jtx {
|
||||
void
|
||||
fee::operator()(Env const&, JTx& jt) const
|
||||
{
|
||||
if (boost::indeterminate(b_))
|
||||
if (! manual_)
|
||||
return;
|
||||
jt.fill_fee = false;
|
||||
if (amount_)
|
||||
jt[jss::Fee] =
|
||||
v_.getJson(0);
|
||||
else
|
||||
jt.fill_fee = b_;
|
||||
amount_->getJson(0);
|
||||
}
|
||||
|
||||
} // jtx
|
||||
|
||||
@@ -28,10 +28,11 @@ namespace jtx {
|
||||
void
|
||||
seq::operator()(Env const&, JTx& jt) const
|
||||
{
|
||||
if (boost::indeterminate(b_))
|
||||
jt[jss::Sequence] = v_;
|
||||
else
|
||||
jt.fill_seq = b_;
|
||||
if (! manual_)
|
||||
return;
|
||||
jt.fill_seq = false;
|
||||
if (num_)
|
||||
jt[jss::Sequence] = *num_;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
|
||||
@@ -28,19 +28,18 @@ namespace jtx {
|
||||
void
|
||||
sig::operator()(Env const&, JTx& jt) const
|
||||
{
|
||||
if(boost::indeterminate(b_))
|
||||
if (! manual_)
|
||||
return;
|
||||
jt.fill_sig = false;
|
||||
if(account_)
|
||||
{
|
||||
// VFALCO Inefficient pre-C++14
|
||||
auto const account = account_;
|
||||
auto const account = *account_;
|
||||
jt.signer = [account](Env&, JTx& jt)
|
||||
{
|
||||
jtx::sign(jt.jv, account);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
jt.fill_sig = b_;
|
||||
}
|
||||
}
|
||||
|
||||
} // jtx
|
||||
|
||||
Reference in New Issue
Block a user