InMemoryDomainTreasury

class InMemoryDomainTreasury(val domainId: DomainId, accounts: Map<String, ChainAccount>, spendPolicy: SpendPolicy = SpendPolicy.DEFAULT, store: TreasuryLedgerStore = InMemoryTreasuryLedgerStore(), config: TreasuryConfig = TreasuryConfig(), eventSink: DomainEventSink = NoopDomainEventSink) : DomainTreasury

Reference DomainTreasury implementation. In-memory reservation accounting over a swappable TreasuryLedgerStore. Production deployments may swap the store for a durable backend; the reservation lock state is volatile by design — reservations are short-lived (default 30 min) and orphaned ones expire harmlessly.

Reservation arithmetic uses TreasuryConfig.safetyMarginNumerator / safetyMarginDenominator (default 11/10) to lock slightly more than the estimate, absorbing intra-block fee-market drift.

Constructors

Link copied to clipboard
constructor(domainId: DomainId, accounts: Map<String, ChainAccount>, spendPolicy: SpendPolicy = SpendPolicy.DEFAULT, store: TreasuryLedgerStore = InMemoryTreasuryLedgerStore(), config: TreasuryConfig = TreasuryConfig(), eventSink: DomainEventSink = NoopDomainEventSink)

Properties

Link copied to clipboard
open override val domainId: DomainId

Functions

Link copied to clipboard
open suspend override fun account(chainId: String): ChainAccount?
Link copied to clipboard
open suspend override fun accounts(): List<ChainAccount>
Link copied to clipboard
open suspend override fun cancel(reservation: Reservation)

Release the reservation in full. Used on submission errors before any fee is incurred, and by the TTL sweeper for expired reservations.

Link copied to clipboard
open override fun ledger(): TreasuryLedger

Read view over the audit ledger.

Link copied to clipboard
open suspend override fun policy(): SpendPolicy
Link copied to clipboard
open suspend override fun reserve(ctx: PaymentContext, estimate: TokenAmount): Reservation

Lock estimate × safety margin against the ChainAccount for ctx.chainId. Throws org.trustweave.anchor.exceptions.TreasuryException subclasses on policy violation or insufficient funds — never on a recoverable mempool condition (that's the plugin's concern).

Link copied to clipboard
open suspend override fun settle(reservation: Reservation, result: AnchorResult, success: Boolean = true)

Commit a reservation against the actual fee reported in result. Releases the (typically smaller) delta back to the available balance and appends the terminal SETTLED (or FAILED if success is false) entry to the ledger.