Documentation
¶
Index ¶
- type Config
- type Reconciler
- func (r *Reconciler) FullBalanceReconciliation(ctx context.Context) error
- func (r *Reconciler) GetReconciliationStatus(ctx context.Context) (*reconcilerstore.ReconciliationState, error)
- func (r *Reconciler) ReconcileAll(ctx context.Context) error
- func (r *Reconciler) ReconcileFromBridgeEvents(ctx context.Context) error
- func (r *Reconciler) ReconcileUserBalancesFromHoldings(ctx context.Context) error
- func (r *Reconciler) StartPeriodicReconciliation(interval time.Duration)
- func (r *Reconciler) Stop()
- type Store
- type UserStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
InitialTimeout time.Duration `yaml:"initial_timeout" default:"2m"`
Interval time.Duration `yaml:"interval" default:"5m"`
}
Config contains settings for balance reconciliation
type Reconciler ¶
type Reconciler struct {
// contains filtered or unexported fields
}
Reconciler handles synchronization between Canton ledger state and DB cache
func New ¶
func New( store Store, userStore UserStore, cantonClient canton.Token, logger *zap.Logger, ) *Reconciler
New creates a new Reconciler
func (*Reconciler) FullBalanceReconciliation ¶
func (r *Reconciler) FullBalanceReconciliation(ctx context.Context) error
FullBalanceReconciliation performs a complete balance reset and rebuild from bridge events. This should be used sparingly, e.g., on startup or when data inconsistencies are detected.
This function: 1. Resets all user balances to 0 2. Clears the bridge_events table (to prevent double-counting) 3. Calls ReconcileFromBridgeEvents to rebuild both balances and event log
Note: Only mint/burn events are considered since transfers are internal Canton operations.
func (*Reconciler) GetReconciliationStatus ¶
func (r *Reconciler) GetReconciliationStatus(ctx context.Context) (*reconcilerstore.ReconciliationState, error)
GetReconciliationStatus returns the current reconciliation state
func (*Reconciler) ReconcileAll ¶
func (r *Reconciler) ReconcileAll(ctx context.Context) error
ReconcileAll synchronizes total supply and user balances from Canton. This method: 1. Calculates total supply from all CIP56Holding contracts 2. Updates registered users' balances based on their Canton party holdings
User balances are reconciled from Canton holdings, which catches ALL balance changes including transfers made directly on the Canton ledger (e.g., by native Canton users).
func (*Reconciler) ReconcileFromBridgeEvents ¶
func (r *Reconciler) ReconcileFromBridgeEvents(ctx context.Context) error
ReconcileFromBridgeEvents fetches all bridge events from Canton and reconciles user balances based on mint/burn events. This provides an authoritative source of truth from the Canton ledger for user balances. Note: Transfers are internal Canton operations and don't affect bridge reconciliation.
func (*Reconciler) ReconcileUserBalancesFromHoldings ¶
func (r *Reconciler) ReconcileUserBalancesFromHoldings(ctx context.Context) error
ReconcileUserBalancesFromHoldings queries all CIP56Holding contracts from Canton and updates registered users' balances in the database. This catches ALL balance changes including transfers made directly on the Canton ledger.
func (*Reconciler) StartPeriodicReconciliation ¶
func (r *Reconciler) StartPeriodicReconciliation(interval time.Duration)
StartPeriodicReconciliation starts a background goroutine that reconciles periodically
type Store ¶
type Store interface {
SetBalanceByCantonPartyID(ctx context.Context, partyID, tokenSymbol, balance string) error
ResetBalancesByTokenSymbol(ctx context.Context, tokenSymbol string) error
SetTotalSupply(ctx context.Context, tokenSymbol, value string) error
UpdateLastReconciled(ctx context.Context, tokenSymbol string) error
GetReconciliationState(ctx context.Context) (*reconcilerstore.ReconciliationState, error)
MarkFullReconcileComplete(ctx context.Context) error
IsEventProcessed(ctx context.Context, contractID string) (bool, error)
StoreTokenTransferEvent(ctx context.Context, event *canton.TokenTransferEvent) error
ClearBridgeEvents(ctx context.Context) error
}
Store provides reconciler data operations.