Files
commerce/models/husdcursor/husdcursor.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

35 lines
1.1 KiB
Go

// Package husdcursor persists the HUSD indexer's scan position: the last block
// fully projected into the ledger, per chain. It lets a restart resume rather
// than rescan from genesis. The record is a singleton per chain id (deterministic
// storage id), lives in the global "system" namespace, and carries no money — it
// is pure indexer bookkeeping.
package husdcursor
import (
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/models/mixin"
"github.com/hanzoai/orm"
)
func init() {
orm.Register[HUSDCursor]("husd-cursor", orm.WithStringKey[HUSDCursor]())
}
// HUSDCursor is the indexer's last fully-scanned block for one chain.
type HUSDCursor struct {
mixin.Model[HUSDCursor]
ChainID int64 `json:"chainId"`
LastBlock uint64 `json:"lastBlock"`
}
func (c *HUSDCursor) Load(ps []datastore.Property) error { return datastore.LoadStruct(c, ps) }
func (c *HUSDCursor) Save() ([]datastore.Property, error) { return datastore.SaveStruct(c) }
// New returns an initialized HUSDCursor bound to db.
func New(db *datastore.Datastore) *HUSDCursor {
c := new(HUSDCursor)
c.Init(db)
return c
}