载入中...
搜索中...
未找到
AtomicResourcePayment.cpp
浏览该文件的文档.
2
3#include <array>
4#include <span>
5#include <utility>
6#include <vector>
7
8namespace eve::transaction {
9namespace {
10
11} // namespace
12
14 std::span<ITransactionParticipant*> participants) {
15 Coordinator coordinator;
16 return coordinator.execute(context, participants);
17}
18
21 std::array<ITransactionParticipant*, 1> participants{&effect};
22 return execute(context, std::span<ITransactionParticipant*>(participants));
23}
24
29 std::array<ITransactionParticipant*, 1> participants{&effect};
30 return execute(context, account, cost, std::span<ITransactionParticipant*>(participants));
31}
32
36 std::span<ITransactionParticipant*> participants) {
37 if (!cost.isValid())
39 eve::DiagnosticCode::InvalidArgument, "resource payment requires a validated non-empty CostSpec", "cost"));
40
41 ResourceDebitParticipant debit(account, cost, "resource-payment");
42 std::vector<ITransactionParticipant*> all;
43 all.reserve(participants.size() + 1u);
44 for (auto* participant : participants) all.push_back(participant);
45 // The debit is deliberately last. Domain participants are therefore
46 // prepared first, and a failed debit compensates any committed domain
47 // participant without exposing a partially paid operation.
48 all.push_back(&debit);
49 Coordinator coordinator;
50 return coordinator.execute(context, std::span<ITransactionParticipant*>(all));
51}
52
57 if (transactionId.empty())
60 "resource payment transaction id must not be empty", "transactionId"));
61 return execute(TransactionContext(std::move(transactionId)), account, cost, effect);
62}
63
64} // namespace eve::transaction
Small transaction facade for a resource cost plus one domain effect.
eve::resource::CostSpec cost
eve::resource::IResourceAccount * account
std::unique_ptr< ParticleEffect > effect
const VegetationPresetContext & context
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Immutable canonical multi-resource cost.
bool isValid() const noexcept
Whether this value contains a validated non-empty cost.
Provider-neutral resource account contract.
static eve::Result< TransactionReceipt > execute(const TransactionContext &context, std::span< ITransactionParticipant * > participants)
Execute already prepared domain participants as one transaction.
Coordinates participant lifecycles with deterministic ordering.
Result< TransactionReceipt > execute(const TransactionContext &context, std::span< ITransactionParticipant * > participants) const
Atomically execute borrowed participants for one context.
Synchronous participant contract for one coordinator transaction.
Adapts IResourceAccount debit semantics to Coordinator.
Immutable context shared by every participant of one transaction.
Definition Transaction.h:30