Appearance
etxn_reserve
Summary. Declare the number of transactions this hook execution will emit. Must be called before the emission APIs that require a reservation, such as etxn_burden, etxn_details, etxn_fee_base, emit, and prepare. etxn_generation and etxn_nonce do not require a reservation.
Signature.
c
int64_t etxn_reserve(uint32_t count);Parameters.
| Name | Type | Description |
|---|---|---|
count | uint32_t | Number of transactions the hook intends to emit this execution; 1..255. |
Return value. Returns count on success. Errors: ALREADY_SET (-8) if a reservation was already made this execution; TOO_SMALL (-4) if count < 1; TOO_BIG (-3) if count > 255 (max_emit).
Common failure patterns.
- Calling it twice in one execution →
ALREADY_SET. - Reserving
0, or more than255→TOO_SMALL/TOO_BIG. - Forgetting it entirely: reservation-dependent emission APIs then return
PREREQUISITE_NOT_MET(-9).
Caveats / notes.
etxn_generationandetxn_noncecan be called beforeetxn_reserve; the reservation is required when calculating emission burden/details or pricing and submitting an emitted transaction.- The reservation is per-execution. A
cbakexecution (or a weak re-execution) starts fresh and must reserve again before emitting. - You must actually emit no more than
counttransactions; thecount+1-themitreturnsTOO_MANY_EMITTED_TXN(-13). Reserving more than you emit is allowed. - Both
etxn_burdenandetxn_detailsfoldcountinto the burden calculation, so reserve the true number you will emit.
Minimal example.
c
etxn_reserve(1); // this hook will emit exactly one transactionPractical example.
c
int64_t hook(uint32_t r)
{
_g(1, 1);
// cannot reserve zero, cannot reserve more than the max
ASSERT(etxn_reserve(0) == TOO_SMALL);
ASSERT(etxn_reserve(256) == TOO_BIG);
// a valid reservation returns the count
ASSERT(etxn_reserve(1) == 1);
// and it may only be set once
ASSERT(etxn_reserve(1) == ALREADY_SET);
accept(0, 0, 0);
}Related APIs. emit, etxn_burden, etxn_details.