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 " +
71 Throw<std::runtime_error>(
"Transaction length invalid");
74 Throw<std::runtime_error>(
"Transaction contains an object terminator");
87 set(format->getSOTemplate());
95 LogicError(
"Transaction type was mutated during assembly");
109 return emplace(n, buf, std::move(*
this));
130 boost::container::flat_set<AccountID>
133 boost::container::flat_set<AccountID> list;
135 for (
auto const& it : *
this)
137 if (
auto sacc =
dynamic_cast<STAccount const*
>(&it))
139 assert(!sacc->isDefault());
140 if (!sacc->isDefault())
141 list.insert(sacc->value());
143 else if (
auto samt =
dynamic_cast<STAmount const*
>(&it))
145 auto const& issuer = samt->getIssuer();
211 Rules const& rules)
const
219 return signingPubKey.
empty()
226 return Unexpected(
"Internal signature check failure.");
254 "INSERT OR REPLACE INTO Transactions "
255 "(TransID, TransType, FromAcct, FromSeq, LedgerSeq, Status, RawTxn, "
279 static boost::format bfTrans(
280 "('%s', '%s', '%s', '%d', '%d', '%c', %s, %s)");
284 assert(format !=
nullptr);
299 return Unexpected(
"Cannot both single- and multi-sign.");
301 bool validSig =
false;
326 if (validSig ==
false)
335 Rules const& rules)
const
345 return Unexpected(
"Cannot both single- and multi-sign.");
352 return Unexpected(
"Invalid Signers array size.");
369 for (
auto const& signer : signers)
371 auto const accountID = signer.getAccountID(
sfAccount);
374 if (accountID == txnAccountID)
378 if (lastAccountID == accountID)
379 return Unexpected(
"Duplicate Signers not allowed.");
382 if (lastAccountID > accountID)
386 lastAccountID = accountID;
389 bool validSig =
false;
440 reason =
"The memo exceeds the maximum allowed size.";
444 for (
auto const& memo : memos)
446 auto memoObj =
dynamic_cast<STObject const*
>(&memo);
448 if (!memoObj || (memoObj->getFName() !=
sfMemo))
450 reason =
"A memo array may contain only Memo objects.";
454 for (
auto const& memoElement : *memoObj)
456 auto const& name = memoElement.getFName();
462 "A memo may contain only MemoType, MemoData or "
463 "MemoFormat fields.";
468 auto optData =
strUnHex(memoElement.getText());
473 "The MemoType, MemoData and MemoFormat fields may "
474 "only contain hex-encoded data.";
489 "-._~:/?#[]@!$&'()*+,;=%"
490 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
491 "abcdefghijklmnopqrstuvwxyz");
493 for (
char c : symbols)
498 for (
auto c : *optData)
500 if (!allowedSymbols[c])
503 "The MemoType and MemoFormat fields may only "
504 "contain characters that are allowed in URLs "
519 for (
int i = 0; i < st.
getCount(); ++i)
522 if (t && t->isDefault())
537 reason =
"An account field is invalid.";
543 reason =
"Cannot submit pseudo transactions.";
555 return std::make_shared<STTx const>(
std::ref(sit));
564 auto tt = safe_cast<TxType>(*t);
static auto getTxFormat(TxType type)
static bool isAccountFieldOkay(STObject const &st)
const STArray & getFieldArray(SField const &field) const
void applyTemplate(const SOTemplate &type)
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 STBase * peekAtPIndex(int offset) const
const SF_UINT32 sfSequence
constexpr std::size_t txMinSizeBytes
Protocol specific constants.
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.
constexpr std::uint32_t tfFullyCanonicalSig
Transaction flags.
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
@ ttAMENDMENT
This system-generated transaction type is used to update the status of the various amendments.
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
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)
static STBase * emplace(std::size_t n, void *buf, T &&val)
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)
Slice slice() const noexcept
std::uint32_t getFlags() const
bool isXRP(AccountID const &c)
@ transactionID
transaction plus signature to give transaction ID
static std::size_t maxMultiSigners(Rules const *rules=0)
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
void add(Serializer &s) const override
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.
uint256 getSigningHash(HashPrefix prefix) const
int getBytesLeft() const noexcept
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
A type which can be exported to a well known binary format.
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.
Rules controlling protocol behavior.
static const std::size_t minMultiSigners
STBase * copy(std::size_t n, void *buf) const override
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
Json::Value getJson(JsonOptions options) const override
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
void set(const SOTemplate &)
STBase * move(std::size_t n, void *buf) override
RequireFullyCanonicalSig
Check the signature.
const SField sfTransaction
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
SerializedTypeID getSType() const override
uint256 getHash(HashPrefix prefix) const