mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-09 11:46:49 +00:00
The six different ranges of TER codes are broken up into six different enumerations. A template class allows subsets of these enumerations to be aggregated. This technique allows verification at compile time that no TEC codes are returned before the signature is checked. Conversion between TER instance and integer is provided by named functions. This makes accidental conversion almost impossible and makes type abuse easier to spot in the code base.
101 lines
2.9 KiB
C++
101 lines
2.9 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.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <ripple/app/tx/impl/CancelOffer.h>
|
|
#include <ripple/basics/Log.h>
|
|
#include <ripple/protocol/st.h>
|
|
#include <ripple/ledger/View.h>
|
|
|
|
namespace ripple {
|
|
|
|
NotTEC
|
|
CancelOffer::preflight (PreflightContext const& ctx)
|
|
{
|
|
auto const ret = preflight1 (ctx);
|
|
if (!isTesSuccess (ret))
|
|
return ret;
|
|
|
|
auto const uTxFlags = ctx.tx.getFlags();
|
|
|
|
if (uTxFlags & tfUniversalMask)
|
|
{
|
|
JLOG(ctx.j.trace()) << "Malformed transaction: " <<
|
|
"Invalid flags set.";
|
|
return temINVALID_FLAG;
|
|
}
|
|
|
|
auto const seq = ctx.tx.getFieldU32 (sfOfferSequence);
|
|
if (! seq)
|
|
{
|
|
JLOG(ctx.j.trace()) <<
|
|
"CancelOffer::preflight: missing sequence";
|
|
return temBAD_SEQUENCE;
|
|
}
|
|
|
|
return preflight2(ctx);
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
TER
|
|
CancelOffer::preclaim(PreclaimContext const& ctx)
|
|
{
|
|
auto const id = ctx.tx[sfAccount];
|
|
auto const offerSequence = ctx.tx[sfOfferSequence];
|
|
|
|
auto const sle = ctx.view.read(
|
|
keylet::account(id));
|
|
|
|
if ((*sle)[sfSequence] <= offerSequence)
|
|
{
|
|
JLOG(ctx.j.trace()) << "Malformed transaction: " <<
|
|
"Sequence " << offerSequence << " is invalid.";
|
|
return temBAD_SEQUENCE;
|
|
}
|
|
|
|
return tesSUCCESS;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
TER
|
|
CancelOffer::doApply ()
|
|
{
|
|
auto const offerSequence = ctx_.tx[sfOfferSequence];
|
|
|
|
auto const sle = view().read(
|
|
keylet::account(account_));
|
|
|
|
uint256 const offerIndex (getOfferIndex (account_, offerSequence));
|
|
|
|
auto sleOffer = view().peek (
|
|
keylet::offer(offerIndex));
|
|
|
|
if (sleOffer)
|
|
{
|
|
JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
|
|
return offerDelete (view(), sleOffer, ctx_.app.journal("View"));
|
|
}
|
|
|
|
JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
|
|
return tesSUCCESS;
|
|
}
|
|
|
|
}
|