mechanisms/evm/batch-settlement/server
import "github.com/x402-foundation/x402/go/v2/mechanisms/evm/batch-settlement/server"
Constants
Source: mechanisms/evm/batch-settlement/server/scheme.go:29
const (
ErrAmountMustBeString = "amount must be a string for batched scheme"
ErrAssetAddressRequired = "asset address is required for batched scheme"
ErrFailedToParsePrice = "failed to parse price"
ErrUnsupportedPriceType = "unsupported price type"
ErrFailedToConvertAmt = "failed to convert amount"
ErrNoAssetSpecified = "no asset specified for batched scheme"
ErrFailedToParseAmount = "failed to parse amount"
)Source: mechanisms/evm/batch-settlement/server/storage.go:43
const (
ChannelUpdated ChannelUpdateStatus = "updated"
ChannelUnchanged ChannelUpdateStatus = "unchanged"
ChannelDeleted ChannelUpdateStatus = "deleted"
)Functions
func NewBatchSettlementChannelManager(config ChannelManagerConfig) *BatchSettlementChannelManager
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:140
NewBatchSettlementChannelManager creates a new channel manager.
func NewBatchSettlementEvmScheme(receiverAddress string, config *BatchSettlementEvmSchemeServerConfig) *BatchSettlementEvmScheme
Source: mechanisms/evm/batch-settlement/server/scheme.go:134
NewBatchSettlementEvmScheme creates a new batched server scheme.
func NewFileChannelStorage(opts batchsettlement.FileChannelStorageOptions) *FileChannelStorage
Source: mechanisms/evm/batch-settlement/server/file_storage.go:24
NewFileChannelStorage returns a file-backed server session storage.
func NewInMemoryChannelStorage() *InMemoryChannelStorage
Source: mechanisms/evm/batch-settlement/server/storage.go:88
NewInMemoryChannelStorage creates a new in-memory server session storage.
Types
type AuthorizerSigner
Source: mechanisms/evm/batch-settlement/server/scheme.go:40
AuthorizerSigner is the interface for the server-controlled receiverAuthorizer key. Used for signing refund and claim batch authorizations.
type AuthorizerSigner interface {
Address() string
SignTypedData(ctx context.Context, domain evm.TypedDataDomain, types map[string][]evm.TypedDataField, primaryType string, message map[string]interface{}) ([]byte, error)
}Methods
Address func() stringSignTypedData func(ctx context.Context, domain evm.TypedDataDomain, types map[string][]evm.TypedDataField, primaryType string, message map[string]interface{}) ([]byte, error)
type AutoSettlementConfig
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:71
AutoSettlementConfig configures interval-driven auto claim/settle/refund.
Each *IntervalSecs schedules an independent timer; passing zero leaves that job disabled. Selector callbacks let callers express custom claim/refund policy (e.g. claim only after a withdrawal trigger, refund only stale channels).
type AutoSettlementConfig struct {
ClaimIntervalSecs int
SettleIntervalSecs int
RefundIntervalSecs int
MaxClaimsPerBatch int
SelectClaimChannels ClaimChannelSelector
ShouldSettle ShouldSettleFunc
SelectRefundChannels RefundChannelSelector
OnClaim func(ClaimResult)
OnSettle func(SettleResult)
OnRefund func(RefundResult)
OnError func(error)
}Fields
ClaimIntervalSecs intSettleIntervalSecs intRefundIntervalSecs intMaxClaimsPerBatch intSelectClaimChannels ClaimChannelSelectorShouldSettle ShouldSettleFuncSelectRefundChannels RefundChannelSelectorOnClaim func(ClaimResult)OnSettle func(SettleResult)OnRefund func(RefundResult)OnError func(error)
type AutoSettlementContext
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:33
AutoSettlementContext is the policy context passed to caller-provided claim/settle/refund selectors.
type AutoSettlementContext struct {
Now int64
LastClaimTime int64
LastSettleTime int64
PendingSettle bool
}Fields
Now int64LastClaimTime int64LastSettleTime int64PendingSettle bool
type BatchSettlementChannelManager
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:119
BatchSettlementChannelManager handles auto-settlement of batched payment channels. Provides one-shot operations (Claim, Settle, ClaimAndSettle, Refund, RefundIdleChannels) and an interval runner via Start/Stop.
type BatchSettlementChannelManager struct {
// contains filtered or unexported fields
}func Claim(ctx context.Context, opts *ClaimOptions) ([]ClaimResult, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:207
Claim collects claimable vouchers and submits them in batches.
func ClaimAndSettle(ctx context.Context, opts *ClaimOptions) ([]ClaimResult, *SettleResult, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:233
ClaimAndSettle claims any eligible vouchers, then settles when claims fired.
func GetClaimableVouchers(opts *GetClaimableVouchersOpts) ([]batchsettlement.BatchSettlementVoucherClaim, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:178
GetClaimableVouchers returns voucher claims ready for onchain settlement.
Skips entries whose chargedCumulativeAmount does not exceed totalClaimed.
func GetWithdrawalPendingSessions() ([]*ChannelSession, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:192
GetWithdrawalPendingSessions returns sessions that have a pending payer-initiated withdrawal (withdrawRequestedAt > 0).
func Refund(ctx context.Context, channelIds []string) ([]RefundResult, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:250
Refund refunds the listed channels. Channels with a live in-flight request reservation are skipped. Pass an empty slice to refund every stored channel.
func RefundIdleChannels(ctx context.Context, idleSecs int) ([]RefundResult, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:284
RefundIdleChannels cooperatively refunds channels that have been idle for at
least idleSecs seconds and still hold a non-zero balance.
func SettlementChannelManager) Settle(ctx context.Context) (*SettleResult, error)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:217
Settle transfers claimed funds to the receiver via a settle(receiver, token) call.
func Start(config AutoSettlementConfig)
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:301
Start begins auto-settlement with the given configuration. Each non-zero *IntervalSecs schedules an independent timer; jobs are queued and drained in {claim, settle, refund} priority.
func Stop(ctx context.Context, opts *StopOptions) error
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:332
type BatchSettlementEvmScheme
Source: mechanisms/evm/batch-settlement/server/scheme.go:60
BatchSettlementEvmScheme implements SchemeNetworkServer for batched settlement.
type BatchSettlementEvmScheme struct {
// contains filtered or unexported fields
}func AfterSettleHook() x402.AfterSettleHook
Source: mechanisms/evm/batch-settlement/server/hooks.go:850
AfterSettleHook returns a hook that updates local session state after the
facilitator settles. Pure state-update - Result.Extra is NOT mutated here;
EnrichSettlementResponse runs after this hook and additively adds the
server-owned chargedCumulativeAmount (and chargedAmount for deposits).
For deposits: read the facilitator's channelState snapshot, compute chargedCumulativeAmount = current + requirements.amount, store the new session state, and remember the channel snapshot so EnrichSettlementResponse can echo chargedCumulativeAmount back to the client.
For refunds: read the facilitator's post-refund channelState, store the updated session (or delete on full-refund when balance <= chargedCumulative).
For vouchers: state was already updated in BeforeSettleHook; nothing to do.
func AfterVerifyHook() x402.AfterVerifyHook
Source: mechanisms/evm/batch-settlement/server/hooks.go:364
AfterVerifyHook atomically reserves the channel and persists session state after successful verification. Busy / stale / missing-context outcomes abort.
For refund vouchers (refund: true), additionally returns a SkipHandler directive so the resource server bypasses the application handler and settles inline.
func BeforeSettleHook() x402.BeforeSettleHook
Source: mechanisms/evm/batch-settlement/server/hooks.go:563
BeforeSettleHook returns a hook that implements the core batched settlement logic. For voucher payloads it:
- Increments chargedCumulativeAmount locally via UpdateChannel
- Returns a Skip result so onchain settlement is NOT triggered
- If the voucher has refund=true, rewrites the payload to a refund settle action that the facilitator will execute onchain
For deposit payloads it annotates responseExtra with the new charged amount. All other payload types pass through to the facilitator.
func BeforeVerifyHook() x402.BeforeVerifyHook
Source: mechanisms/evm/batch-settlement/server/hooks.go:81
BeforeVerifyHook binds the claimed channelId and reads a channel snapshot. This phase performs no storage mutation. Reservation + persist happen in AfterVerifyHook after successful verification.
func ClearPendingRequest(payload any) error
Source: mechanisms/evm/batch-settlement/server/scheme.go:273
ClearPendingRequest clears this request's pending reservation in storage, without affecting any newer reservation that may have replaced it. If the stored channel only existed for this reservation (no snapshot), the channel record is deleted entirely.
func CreateChannelManager(facilitator x402.FacilitatorClient, network x402.Network) *BatchSettlementChannelManager
Source: mechanisms/evm/batch-settlement/server/scheme.go:702
CreateChannelManager creates a new channel manager for auto-settlement rooted at this scheme's receiver and the network's default settlement asset.
Pass a custom token via NewBatchSettlementChannelManager directly when you need a non-default settlement asset for this manager.
func DeleteSession(channelId string) error
Source: mechanisms/evm/batch-settlement/server/scheme.go:727
DeleteSession removes a session for a channel.
func EnhancePaymentRequirements( ctx context.Context, requirements types.PaymentRequirements, supportedKind types.SupportedKind, extensionKeys []string, ) (types.PaymentRequirements, error)
Source: mechanisms/evm/batch-settlement/server/scheme.go:511
EnhancePaymentRequirements adds batched-specific fields to payment requirements.
func EnrichPaymentRequiredResponse(ctx x402.PaymentRequiredContext)
Source: mechanisms/evm/batch-settlement/server/scheme.go:299
EnrichPaymentRequiredResponse implements x402.PaymentRequiredEnricher. On a cumulative-amount-mismatch verify failure it adds corrective ChannelState (sourced first from a BeforeVerifyHook snapshot, then from storage) to each matching batch-settlement requirement so the client can resync.
func EnrichSettlementPayload(ctx x402.SettleContext) (map[string]interface{}, error)
Source: mechanisms/evm/batch-settlement/server/hooks.go:727
EnrichSettlementPayload supplies server-owned settlement-payload fields
before the facilitator settles. For refund payloads it returns the additive
{amount?, refundNonce, claims, refundAuthorizerSignature?, claimAuthorizerSignature?}
map; the framework's additive policy (AssertAdditivePayloadEnrichment)
rejects any attempt to overwrite existing client-set keys.
Returns nil for non-refund payloads. Returns a structured error on validation failure; the framework converts it into a settle abort with the error string as the reason.
func EnrichSettlementResponse(ctx x402.SettleResultContext) (map[string]interface{}, error)
Source: mechanisms/evm/batch-settlement/server/hooks.go:1024
EnrichSettlementResponse supplies server-owned settlement-response fields
after the facilitator settles. Returns the additive
{channelState: {chargedCumulativeAmount}, chargedAmount?} map so the
framework can deep-merge it into result.extra without overwriting the
channelState.{balance,totalClaimed,...} fields the facilitator already
populated.
The snapshot is set by EnrichSettlementPayload (refund) or by AfterSettleHook (deposit) via RememberChannelSnapshot.
func GetAssetDecimals(asset string, network x402.Network) int
Source: mechanisms/evm/batch-settlement/server/scheme.go:398
GetAssetDecimals implements AssetDecimalsProvider.
func GetOnchainStateTtlMs() int64
Source: mechanisms/evm/batch-settlement/server/scheme.go:170
GetOnchainStateTtlMs returns the configured TTL (in ms) for trusting cached onchain channel state for local voucher verification.
func GetReceiverAddress() string
Source: mechanisms/evm/batch-settlement/server/scheme.go:418
GetReceiverAddress returns the receiver address.
func GetReceiverAuthorizerAddress() string
Source: mechanisms/evm/batch-settlement/server/scheme.go:428
GetReceiverAuthorizerAddress returns the receiver authorizer's address.
func GetSession(channelId string) (*ChannelSession, error)
Source: mechanisms/evm/batch-settlement/server/scheme.go:722
GetSession retrieves a session for a channel.
func GetStorage() SessionStorage
Source: mechanisms/evm/batch-settlement/server/scheme.go:413
GetStorage returns the underlying session storage.
func GetWithdrawDelay() int
Source: mechanisms/evm/batch-settlement/server/scheme.go:423
GetWithdrawDelay returns the configured withdraw delay.
func MergeRequestContext(payload any, partial BatchSettlementRequestContext)
Source: mechanisms/evm/batch-settlement/server/scheme.go:195
MergeRequestContext merges fields into the per-payload request context, creating one if none exists.
func OnSettleFailureHook() x402.OnSettleFailureHook
Source: mechanisms/evm/batch-settlement/server/hooks.go:709
OnSettleFailureHook releases a reservation when facilitator settlement fails.
func OnVerifiedPaymentCanceledHook() x402.OnVerifiedPaymentCanceledHook
Source: mechanisms/evm/batch-settlement/server/scheme.go:368
OnVerifiedPaymentCanceledHook returns a hook that releases this request's pending reservation when the resource handler errors or returns a non-2xx response.
func OnVerifyFailureHook() x402.OnVerifyFailureHook
Source: mechanisms/evm/batch-settlement/server/hooks.go:545
OnVerifyFailureHook releases a reservation when facilitator verification fails.
func ParsePrice(price x402.Price, network x402.Network) (x402.AssetAmount, error)
Source: mechanisms/evm/batch-settlement/server/scheme.go:461
ParsePrice parses a price and converts it to an asset amount.
func ReadRequestContext(payload any) *BatchSettlementRequestContext
Source: mechanisms/evm/batch-settlement/server/scheme.go:225
ReadRequestContext returns the per-payload request context without clearing it.
func RegisterMoneyParser(parser x402.MoneyParser) *BatchSettlementEvmScheme
Source: mechanisms/evm/batch-settlement/server/scheme.go:407
RegisterMoneyParser registers a custom money parser.
func RememberChannelSnapshot(payload any, session *ChannelSession)
Source: mechanisms/evm/batch-settlement/server/scheme.go:250
RememberChannelSnapshot stores a channel snapshot keyed to a specific payload so EnrichPaymentRequiredResponse can echo it in the corrective 402.
func Scheme) Scheme() string
Source: mechanisms/evm/batch-settlement/server/scheme.go:393
Scheme returns the scheme identifier.
func SignClaimBatch(ctx context.Context, claims []batchsettlement.BatchSettlementVoucherClaim, network string) ([]byte, error)
Source: mechanisms/evm/batch-settlement/server/scheme.go:648
SignClaimBatch signs a ClaimBatch EIP-712 message.
func SignRefund(ctx context.Context, channelId string, amount string, nonce string, network string) ([]byte, error)
Source: mechanisms/evm/batch-settlement/server/scheme.go:597
SignRefund signs a cooperative refund EIP-712 message.
func TakeChannelSnapshot(payload any) *ChannelSession
Source: mechanisms/evm/batch-settlement/server/scheme.go:261
TakeChannelSnapshot reads and clears the channel snapshot for a payload.
func TakeRequestContext(payload any) *BatchSettlementRequestContext
Source: mechanisms/evm/batch-settlement/server/scheme.go:236
TakeRequestContext reads and clears the per-payload request context.
func UpdateSession(channelId string, session *ChannelSession) error
Source: mechanisms/evm/batch-settlement/server/scheme.go:717
UpdateSession updates or creates a session for a channel.
func ValidateFacilitatorSupport( network x402.Network, supportedKind types.SupportedKind, _ []string, ) error
Source: mechanisms/evm/batch-settlement/server/scheme.go:438
ValidateFacilitatorSupport rejects startup when this scheme delegates the receiver-authorizer role but the facilitator does not advertise a usable receiverAuthorizer.
type BatchSettlementEvmSchemeServerConfig
Source: mechanisms/evm/batch-settlement/server/scheme.go:46
BatchSettlementEvmSchemeServerConfig configures the batched server scheme.
type BatchSettlementEvmSchemeServerConfig struct {
// Storage is the session persistence backend. Defaults to in-memory.
Storage SessionStorage
// ReceiverAuthorizerSigner is the server-controlled key for signing refund/claim authorizations.
ReceiverAuthorizerSigner AuthorizerSigner
// WithdrawDelay is the withdraw delay in seconds. Defaults to 900 (15 min).
WithdrawDelay int
// OnchainStateTtlMs is the maximum age of cached onchain state, in
// milliseconds, that may be trusted for local voucher verification.
// When zero, derived from WithdrawDelay (clamped between 30s and 5min).
OnchainStateTtlMs int64
}Fields
Storage SessionStorageStorage is the session persistence backend. Defaults to in-memory.
ReceiverAuthorizerSigner AuthorizerSignerReceiverAuthorizerSigner is the server-controlled key for signing refund/claim authorizations.
WithdrawDelay intWithdrawDelay is the withdraw delay in seconds. Defaults to 900 (15 min).
OnchainStateTtlMs int64OnchainStateTtlMs is the maximum age of cached onchain state, in milliseconds, that may be trusted for local voucher verification. When zero, derived from WithdrawDelay (clamped between 30s and 5min).
type BatchSettlementRequestContext
Source: mechanisms/evm/batch-settlement/server/scheme.go:20
BatchSettlementRequestContext carries per-request state across the verify->settle lifecycle for a single payment.
type BatchSettlementRequestContext struct {
ChannelId string
PendingId string
ChannelSnapshot *ChannelSession
LocalVerify bool
ReservationCommitted bool
}Fields
ChannelId stringPendingId stringChannelSnapshot *ChannelSessionLocalVerify boolReservationCommitted bool
type ChannelManagerConfig
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:23
ChannelManagerConfig wires the channel manager to its dependencies.
Receiver and Token are required: the manager calls
settle(receiver, token) directly, so storage may be empty when settle()
fires, for example immediately after a flush.
type ChannelManagerConfig struct {
Scheme *BatchSettlementEvmScheme
Facilitator x402.FacilitatorClient
Receiver string
Token string
Network x402.Network
}Fields
Scheme *BatchSettlementEvmSchemeFacilitator x402.FacilitatorClientReceiver stringToken stringNetwork x402.Network
type ChannelSession
Source: mechanisms/evm/batch-settlement/server/storage.go:20
ChannelSession holds per-channel session state on the server side.
type ChannelSession struct {
ChannelId string `json:"channelId"`
ChannelConfig batchsettlement.ChannelConfig `json:"channelConfig"`
ChargedCumulativeAmount string `json:"chargedCumulativeAmount"`
SignedMaxClaimable string `json:"signedMaxClaimable"`
Signature string `json:"signature"`
Balance string `json:"balance"`
TotalClaimed string `json:"totalClaimed"`
WithdrawRequestedAt int `json:"withdrawRequestedAt"`
RefundNonce int `json:"refundNonce"`
LastRequestTimestamp int64 `json:"lastRequestTimestamp"`
// OnchainSyncedAt is the wall-clock time (unix millis) when balance/totalClaimed/
// withdrawRequestedAt/refundNonce were last refreshed from onchain state.
// Used by the local voucher verifier to decide whether to skip facilitator verify.
OnchainSyncedAt int64 `json:"onchainSyncedAt,omitempty"`
// PendingRequest is the in-flight reservation for this channel, if any.
PendingRequest *PendingRequest `json:"pendingRequest,omitempty"`
}Fields
ChannelId string`json:"channelId"`ChannelConfig batchsettlement.ChannelConfig`json:"channelConfig"`ChargedCumulativeAmount string`json:"chargedCumulativeAmount"`SignedMaxClaimable string`json:"signedMaxClaimable"`Signature string`json:"signature"`Balance string`json:"balance"`TotalClaimed string`json:"totalClaimed"`WithdrawRequestedAt int`json:"withdrawRequestedAt"`RefundNonce int`json:"refundNonce"`LastRequestTimestamp int64`json:"lastRequestTimestamp"`OnchainSyncedAt int64`json:"onchainSyncedAt,omitempty"`OnchainSyncedAt is the wall-clock time (unix millis) when balance/totalClaimed/ withdrawRequestedAt/refundNonce were last refreshed from onchain state. Used by the local voucher verifier to decide whether to skip facilitator verify.
PendingRequest *PendingRequest`json:"pendingRequest,omitempty"`PendingRequest is the in-flight reservation for this channel, if any.
type ChannelUpdateResult
Source: mechanisms/evm/batch-settlement/server/storage.go:49
ChannelUpdateResult is the result of an UpdateChannel call.
type ChannelUpdateResult struct {
Channel *ChannelSession
Status ChannelUpdateStatus
}Fields
Channel *ChannelSessionStatus ChannelUpdateStatus
type ChannelUpdateStatus
Source: mechanisms/evm/batch-settlement/server/storage.go:40
ChannelUpdateStatus describes the outcome of an UpdateChannel call.
type ChannelUpdateStatus stringtype ClaimChannelSelector
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:44
ClaimChannelSelector picks the channel set the manager should consider for
claiming on each pass. Returning a subset of channels is the supported way
to express custom claim policy (e.g. only channels with non-trivial pending
amounts).
type ClaimChannelSelector func(channels []*ChannelSession, ctx AutoSettlementContext) ([]*ChannelSession, error)type ClaimOptions
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:54
ClaimOptions tunes a one-shot Claim call.
type ClaimOptions struct {
// MaxClaimsPerBatch caps the number of vouchers per facilitator claim tx.
// Defaults to 100.
MaxClaimsPerBatch int
// IdleSecs filters out channels that received a request within the last
// `IdleSecs` seconds. Zero means "no idle filter".
IdleSecs int
// SelectClaimChannels narrows the channel set considered for claiming.
SelectClaimChannels ClaimChannelSelector
}Fields
MaxClaimsPerBatch intMaxClaimsPerBatch caps the number of vouchers per facilitator claim tx. Defaults to 100.
IdleSecs intIdleSecs filters out channels that received a request within the last
IdleSecsseconds. Zero means "no idle filter".SelectClaimChannels ClaimChannelSelectorSelectClaimChannels narrows the channel set considered for claiming.
type ClaimResult
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:86
ClaimResult is one batch worth of claim submission.
type ClaimResult struct {
Vouchers int
Transaction string
}Fields
Vouchers intTransaction string
type FileChannelStorage
Source: mechanisms/evm/batch-settlement/server/file_storage.go:19
FileChannelStorage is a file-backed SessionStorage. Each session is stored as {root}/server/{channelId}.json. CompareAndSet is serialised through an exclusive lock file ({channelId}.json.lock) so concurrent writers see the loser as a no-op rather than racing.
type FileChannelStorage struct {
// contains filtered or unexported fields
}func CompareAndSet(channelId string, expectedCharged string, session *ChannelSession) (bool, error)
Source: mechanisms/evm/batch-settlement/server/file_storage.go:108
CompareAndSet uses an exclusive lock file to serialise concurrent writers. The mkdir call ensures the very first CompareAndSet on a fresh directory does not fail with ENOENT on the lock file.
func Delete(channelId string) error
Source: mechanisms/evm/batch-settlement/server/file_storage.go:60
func Get(channelId string) (*ChannelSession, error)
Source: mechanisms/evm/batch-settlement/server/file_storage.go:36
func List() ([]*ChannelSession, error)
Source: mechanisms/evm/batch-settlement/server/file_storage.go:71
func Set(channelId string, session *ChannelSession) error
Source: mechanisms/evm/batch-settlement/server/file_storage.go:52
func UpdateChannel(channelId string, update func(current *ChannelSession) *ChannelSession) (*ChannelUpdateResult, error)
Source: mechanisms/evm/batch-settlement/server/file_storage.go:149
UpdateChannel atomically reads, mutates, and writes a channel record under an exclusive lock file. Returning a different pointer commits the new session; returning nil deletes the file; returning the same pointer is treated as a no-op (status: unchanged).
type GetClaimableVouchersOpts
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:172
GetClaimableVouchersOpts filters claimable vouchers by idle time.
type GetClaimableVouchersOpts struct {
IdleSecs int
}Fields
IdleSecs int
type InMemoryChannelStorage
Source: mechanisms/evm/batch-settlement/server/storage.go:81
InMemoryChannelStorage is a volatile in-memory implementation of SessionStorage.
Note on unbounded growth: the per-channel lock map is allocated lazily and dropped when Delete is called for that channel. For long-lived servers that see an effectively unbounded set of distinct channelIds without ever calling Delete, this map will grow over time. Production deployments backed by a persistent store (e.g. FileChannelStorage) should prefer Delete-on-drain.
type InMemoryChannelStorage struct {
// contains filtered or unexported fields
}func CompareAndSet(channelId string, expectedCharged string, session *ChannelSession) (bool, error)
Source: mechanisms/evm/batch-settlement/server/storage.go:160
func Delete(channelId string) error
Source: mechanisms/evm/batch-settlement/server/storage.go:133
func Get(channelId string) (*ChannelSession, error)
Source: mechanisms/evm/batch-settlement/server/storage.go:106
func List() ([]*ChannelSession, error)
Source: mechanisms/evm/batch-settlement/server/storage.go:149
func Set(channelId string, session *ChannelSession) error
Source: mechanisms/evm/batch-settlement/server/storage.go:121
func UpdateChannel(channelId string, update func(current *ChannelSession) *ChannelSession) (*ChannelUpdateResult, error)
Source: mechanisms/evm/batch-settlement/server/storage.go:176
type PendingRequest
Source: mechanisms/evm/batch-settlement/server/storage.go:13
PendingRequest reserves a channel against concurrent same-channel requests. A request is allowed when no live (unexpired) pending entry exists. Cleanup hooks clear the reservation; the bounded TTL guarantees release if cleanup never runs.
type PendingRequest struct {
PendingId string `json:"pendingId"`
SignedMaxClaimable string `json:"signedMaxClaimable"`
ExpiresAt int64 `json:"expiresAt"` // unix millis
}Fields
PendingId string`json:"pendingId"`SignedMaxClaimable string`json:"signedMaxClaimable"`ExpiresAt int64`json:"expiresAt"`unix millis
type RefundChannelSelector
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:51
RefundChannelSelector picks idle channels for cooperative refund.
type RefundChannelSelector func(channels []*ChannelSession, ctx AutoSettlementContext) ([]*ChannelSession, error)type RefundResult
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:99
RefundResult is one cooperative refund transaction (one channel).
Each refunded channel returns one result.
type RefundResult struct {
Channel string
Transaction string
}Fields
Channel stringTransaction string
type SessionStorage
Source: mechanisms/evm/batch-settlement/server/storage.go:55
SessionStorage is the interface for persisting server-side channel sessions.
type SessionStorage interface {
Get(channelId string) (*ChannelSession, error)
Set(channelId string, session *ChannelSession) error
Delete(channelId string) error
List() ([]*ChannelSession, error)
// CompareAndSet atomically updates a session only if the current
// chargedCumulativeAmount matches expectedCharged. Returns true if the
// swap succeeded, false if the value changed underneath (concurrent request).
//
// Deprecated: prefer UpdateChannel for richer atomic mutations.
CompareAndSet(channelId string, expectedCharged string, session *ChannelSession) (bool, error)
// UpdateChannel atomically inspects and mutates a channel record.
// The update callback receives the current session (or nil) and returns
// the next session (or nil to delete). Returning the unchanged input is
// a no-op (status: unchanged). The implementation must guarantee no
// concurrent mutation can interleave between read and write.
UpdateChannel(channelId string, update func(current *ChannelSession) *ChannelSession) (*ChannelUpdateResult, error)
}Methods
Get func(channelId string) (*ChannelSession, error)Set func(channelId string, session *ChannelSession) errorDelete func(channelId string) errorList func() ([]*ChannelSession, error)CompareAndSet func(channelId string, expectedCharged string, session *ChannelSession) (bool, error)CompareAndSet atomically updates a session only if the current chargedCumulativeAmount matches expectedCharged. Returns true if the swap succeeded, false if the value changed underneath (concurrent request).
Deprecated: prefer UpdateChannel for richer atomic mutations.
UpdateChannel func(channelId string, update func(current *ChannelSession) *ChannelSession) (*ChannelUpdateResult, error)UpdateChannel atomically inspects and mutates a channel record. The update callback receives the current session (or nil) and returns the next session (or nil to delete). Returning the unchanged input is a no-op (status: unchanged). The implementation must guarantee no concurrent mutation can interleave between read and write.
type SettleResult
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:92
SettleResult is one settle transaction.
type SettleResult struct {
Transaction string
}Fields
Transaction string
type ShouldSettleFunc
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:48
ShouldSettleFunc decides whether a settle pass should fire for this tick. Return false to skip; the next interval will re-evaluate.
type ShouldSettleFunc func(ctx AutoSettlementContext) (bool, error)type StopOptions
Source: mechanisms/evm/batch-settlement/server/channel_manager.go:328
Stop halts auto-settlement. When opts.Flush is true, runs a final ClaimAndSettle before returning.
type StopOptions struct {
Flush bool
}Fields
Flush bool
