Skip to content

feat: batch settlement go sdk#2230

Merged
Must-be-Ash merged 5 commits intomainfrom
feat/batch-settlement-go-sdk
May 8, 2026
Merged

feat: batch settlement go sdk#2230
Must-be-Ash merged 5 commits intomainfrom
feat/batch-settlement-go-sdk

Conversation

@CarsonRoscoe
Copy link
Copy Markdown
Contributor

@CarsonRoscoe CarsonRoscoe commented May 8, 2026

Follow up of PR #2164, which was automatically closed when the Typescript SDK merged to main

Description

Adds the batch-settlement EVM scheme to the Go SDK at parity with the TypeScript reference implementation, plus the
resource-server architectural changes from #2109 that batch-settlement depends on.

New: batch-settlement scheme (go/mechanisms/evm/batch-settlement/)

  • Client: BatchSettlementEvmScheme with deposit (ERC-3009 + Permit2 transports), voucher signing, channel-state recovery, corrective
    402 resync, cooperative refund (scheme.Refund(url)).
  • Facilitator: simulate-then-execute for deposit/claim/refund/settle; multicall(claim+refund) on cooperative refund; ECDSA + ERC-1271
    voucher verification.
  • Server: atomic per-channel UpdateChannel storage + PendingRequest reservations; voucher local-commit short-circuit (no on-chain
    settle for vouchers); local voucher verification when on-chain state is fresh (OnchainStateTtlMs); InMemory + File channel storage
    backends; BatchSettlementChannelManager claim/settle/refund tick loop.
  • Wire format matches TS byte-for-byte (nested extra.channelState, chargedAmount, etc.); error codes consolidated under the
    invalid_batch_settlement_evm_* prefix.

Resource-server hook architecture (go/server.go, go/server_hooks.go, go/server_hook_policy.go) — port of TS PR #2109:

  • Per-(network, scheme) hook isolation: scheme-provided hooks no longer leak into the global hook list and only fire for the matched
    scheme.
  • Hook execution order: manual → matched scheme → declared extensions (mirrors TS getLabeledHooks).
  • Extension hook adapters: extensions can declare ResourceServerExtensionHooks{...}; each hook is gated on
    ctx.DeclaredExtensions[key] being set on the route.
  • Scheme-level EnrichSettlementPayload / EnrichSettlementResponse providers, called around facilitator settle.
  • Additive-policy guards (AssertAcceptsAllowlistedAfterExtensionEnrich, AssertAdditivePayloadEnrichment,
    AssertAdditiveSettlementExtra, MergeAdditiveSettlementExtra, etc.) — full port of TS hookPolicy.ts. Replaces TS's compile-time
    DeepReadonly enforcement with runtime additive-policy enforcement.
  • New VerifyPaymentWithExtensions / SettlePaymentWithExtensions / ProcessSettlementWithExtensions /
    CreatePaymentCancellationDispatcherWithExtensions methods thread declared extensions through verify → settle → cancellation.
    Existing API methods delegate with nil for backward compat.
  • HTTP middlewares (nethttp, gin, echo) all forward result.DeclaredExtensions and honor the SkipHandler directive
    (previously only nethttp did).

Examples (examples/go/{clients,servers,facilitator}/batch-settlement/): drop-in client, server, and facilitator examples with .env-example files mirroring the TS examples.

E2E (e2e/clients/go-http, e2e/facilitators/go, e2e/servers/{gin,nethttp}): batch-settlement scenarios wired into the cross-SDK harness, exercising deposit + voucher + cooperative-refund phases across go-http × {gin, nethttp} × go-facilitator on Base Sepolia.

Tests

make test and make test-integration from /go both pass:

Cross-SDK e2e testing between Typescript and Go for batch-settlement

Checklist

  • I have formatted and linted my code
  • All new and existing tests pass
  • My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits
  • I added a changelog fragment for user-facing changes (docs-only changes can skip)

CarsonRoscoe and others added 5 commits May 6, 2026 17:43
* fix PendingRequest and refund cleanup

* fix lint

* remove duplicate payer info from storage

* fix PAYMENT-RESPONSE field ordering

* clean up comments

* consolidate ProcessSettlementWithExtensions into ProcessSettlement
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402 Ready Ready Preview, Comment May 8, 2026 0:46am

Request Review

@github-actions github-actions Bot added go sdk Changes to core v2 packages examples Changes to examples labels May 8, 2026
@CarsonRoscoe CarsonRoscoe changed the title Feat/batch settlement go sdk feat: batch settlement go sdk May 8, 2026
@CarsonRoscoe CarsonRoscoe marked this pull request as ready for review May 8, 2026 00:45
@CarsonRoscoe CarsonRoscoe requested a review from Must-be-Ash May 8, 2026 00:47
@Must-be-Ash Must-be-Ash merged commit 2b7914c into main May 8, 2026
17 checks passed
@Must-be-Ash Must-be-Ash deleted the feat/batch-settlement-go-sdk branch May 8, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples Changes to examples go sdk Changes to core v2 packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants