store

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BridgeEventDao

type BridgeEventDao struct {
	bun.BaseModel        `bun:"table:bridge_events"`
	ID                   int64      `bun:",pk,autoincrement"`
	EventType            string     `bun:",notnull,type:varchar(20)"`
	ContractID           string     `bun:",unique,notnull,type:varchar(255)"`
	Fingerprint          *string    `bun:",type:varchar(128)"`
	RecipientFingerprint *string    `bun:"recipient_fingerprint,type:varchar(128)"`
	Amount               string     `bun:",notnull,type:numeric(38,18)"`
	EvmTxHash            *string    `bun:"evm_tx_hash,type:varchar(66)"`
	EvmDestination       *string    `bun:"evm_destination,type:varchar(42)"`
	TokenSymbol          *string    `bun:"token_symbol,type:varchar(20)"`
	CantonTimestamp      *time.Time `bun:"canton_timestamp"`
	ProcessedAt          time.Time  `bun:",nullzero,notnull,default:current_timestamp"`
}

BridgeEventDao maps to bridge_events table in PostgreSQL.

type PGStore

type PGStore struct {
	// contains filtered or unexported fields
}

PGStore is a PostgreSQL-backed reconciler store.

func NewStore

func NewStore(db *bun.DB) *PGStore

NewStore creates a new PostgreSQL-backed reconciler store.

func (*PGStore) ClearBridgeEvents

func (s *PGStore) ClearBridgeEvents(ctx context.Context) error

ClearBridgeEvents clears all bridge events and resets processed counter.

func (*PGStore) DecrementBalanceByEVMAddress

func (s *PGStore) DecrementBalanceByEVMAddress(ctx context.Context, evmAddress, amount, tokenSymbol string) error

DecrementBalanceByEVMAddress decrements a user's token balance by amount.

func (*PGStore) GetBalanceByEVMAddress

func (s *PGStore) GetBalanceByEVMAddress(ctx context.Context, evmAddress, tokenSymbol string) (string, error)

GetBalanceByEVMAddress returns the stored user balance for token and EVM address.

func (*PGStore) GetBalanceByFingerprint

func (s *PGStore) GetBalanceByFingerprint(ctx context.Context, fingerprint, tokenSymbol string) (string, error)

GetBalanceByFingerprint returns the stored user balance for token and fingerprint.

func (*PGStore) GetReconciliationState

func (s *PGStore) GetReconciliationState(ctx context.Context) (*ReconciliationState, error)

GetReconciliationState returns the current reconciliation status.

func (*PGStore) IncrementBalanceByFingerprint

func (s *PGStore) IncrementBalanceByFingerprint(ctx context.Context, fingerprint, amount, tokenSymbol string) error

IncrementBalanceByFingerprint increments a user's token balance by amount.

func (*PGStore) IsEventProcessed

func (s *PGStore) IsEventProcessed(ctx context.Context, contractID string) (bool, error)

IsEventProcessed checks if a bridge event was already processed.

func (*PGStore) MarkFullReconcileComplete

func (s *PGStore) MarkFullReconcileComplete(ctx context.Context) error

MarkFullReconcileComplete marks reconciliation completion timestamp.

func (*PGStore) ResetBalancesByTokenSymbol

func (s *PGStore) ResetBalancesByTokenSymbol(ctx context.Context, tokenSymbol string) error

ResetBalancesByTokenSymbol resets all balances for the given token symbol to zero.

func (*PGStore) SetBalanceByCantonPartyID

func (s *PGStore) SetBalanceByCantonPartyID(ctx context.Context, partyID, tokenSymbol, balance string) error

SetBalanceByCantonPartyID sets an absolute balance for a user/token pair. It upserts based on (canton_party_id, token_symbol) in user_token_balances.

func (*PGStore) SetTotalSupply

func (s *PGStore) SetTotalSupply(ctx context.Context, tokenSymbol, value string) error

SetTotalSupply sets the total supply for a token.

func (*PGStore) StoreTokenTransferEvent

func (s *PGStore) StoreTokenTransferEvent(ctx context.Context, event *canton.TokenTransferEvent) error

StoreTokenTransferEvent stores a token transfer event and updates user balances atomically. MINT events credit balances, BURN events debit balances, TRANSFER events are ignored.

func (*PGStore) UpdateLastReconciled

func (s *PGStore) UpdateLastReconciled(ctx context.Context, tokenSymbol string) error

UpdateLastReconciled updates the last reconciled timestamp for a token.

func (*PGStore) UpdateReconciliationOffset

func (s *PGStore) UpdateReconciliationOffset(ctx context.Context, offset int64) error

UpdateReconciliationOffset updates the reconciliation offset cursor.

type ReconciliationState

type ReconciliationState struct {
	LastProcessedOffset int64      `json:"last_processed_offset"`
	LastFullReconcileAt *time.Time `json:"last_full_reconcile_at,omitempty"`
	EventsProcessed     int        `json:"events_processed"`
	UpdatedAt           time.Time  `json:"updated_at"`
}

ReconciliationState tracks reconciliation progress.

type ReconciliationStateDao

type ReconciliationStateDao struct {
	bun.BaseModel       `bun:"table:reconciliation_state"`
	ID                  int        `bun:",pk,notnull"`
	LastProcessedOffset int64      `bun:"last_processed_offset,notnull,default:0"`
	LastFullReconcileAt *time.Time `bun:"last_full_reconcile_at"`
	EventsProcessed     int        `bun:"events_processed,notnull,default:0"`
	UpdatedAt           time.Time  `bun:",nullzero,notnull,default:current_timestamp"`
}

ReconciliationStateDao maps to reconciliation_state table in PostgreSQL.

type TokenMetricsDao

type TokenMetricsDao struct {
	bun.BaseModel    `bun:"table:token_metrics"`
	TokenSymbol      string     `bun:",pk,notnull,type:varchar(20)"`
	TotalSupply      string     `bun:",notnull,type:numeric(38,18),default:'0'"`
	LastReconciledAt *time.Time `bun:"last_reconciled_at"`
	UpdatedAt        time.Time  `bun:",nullzero,notnull,default:current_timestamp"`
}

TokenMetricsDao maps to token_metrics table in PostgreSQL.

type UserTokenBalanceDao

type UserTokenBalanceDao struct {
	bun.BaseModel `bun:"table:user_token_balances,alias:utb"`
	ID            int64     `bun:"id,pk,autoincrement"`
	Fingerprint   *string   `bun:"fingerprint,type:varchar(128)"`
	TokenSymbol   string    `bun:"token_symbol,notnull,type:varchar(20)"`
	EVMAddress    *string   `bun:"evm_address,type:varchar(42)"`
	CantonPartyID *string   `bun:"canton_party_id,type:varchar(255)"`
	Balance       string    `bun:",notnull,type:numeric(38,18),default:'0'"`
	UpdatedAt     time.Time `bun:",nullzero,notnull,default:current_timestamp"`
}

UserTokenBalanceDao maps to user_token_balances table in PostgreSQL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL