20#include <xrpl/basics/Log.h>
21#include <xrpl/basics/StringUtilities.h>
22#include <xrpl/basics/contract.h>
23#include <xrpl/basics/safe_cast.h>
24#include <xrpl/json/to_string.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/HashPrefix.h>
27#include <xrpl/protocol/Protocol.h>
28#include <xrpl/protocol/PublicKey.h>
29#include <xrpl/protocol/STAccount.h>
30#include <xrpl/protocol/STArray.h>
31#include <xrpl/protocol/STTx.h>
32#include <xrpl/protocol/Sign.h>
33#include <xrpl/protocol/TxFlags.h>
34#include <xrpl/protocol/UintTypes.h>
35#include <xrpl/protocol/jss.h>
36#include <boost/format.hpp>
50 if (format ==
nullptr)
52 Throw<std::runtime_error>(
53 "Invalid transaction type " +
72 Throw<std::runtime_error>(
"Transaction length invalid");
75 Throw<std::runtime_error>(
"Transaction contains an object terminator");
88 set(format->getSOTemplate());
96 LogicError(
"Transaction type was mutated during assembly");
110 return emplace(n, buf, std::move(*
this));
117 return STI_TRANSACTION;
131boost::container::flat_set<AccountID>
134 boost::container::flat_set<AccountID> list;
136 for (
auto const& it : *
this)
138 if (
auto sacc =
dynamic_cast<STAccount const*
>(&it))
142 "ripple::STTx::getMentionedAccounts : account is set");
143 if (!sacc->isDefault())
144 list.insert(sacc->value());
146 else if (
auto samt =
dynamic_cast<STAmount const*
>(&it))
148 auto const& issuer = samt->getIssuer();
214 Rules const& rules)
const
222 return signingPubKey.
empty()
229 return Unexpected(
"Internal signature check failure.");
254 ret[jss::tx] = dataBin;
273 "INSERT OR REPLACE INTO Transactions "
274 "(TransID, TransType, FromAcct, FromSeq, LedgerSeq, Status, RawTxn, "
298 static boost::format bfTrans(
299 "('%s', '%s', '%s', '%d', '%d', '%c', %s, %s)");
303 XRPL_ASSERT(format,
"ripple::STTx::getMetaSQL : non-null type format");
308 getFieldU32(sfSequence) % inLedger % status % rTxn % escapedMetaData);
318 return Unexpected(
"Cannot both single- and multi-sign.");
320 bool validSig =
false;
345 if (validSig ==
false)
354 Rules const& rules)
const
364 return Unexpected(
"Cannot both single- and multi-sign.");
371 return Unexpected(
"Invalid Signers array size.");
388 for (
auto const& signer : signers)
390 auto const accountID = signer.getAccountID(sfAccount);
393 if (accountID == txnAccountID)
397 if (lastAccountID == accountID)
398 return Unexpected(
"Duplicate Signers not allowed.");
401 if (lastAccountID > accountID)
405 lastAccountID = accountID;
408 bool validSig =
false;
414 auto spk = signer.getFieldVL(sfSigningPubKey);
418 Blob const signature = signer.getFieldVL(sfTxnSignature);
459 reason =
"The memo exceeds the maximum allowed size.";
463 for (
auto const& memo : memos)
465 auto memoObj =
dynamic_cast<STObject const*
>(&memo);
467 if (!memoObj || (memoObj->getFName() != sfMemo))
469 reason =
"A memo array may contain only Memo objects.";
473 for (
auto const& memoElement : *memoObj)
475 auto const& name = memoElement.getFName();
477 if (name != sfMemoType && name != sfMemoData &&
478 name != sfMemoFormat)
481 "A memo may contain only MemoType, MemoData or "
482 "MemoFormat fields.";
487 auto optData =
strUnHex(memoElement.getText());
492 "The MemoType, MemoData and MemoFormat fields may "
493 "only contain hex-encoded data.";
497 if (name == sfMemoData)
508 "-._~:/?#[]@!$&'()*+,;=%"
509 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
510 "abcdefghijklmnopqrstuvwxyz");
512 for (
char c : symbols)
517 for (
auto c : *optData)
519 if (!allowedSymbols[c])
522 "The MemoType and MemoFormat fields may only "
523 "contain characters that are allowed in URLs "
538 for (
int i = 0; i < st.
getCount(); ++i)
541 if (t && t->isDefault())
551 auto const txType = tx[~sfTransactionType];
554 if (
auto const* item =
557 for (
auto const& e : item->getSOTemplate())
561 if (
auto const& field = tx.
peekAtField(e.sField());
562 (field.getSType() == STI_AMOUNT &&
564 (field.getSType() == STI_ISSUE &&
584 reason =
"An account field is invalid.";
590 reason =
"Cannot submit pseudo transactions.";
596 reason =
"Amount can not be MPT.";
609 return std::make_shared<STTx const>(
std::ref(sit));
615 auto t = tx[~sfTransactionType];
618 auto tt = safe_cast<TxType>(*t);
619 return tt == ttAMENDMENT || tt == ttFEE || tt == ttUNL_MODIFY;
Rules controlling protocol behavior.
constexpr bool holds() const noexcept
A type which can be exported to a well known binary format.
static STBase * emplace(std::size_t n, void *buf, T &&val)
Blob getFieldVL(SField const &field) const
AccountID getAccountID(SField const &field) const
const STArray & getFieldArray(SField const &field) const
std::uint16_t getFieldU16(SField const &field) const
std::uint32_t getFieldU32(SField const &field) const
void setFieldU16(SField const &field, std::uint16_t)
const STBase * peekAtPIndex(int offset) const
Serializer getSerializer() const
void add(Serializer &s) const override
uint256 getSigningHash(HashPrefix prefix) const
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
uint256 getHash(HashPrefix prefix) const
void set(const SOTemplate &)
std::string getFullText() const override
const STBase & peekAtField(SField const &field) const
bool isFieldPresent(SField const &field) const
Json::Value getJson(JsonOptions options) const override
void applyTemplate(const SOTemplate &type)
void addWithoutSigningFields(Serializer &s) const
void setFieldVL(SField const &field, Blob const &)
std::uint32_t getFlags() const
boost::container::flat_set< AccountID > getMentionedAccounts() const
uint256 getSigningHash() const
static std::string const & getMetaSQLInsertReplaceHeader()
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
SeqProxy getSeqProxy() const
Json::Value getJson(JsonOptions options) const override
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
STBase * move(std::size_t n, void *buf) override
static std::size_t const minMultiSigners
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
static std::size_t maxMultiSigners(Rules const *rules=0)
RequireFullyCanonicalSig
Check the signature.
Blob getSignature() const
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
uint256 getTransactionID() const
SerializedTypeID getSType() const override
std::string getFullText() const override
STBase * copy(std::size_t n, void *buf) const override
A type that represents either a sequence value or a ticket value.
static constexpr SeqProxy sequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
int getBytesLeft() const noexcept
Slice slice() const noexcept
Blob const & peekData() const
int getDataLength() const
@ objectValue
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
bool isXRP(AccountID const &c)
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
static bool isAccountFieldOkay(STObject const &st)
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
TxType
Transaction type identifiers.
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Serializer startMultiSigningData(STObject const &obj)
Break the multi-signing hash computation into 2 parts for optimization.
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
static bool isMemoOkay(STObject const &st, std::string &reason)
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safe_cast(Src s) noexcept
std::size_t constexpr txMinSizeBytes
Protocol specific constants.
static auto getTxFormat(TxType type)
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
static bool invalidMPTAmountInTx(STObject const &tx)
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
std::string strHex(FwdIt begin, FwdIt end)
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
std::vector< unsigned char > Blob
Storage for linear binary data.
static Blob getSigningData(STTx const &that)
bool passesLocalChecks(STObject const &st, std::string &)
std::size_t constexpr txMaxSizeBytes
Largest legal byte size of a transaction.
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfFullyCanonicalSig
Transaction flags.
@ txSign
inner transaction to sign
@ transactionID
transaction plus signature to give transaction ID
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
Note, should be treated as flags that can be | and &.