20 #include <ripple/basics/Log.h>
21 #include <ripple/basics/StringUtilities.h>
22 #include <ripple/basics/contract.h>
23 #include <ripple/basics/safe_cast.h>
24 #include <ripple/json/to_string.h>
25 #include <ripple/protocol/Feature.h>
26 #include <ripple/protocol/HashPrefix.h>
27 #include <ripple/protocol/Protocol.h>
28 #include <ripple/protocol/PublicKey.h>
29 #include <ripple/protocol/STAccount.h>
30 #include <ripple/protocol/STArray.h>
31 #include <ripple/protocol/STTx.h>
32 #include <ripple/protocol/Sign.h>
33 #include <ripple/protocol/TxFlags.h>
34 #include <ripple/protocol/UintTypes.h>
35 #include <ripple/protocol/jss.h>
36 #include <boost/format.hpp>
49 if (format ==
nullptr)
51 Throw<std::runtime_error>(
52 "Invalid transaction type " +
62 applyTemplate(
getTxFormat(tx_type_)->getSOTemplate());
68 int length = sit.getBytesLeft();
71 Throw<std::runtime_error>(
"Transaction length invalid");
74 Throw<std::runtime_error>(
"Transaction contains an object terminator");
78 applyTemplate(
getTxFormat(tx_type_)->getSOTemplate());
87 set(format->getSOTemplate());
95 LogicError(
"Transaction type was mutated during assembly");
111 boost::container::flat_set<AccountID>
114 boost::container::flat_set<AccountID> list;
116 for (
auto const& it : *
this)
118 if (
auto sacc =
dynamic_cast<STAccount const*
>(&it))
120 assert(!sacc->isDefault());
121 if (!sacc->isDefault())
122 list.insert(sacc->value());
124 else if (
auto samt =
dynamic_cast<STAmount const*
>(&it))
126 auto const& issuer = samt->getIssuer();
204 return Unexpected(
"Internal signature check failure.");
232 "INSERT OR REPLACE INTO Transactions "
233 "(TransID, TransType, FromAcct, FromSeq, LedgerSeq, Status, RawTxn, "
257 static boost::format bfTrans(
258 "('%s', '%s', '%s', '%d', '%d', '%c', %s, %s)");
262 assert(format !=
nullptr);
277 return Unexpected(
"Cannot both single- and multi-sign.");
279 bool validSig =
false;
304 if (validSig ==
false)
321 return Unexpected(
"Cannot both single- and multi-sign.");
327 return Unexpected(
"Invalid Signers array size.");
344 for (
auto const& signer : signers)
346 auto const accountID = signer.getAccountID(
sfAccount);
349 if (accountID == txnAccountID)
353 if (lastAccountID == accountID)
354 return Unexpected(
"Duplicate Signers not allowed.");
357 if (lastAccountID > accountID)
361 lastAccountID = accountID;
364 bool validSig =
false;
415 reason =
"The memo exceeds the maximum allowed size.";
419 for (
auto const& memo : memos)
421 auto memoObj =
dynamic_cast<STObject const*
>(&memo);
423 if (!memoObj || (memoObj->getFName() !=
sfMemo))
425 reason =
"A memo array may contain only Memo objects.";
429 for (
auto const& memoElement : *memoObj)
431 auto const& name = memoElement.getFName();
437 "A memo may contain only MemoType, MemoData or "
438 "MemoFormat fields.";
443 auto optData =
strUnHex(memoElement.getText());
448 "The MemoType, MemoData and MemoFormat fields may "
449 "only contain hex-encoded data.";
465 "-._~:/?#[]@!$&'()*+,;=%"
466 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
467 "abcdefghijklmnopqrstuvwxyz");
469 for (
char c : symbols)
474 for (
auto c : *optData)
476 if (!allowedSymbols[c])
479 "The MemoType and MemoFormat fields may only "
480 "contain characters that are allowed in URLs "
495 for (
int i = 0; i < st.
getCount(); ++i)
498 if (t && t->isDefault())
513 reason =
"An account field is invalid.";
519 reason =
"Cannot submit pseudo transactions.";
531 return std::make_shared<STTx const>(
std::ref(sit));
540 auto tt = safe_cast<TxType>(*t);
static auto getTxFormat(TxType type)
static bool isAccountFieldOkay(STObject const &st)
const STArray & getFieldArray(SField const &field) const
std::vector< unsigned char > Blob
Storage for linear binary data.
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
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)
void setFieldU16(SField const &field, std::uint16_t)
const SF_UINT32 sfSequence
constexpr std::size_t txMinSizeBytes
Protocol specific constants, types, and data.
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a signature on a message.
const SF_VL sfSigningPubKey
Unexpected(E(&)[N]) -> Unexpected< E const * >
@ ttFEE
This system-generated transaction type is used to update the network's fee settings.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Serializer getSerializer() const
static constexpr SeqProxy sequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
TxType
Transaction type identifiers.
uint256 getSigningHash() const
SeqProxy getSeqProxy() const
const SF_UINT32 sfTicketSequence
static std::string const & getMetaSQLInsertReplaceHeader()
void setFieldVL(SField const &field, Blob const &)
Blob getFieldVL(SField const &field) const
const STBase * peekAtPIndex(int offset) const
@ ttAMENDMENT
This system-generated transaction type is used to update the status of the various amendments.
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
virtual std::string getFullText() const override
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
int getDataLength() const
const SF_UINT16 sfTransactionType
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
static Blob getSigningData(STTx const &that)
@ ttUNL_MODIFY
This system-generated transaction type is used to update the network's negative UNL.
bool passesLocalChecks(STObject const &st, std::string &reason)
AccountID getAccountID(SField const &field) const
std::string getFullText() const override
constexpr std::enable_if_t< std::is_same_v< typename Dest::unit_type, typename Src::unit_type > &&std::is_integral_v< typename Dest::value_type > &&std::is_integral_v< typename Src::value_type >, Dest > safe_cast(Src s) noexcept
Serializer startMultiSigningData(STObject const &obj)
Break the multi-signing hash computation into 2 parts for optimization.
static bool isMemoOkay(STObject const &st, std::string &reason)
const std::uint32_t tfFullyCanonicalSig
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
Slice slice() const noexcept
std::uint32_t getFlags() const
bool isXRP(AccountID const &c)
@ transactionID
transaction plus signature to give transaction ID
void addWithoutSigningFields(Serializer &s) const
constexpr std::size_t txMaxSizeBytes
Largest legal byte size of a transaction.
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
std::uint16_t getFieldU16(SField const &field) const
Json::Value getJson(JsonOptions options) const override
uint256 getTransactionID() const
const SF_VL sfTxnSignature
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
static const std::size_t maxMultiSigners
uint256 getSigningHash(HashPrefix prefix) const
virtual void add(Serializer &s) const override
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
Blob getSignature() const
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
bool isFieldPresent(SField const &field) const
Blob const & peekData() const
boost::container::flat_set< AccountID > getMentionedAccounts() const
A type that represents either a sequence value or a ticket value.
static const std::size_t minMultiSigners
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
int add32(std::uint32_t i)
std::string strHex(FwdIt begin, FwdIt end)
@ txSign
inner transaction to sign
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
std::uint32_t getFieldU32(SField const &field) const
virtual Json::Value getJson(JsonOptions options) const override
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
void set(const SOTemplate &)
RequireFullyCanonicalSig
Check the signature.
const SField sfTransaction
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
uint256 getHash(HashPrefix prefix) const