Files
zeekay e4bb5aa907 feat(mpc): treasury 3-of-5 + purge Postgres, SQLite-only
- Postgres purge: delete cas_postgres_test.go, strip PG sidecar from CI
- Treasury 3-of-5 governance: pkg/api/handlers_treasury.go + models
- Routes: POST /v1/mpc/treasury/wallets, POST /v1/mpc/treasury/sign,
  GET /v1/mpc/treasury/wallets/{id}
- Per-org HSM isolation via tenant-scoped cosigner key
- Threshold escalation: small=3-of-5, large=4-of-5
2025-12-28 11:29:17 -08:00

57 lines
1.5 KiB
Go

package db
import (
"fmt"
"strings"
"github.com/hanzoai/orm"
ormdb "github.com/hanzoai/orm/db"
)
// Database holds the ORM entity store. SQLite is the only backend — the
// driver-level write mutex plus BEGIN IMMEDIATE gives us serializable
// writes across goroutines in a single process. For multi-process
// deployments the same file is accessed through the reserved-lock path,
// which is enough for the MPC dashboard's control-plane workload.
type Database struct {
ORM orm.DB
}
// New creates a Database. dsn selects the SQLite location:
//
// "" → sqlite ./mpc.db
// "sqlite://path" → sqlite at path
// "path.db" → sqlite at path (legacy)
//
// The second positional argument is kept for call-site compatibility and is
// ignored (it used to configure a KV sidecar that no longer exists).
func New(dsn, _ string) (*Database, error) {
path := "mpc.db"
switch {
case dsn == "":
// default
case strings.HasPrefix(dsn, "sqlite://"):
path = strings.TrimPrefix(dsn, "sqlite://")
case strings.HasSuffix(dsn, ".db"):
path = dsn
default:
return nil, fmt.Errorf("unsupported DSN: %q (use sqlite:// or a .db path)", dsn)
}
sqliteDB, err := ormdb.NewSQLiteDB(&ormdb.SQLiteDBConfig{Path: path})
if err != nil {
return nil, fmt.Errorf("sqlite: %w", err)
}
return &Database{
ORM: orm.AdaptDB(sqliteDB),
}, nil
}
// Close releases all database resources.
func (d *Database) Close() {
if d.ORM != nil {
d.ORM.Close()
}
}