20#include <xrpl/basics/Blob.h>
21#include <xrpl/basics/Expected.h>
22#include <xrpl/basics/Slice.h>
23#include <xrpl/basics/StringUtilities.h>
24#include <xrpl/basics/base_uint.h>
25#include <xrpl/basics/contract.h>
26#include <xrpl/basics/safe_cast.h>
27#include <xrpl/basics/strHex.h>
28#include <xrpl/beast/utility/Zero.h>
29#include <xrpl/beast/utility/instrumentation.h>
30#include <xrpl/json/json_value.h>
31#include <xrpl/protocol/AccountID.h>
32#include <xrpl/protocol/HashPrefix.h>
33#include <xrpl/protocol/MPTIssue.h>
34#include <xrpl/protocol/Protocol.h>
35#include <xrpl/protocol/PublicKey.h>
36#include <xrpl/protocol/Rules.h>
37#include <xrpl/protocol/SField.h>
38#include <xrpl/protocol/SOTemplate.h>
39#include <xrpl/protocol/STAccount.h>
40#include <xrpl/protocol/STAmount.h>
41#include <xrpl/protocol/STArray.h>
42#include <xrpl/protocol/STBase.h>
43#include <xrpl/protocol/STObject.h>
44#include <xrpl/protocol/STTx.h>
45#include <xrpl/protocol/SecretKey.h>
46#include <xrpl/protocol/SeqProxy.h>
47#include <xrpl/protocol/Serializer.h>
48#include <xrpl/protocol/Sign.h>
49#include <xrpl/protocol/TxFlags.h>
50#include <xrpl/protocol/TxFormats.h>
51#include <xrpl/protocol/jss.h>
53#include <boost/container/flat_set.hpp>
54#include <boost/format/format_fwd.hpp>
55#include <boost/format/free_funcs.hpp>
77 if (format ==
nullptr)
79 Throw<std::runtime_error>(
80 "Invalid transaction type " +
99 Throw<std::runtime_error>(
"Transaction length invalid");
102 Throw<std::runtime_error>(
"Transaction contains an object terminator");
115 set(format->getSOTemplate());
123 LogicError(
"Transaction type was mutated during assembly");
137 return emplace(n, buf, std::move(*
this));
144 return STI_TRANSACTION;
158boost::container::flat_set<AccountID>
161 boost::container::flat_set<AccountID> list;
163 for (
auto const& it : *
this)
165 if (
auto sacc =
dynamic_cast<STAccount const*
>(&it))
169 "ripple::STTx::getMentionedAccounts : account is set");
170 if (!sacc->isDefault())
171 list.insert(sacc->value());
173 else if (
auto samt =
dynamic_cast<STAmount const*
>(&it))
175 auto const& issuer = samt->getIssuer();
247 Rules const& rules)
const
255 return signingPubKey.
empty()
262 return Unexpected(
"Internal signature check failure.");
287 ret[jss::tx] = dataBin;
306 "INSERT OR REPLACE INTO Transactions "
307 "(TransID, TransType, FromAcct, FromSeq, LedgerSeq, Status, RawTxn, "
331 static boost::format bfTrans(
332 "('%s', '%s', '%s', '%d', '%d', '%c', %s, %s)");
336 XRPL_ASSERT(format,
"ripple::STTx::getMetaSQL : non-null type format");
341 getFieldU32(sfSequence) % inLedger % status % rTxn % escapedMetaData);
351 return Unexpected(
"Cannot both single- and multi-sign.");
353 bool validSig =
false;
378 if (validSig ==
false)
387 Rules const& rules)
const
397 return Unexpected(
"Cannot both single- and multi-sign.");
404 return Unexpected(
"Invalid Signers array size.");
423 auto const accountID =
signer.getAccountID(sfAccount);
426 if (accountID == txnAccountID)
430 if (lastAccountID == accountID)
431 return Unexpected(
"Duplicate Signers not allowed.");
434 if (lastAccountID > accountID)
438 lastAccountID = accountID;
441 bool validSig =
false;
447 auto spk =
signer.getFieldVL(sfSigningPubKey);
451 Blob const signature =
signer.getFieldVL(sfTxnSignature);
492 reason =
"The memo exceeds the maximum allowed size.";
496 for (
auto const&
memo : memos)
500 if (!memoObj || (memoObj->getFName() != sfMemo))
502 reason =
"A memo array may contain only Memo objects.";
506 for (
auto const& memoElement : *memoObj)
508 auto const& name = memoElement.getFName();
510 if (name != sfMemoType && name != sfMemoData &&
511 name != sfMemoFormat)
514 "A memo may contain only MemoType, MemoData or "
515 "MemoFormat fields.";
520 auto optData =
strUnHex(memoElement.getText());
525 "The MemoType, MemoData and MemoFormat fields may "
526 "only contain hex-encoded data.";
530 if (name == sfMemoData)
541 "-._~:/?#[]@!$&'()*+,;=%"
542 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
543 "abcdefghijklmnopqrstuvwxyz");
545 for (
char c : symbols)
550 for (
auto c : *optData)
552 if (!allowedSymbols[c])
555 "The MemoType and MemoFormat fields may only "
556 "contain characters that are allowed in URLs "
571 for (
int i = 0; i < st.
getCount(); ++i)
574 if (t && t->isDefault())
584 auto const txType = tx[~sfTransactionType];
587 if (
auto const* item =
590 for (
auto const& e : item->getSOTemplate())
594 if (
auto const& field = tx.
peekAtField(e.sField());
595 (field.getSType() == STI_AMOUNT &&
597 (field.getSType() == STI_ISSUE &&
617 reason =
"An account field is invalid.";
623 reason =
"Cannot submit pseudo transactions.";
629 reason =
"Amount can not be MPT.";
642 return std::make_shared<STTx const>(
std::ref(sit));
648 auto t = tx[~sfTransactionType];
651 auto tt = safe_cast<TxType>(*t);
652 return tt == ttAMENDMENT || tt == ttFEE || tt == ttUNL_MODIFY;
UInt size() const
Number of values in array or object.
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)
void applyTemplate(SOTemplate const &type)
Blob getFieldVL(SField const &field) const
AccountID getAccountID(SField const &field) const
STArray const & getFieldArray(SField const &field) const
STBase const * peekAtPIndex(int offset) 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)
Serializer getSerializer() const
void set(SOTemplate 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
std::string getFullText() const override
bool isFieldPresent(SField const &field) const
Json::Value getJson(JsonOptions=JsonOptions::none) const override
STBase const & peekAtField(SField const &field) const
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::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
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.
constexpr std::uint32_t value() const
int getBytesLeft() const noexcept
Slice slice() const noexcept
Blob const & peekData() const
int getDataLength() const
Set the regular signature on a JTx.
@ objectValue
object value (collection of name/value pairs).
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
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 &.
Set the sequence number on a JTx.
A signer in a SignerList.