@lelantos-org/sdk / x402 / BudgetLedger
Class: BudgetLedger โ
Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:27
Constructors โ
Constructor โ
new BudgetLedger(budget, allowHosts?): BudgetLedger;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:33
Parameters โ
| Parameter | Type |
|---|---|
budget | Budget |
allowHosts? | readonly string[] |
Returns โ
BudgetLedger
Methods โ
assertHostAllowed() โ
assertHostAllowed(url): void;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:35
Parameters โ
| Parameter | Type |
|---|---|
url | string |
Returns โ
void
Throws โ
host-not-allowed
assertWithinLimits() โ
assertWithinLimits(
amount,
asset,
resource?
): void;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:40
Parameters โ
| Parameter | Type | Description |
|---|---|---|
amount | CircuitAmount | Circuit units for this asset. |
asset | AssetInfo | - |
resource? | string | - |
Returns โ
void
Throws โ
per-request-limit or budget-exceeded
record() โ
record(amount, asset): void;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:58
Call only once a payment has been made.
Parameters โ
| Parameter | Type |
|---|---|
amount | bigint |
asset | bigint |
Returns โ
void
reserve() โ
reserve(
amount,
asset,
resource?
): BudgetReservation;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:56
Check the limits and hold amount against them in one step.
Checking and recording separately is not enough: minting a payment takes seconds (a Groth16 prove, then a submit), and nothing held the ledger across that await โ so N concurrent payments all passed the check before any of them recorded, and the budget was enforced against a total that ignored every payment still in flight. With { total: "5" } and 1-unit payments, twenty concurrent calls all went through.
The reservation is synchronous and counts toward the limits until it is committed or released, so a concurrent caller sees it.
Parameters โ
| Parameter | Type |
|---|---|
amount | CircuitAmount |
asset | AssetInfo |
resource? | string |
Returns โ
BudgetReservation
Throws โ
per-request-limit or budget-exceeded
spent() โ
spent(): Map<bigint, bigint>;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:60
Circuit units spent so far, keyed by asset id.
Returns โ
Map<bigint, bigint>