Replace the design-note docs (p1–p7) with the implemented "make it real" phase docs (p8–p10) and wire production-grade, env-gated real integrations: - p8 Casper Testnet: byte-exact deploys + WASM install via casper-js-sdk; live node reads (node.testnet.casper.network); CRED402_CHAIN=sim|testnet transport. - p9 x402 + data + MCP: real EIP-712 typed-data digests (@casper-ecosystem/ casper-eip-712); casper-x402 facilitator client (x402 V2); live Open-Meteo GHI; official @modelcontextprotocol/sdk server; casper-sidecar SSE event feed. - p10 RealFi + cross-chain: real Stripe test-mode webhooks (HMAC-verified) and Plaid sandbox → privacy-preserving on-chain envelopes; Base Sepolia EVM deploy (Foundry); reachable via /api/realfi/* and /api/x402/facilitator routes. - Sign-in with Casper Wallet: real extension provider + challenge/ed25519/session flow (/v1/auth/wallet/*), console connect + sign-in button. - Branding: Cred402 logo mark, favicon, OG image; Vercel config for the console. All env-gated with sim/free-API fallbacks; full suite green, all toolchains (TS/Rust/Go/Solidity) build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
// Package sink persists projections. The Sink interface is what a Postgres /
|
|
// ClickHouse writer implements in production; here we ship Stdout and File sinks
|
|
// so the indexer is fully runnable without a database.
|
|
package sink
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/cred402/event-indexer/internal/projections"
|
|
)
|
|
|
|
type Sink interface {
|
|
Write(store *projections.Store) error
|
|
}
|
|
|
|
// StdoutSink pretty-prints the projection set.
|
|
type StdoutSink struct{ W io.Writer }
|
|
|
|
func (s StdoutSink) Write(store *projections.Store) error {
|
|
w := s.W
|
|
if w == nil {
|
|
w = os.Stdout
|
|
}
|
|
enc := json.NewEncoder(w)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(view(store))
|
|
}
|
|
|
|
// FileSink writes the projection set to a JSON file atomically.
|
|
type FileSink struct{ Path string }
|
|
|
|
func (s FileSink) Write(store *projections.Store) error {
|
|
tmp := s.Path + ".tmp"
|
|
b, err := json.MarshalIndent(view(store), "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(tmp, b, 0o644); err != nil {
|
|
return err
|
|
}
|
|
return os.Rename(tmp, s.Path)
|
|
}
|
|
|
|
// view is the JSON-serializable projection (sorted agents + pool + checkpoint).
|
|
func view(store *projections.Store) map[string]any {
|
|
return map[string]any{
|
|
"checkpoint": store.LastSeq,
|
|
"events_applied": store.EventsApplied,
|
|
"disputes_opened": store.Disputes,
|
|
"pool": store.Pool,
|
|
"agents": store.SortedAgents(),
|
|
}
|
|
}
|