rippled
Loading...
Searching...
No Matches
batch.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TEST_JTX_BATCH_H_INCLUDED
21#define RIPPLE_TEST_JTX_BATCH_H_INCLUDED
22
23#include <test/jtx/Account.h>
24#include <test/jtx/Env.h>
25#include <test/jtx/amount.h>
26#include <test/jtx/owners.h>
27#include <test/jtx/tags.h>
28
29#include <xrpl/protocol/TxFlags.h>
30
31#include "test/jtx/SignerUtils.h"
32
33#include <concepts>
34#include <cstdint>
35#include <optional>
36
37namespace ripple {
38namespace test {
39namespace jtx {
40
42namespace batch {
43
47 jtx::Env const& env,
48 uint32_t const& numSigners,
49 uint32_t const& txns = 0);
50
53outer(
54 jtx::Account const& account,
55 uint32_t seq,
56 STAmount const& fee,
58
60class inner
61{
62private:
66
67public:
69 Json::Value const& txn,
70 std::uint32_t const& sequence,
71 std::optional<std::uint32_t> const& ticket = std::nullopt,
72 std::optional<std::uint32_t> const& fee = std::nullopt)
73 : txn_(txn), seq_(sequence), ticket_(ticket)
74 {
75 txn_[jss::SigningPubKey] = "";
76 txn_[jss::Sequence] = seq_;
77 txn_[jss::Fee] = "0";
78 txn_[jss::Flags] = txn_[jss::Flags].asUInt() | tfInnerBatchTxn;
79
80 // Optionally set ticket sequence
81 if (ticket_.has_value())
82 {
83 txn_[jss::Sequence] = 0;
84 txn_[sfTicketSequence.jsonName] = *ticket_;
85 }
86 }
87
88 void
89 operator()(Env&, JTx& jtx) const;
90
93 {
94 return txn_[key];
95 }
96
97 void
99 {
100 txn_.removeMember(key);
101 }
102
103 Json::Value const&
104 getTxn() const
105 {
106 return txn_;
107 }
108};
109
111class sig
112{
113public:
115
116 sig(std::vector<Reg> signers_) : signers(std::move(signers_))
117 {
119 }
120
121 template <class AccountType, class... Accounts>
122 requires std::convertible_to<AccountType, Reg>
123 explicit sig(AccountType&& a0, Accounts&&... aN)
124 : signers{std::forward<AccountType>(a0), std::forward<Accounts>(aN)...}
125 {
127 }
128
129 void
130 operator()(Env&, JTx& jt) const;
131};
132
134class msig
135{
136public:
139
140 msig(Account const& masterAccount, std::vector<Reg> signers_)
141 : master(masterAccount), signers(std::move(signers_))
142 {
144 }
145
146 template <class AccountType, class... Accounts>
147 requires std::convertible_to<AccountType, Reg>
148 explicit msig(
149 Account const& masterAccount,
150 AccountType&& a0,
151 Accounts&&... aN)
152 : master(masterAccount)
153 , signers{std::forward<AccountType>(a0), std::forward<Accounts>(aN)...}
154 {
156 }
157
158 void
159 operator()(Env&, JTx& jt) const;
160};
161
162} // namespace batch
163
164} // namespace jtx
165
166} // namespace test
167} // namespace ripple
168
169#endif
Lightweight wrapper to tag static string.
Definition: json_value.h:64
Represents a JSON value.
Definition: json_value.h:150
UInt asUInt() const
Definition: json_value.cpp:558
Value removeMember(char const *key)
Remove and return the named member.
Definition: json_value.cpp:935
Immutable cryptographic account descriptor.
Definition: Account.h:39
A transaction testing environment.
Definition: Env.h:121
Adds a new Batch Txn on a JTx and autofills.
Definition: batch.h:61
std::optional< std::uint32_t > ticket_
Definition: batch.h:65
inner(Json::Value const &txn, std::uint32_t const &sequence, std::optional< std::uint32_t > const &ticket=std::nullopt, std::optional< std::uint32_t > const &fee=std::nullopt)
Definition: batch.h:68
void removeMember(Json::StaticString const &key)
Definition: batch.h:98
Json::Value const & getTxn() const
Definition: batch.h:104
Json::Value & operator[](Json::StaticString const &key)
Definition: batch.h:92
void operator()(Env &, JTx &jtx) const
Definition: batch.cpp:66
Set a batch nested multi-signature on a JTx.
Definition: batch.h:135
msig(Account const &masterAccount, AccountType &&a0, Accounts &&... aN)
Definition: batch.h:148
void operator()(Env &, JTx &jt) const
Definition: batch.cpp:111
msig(Account const &masterAccount, std::vector< Reg > signers_)
Definition: batch.h:140
std::vector< Reg > signers
Definition: batch.h:138
Set a batch signature on a JTx.
Definition: batch.h:112
void operator()(Env &, JTx &jt) const
Definition: batch.cpp:77
sig(AccountType &&a0, Accounts &&... aN)
Definition: batch.h:123
sig(std::vector< Reg > signers_)
Definition: batch.h:116
std::vector< Reg > signers
Definition: batch.h:114
Set the fee on a JTx.
Definition: fee.h:37
Match set account flags.
Definition: flags.h:128
Json::Value outer(jtx::Account const &account, uint32_t seq, STAmount const &fee, std::uint32_t flags)
Batch.
Definition: batch.cpp:49
XRPAmount calcBatchFee(jtx::Env const &env, uint32_t const &numSigners, uint32_t const &txns=0)
Calculate Batch Fee.
Definition: batch.cpp:38
void sortSigners(std::vector< Reg > &signers)
Definition: SignerUtils.h:44
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr std::uint32_t tfInnerBatchTxn
Definition: TxFlags.h:61
STL namespace.
T has_value(T... args)
Execution context for applying a JSON transaction.
Definition: JTx.h:45
Set the sequence number on a JTx.
Definition: seq.h:34