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();
170 boost::optional<std::uint32_t>
const ticketSeq{
operator[](
205 ret = {
false,
"Internal signature check failure."};
235 "INSERT OR REPLACE INTO Transactions "
236 "(TransID, TransType, FromAcct, FromSeq, LedgerSeq, Status, RawTxn, "
260 static boost::format bfTrans(
261 "('%s', '%s', '%s', '%d', '%d', '%c', %s, %s)");
265 assert(format !=
nullptr);
280 return {
false,
"Cannot both single- and multi-sign."};
282 bool validSig =
false;
307 if (validSig ==
false)
308 return {
false,
"Invalid signature."};
319 return {
false,
"Empty SigningPubKey."};
324 return {
false,
"Cannot both single- and multi-sign."};
330 return {
false,
"Invalid Signers array size."};
347 for (
auto const& signer : signers)
349 auto const accountID = signer.getAccountID(
sfAccount);
352 if (accountID == txnAccountID)
353 return {
false,
"Invalid multisigner."};
356 if (lastAccountID == accountID)
357 return {
false,
"Duplicate Signers not allowed."};
360 if (lastAccountID > accountID)
361 return {
false,
"Unsorted Signers array."};
364 lastAccountID = accountID;
367 bool validSig =
false;
420 reason =
"The memo exceeds the maximum allowed size.";
424 for (
auto const& memo : memos)
426 auto memoObj =
dynamic_cast<STObject const*
>(&memo);
428 if (!memoObj || (memoObj->getFName() !=
sfMemo))
430 reason =
"A memo array may contain only Memo objects.";
434 for (
auto const& memoElement : *memoObj)
436 auto const& name = memoElement.getFName();
442 "A memo may contain only MemoType, MemoData or "
443 "MemoFormat fields.";
448 auto optData =
strUnHex(memoElement.getText());
453 "The MemoType, MemoData and MemoFormat fields may "
454 "only contain hex-encoded data.";
470 "-._~:/?#[]@!$&'()*+,;=%"
471 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
472 "abcdefghijklmnopqrstuvwxyz");
474 for (
char c : symbols)
479 for (
auto c : *optData)
481 if (!allowedSymbols[c])
484 "The MemoType and MemoFormat fields may only "
485 "contain characters that are allowed in URLs "
500 for (
int i = 0; i < st.
getCount(); ++i)
503 if (t && t->isDefault())
518 reason =
"An account field is invalid.";
524 reason =
"Cannot submit pseudo transactions.";
536 return std::make_shared<STTx const>(
std::ref(sit));
545 auto tt = safe_cast<TxType>(*t);
static auto getTxFormat(TxType type)
static bool isAccountFieldOkay(STObject const &st)
std::pair< bool, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
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)
std::pair< bool, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
void setFieldU16(SField const &field, std::uint16_t)
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
const SField sfSigners(access, STI_ARRAY, 3, "Signers", SField::sMD_Default, SField::notSigning)
const SF_Blob sfMemoType(access, STI_VL, 12, "MemoType")
const SF_Blob sfSigningPubKey(access, STI_VL, 3, "SigningPubKey")
constexpr std::size_t txMinSizeBytes
Protocol specific constants, types, and data.
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
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.
uint256 getSigningHash() const
SeqProxy getSeqProxy() const
boost::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
static std::string const & getMetaSQLInsertReplaceHeader()
static std::string sqlEscape(std::string const &strSrc)
std::string to_string(ListDisposition disposition)
void setFieldVL(SField const &field, Blob const &)
Blob getFieldVL(SField const &field) const
const STBase * peekAtPIndex(int offset) const
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
virtual std::string getFullText() const override
const SF_Blob sfMemoData(access, STI_VL, 13, "MemoData")
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical)
Verify a signature on a message.
int getDataLength() const
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
static Blob getSigningData(STTx const &that)
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.
const SField sfTransaction(access, STI_TRANSACTION, 257, "Transaction")
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,...
const SF_Blob sfTxnSignature(access, STI_VL, 4, "TxnSignature", SField::sMD_Default, SField::notSigning)
const SF_U16 sfTransactionType(access, STI_UINT16, 2, "TransactionType")
Slice slice() const noexcept
std::uint32_t getFlags() const
bool isXRP(AccountID const &c)
@ transactionID
transaction plus signature to give transaction ID
std::pair< bool, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
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_U32 sfTicketSequence(access, STI_UINT32, 41, "TicketSequence")
const SField sfMemo(access, STI_OBJECT, 10, "Memo")
TxType
Transaction type identifiers.
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.
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.
const SField sfMemos(access, STI_ARRAY, 9, "Memos")
static const std::size_t minMultiSigners
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
Return the value of a field.
std::uint32_t getFieldU32(SField const &field) const
virtual Json::Value getJson(JsonOptions options) const override
void set(const SOTemplate &)
RequireFullyCanonicalSig
Check the signature.
const SF_Blob sfMemoFormat(access, STI_VL, 14, "MemoFormat")
uint256 getHash(HashPrefix prefix) const