@lelantos-org/sdk / x402 / BudgetLedger
Class: BudgetLedger
Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:25
Enforces Budget and the host allowlist, and tracks spend. One ledger per x402() call; totals cover the payer's lifetime, not the process's.
Constructors
Constructor
new BudgetLedger(budget, allowHosts?): BudgetLedger;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:31
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:33
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:38
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:51
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:49
Check the limits and hold amount against them in one synchronous step.
Minting a payment spans a Groth16 prove and a submit, so checking and recording separately would let concurrent payments all pass the check before any is recorded. The hold counts toward the limits until it is committed or released.
Parameters
| Parameter | Type |
|---|---|
amount | CircuitAmount |
asset | AssetInfo |
resource? | string |
Returns
Throws
per-request-limit or budget-exceeded
spent()
spent(): Map<bigint, bigint>;Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:53
Circuit units spent so far, keyed by asset id.
Returns
Map<bigint, bigint>