balance

package
v0.0.0-...-7f47b3a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package balance provides a generic chain-agnostic balance monitoring service that tracks account balances across different blockchain networks.

Package balance provides a generic chain-agnostic balance monitoring service that tracks account balances across different blockchain networks.

Package balance provides a generic chain-agnostic balance monitoring service that tracks account balances across different blockchain networks.

Index

Constants

View Source
const (
	// WorkflowExecutionIDShortLen is the length of the short version of the WorkflowExecutionId (label)
	WorkflowExecutionIDShortLen = 3 // first 3 characters, 16^3 = 4.096 possibilities (mid-high cardinality)
)

Variables

This section is empty.

Functions

func NewGenericBalanceMonitor

func NewGenericBalanceMonitor(opts GenericBalanceMonitorOpts) (services.Service, error)

NewGenericBalanceMonitor returns a balance monitoring services.Service which reports the balance of all Keystore accounts.

func ValOrUnknown

func ValOrUnknown(val string) string

ValOrUnknown returns the value if it is not empty, otherwise it returns "unknown" This is needed to avoid issues during exporting OTel metrics to Prometheus For more details see https://smartcontract-it.atlassian.net/browse/INFOPLAT-1349

func ValShortOrUnknown

func ValShortOrUnknown(val string, maxLen int) string

ValShortOrUnknown returns the short len value if not empty or available, otherwise it returns "unknown"

Types

type ChainInfo

type ChainInfo struct {
	ChainFamilyName string
	ChainID         string
	NetworkName     string
	NetworkNameFull string
}

ChainInfo contains information about the blockchain network.

type ExecutionMetadata

type ExecutionMetadata struct {
	// Execution Context - Source
	SourceID string
	// Execution Context - Chain
	ChainFamilyName string
	ChainID         string
	NetworkName     string
	NetworkNameFull string
	// Execution Context - Workflow (capabilities.RequestMetadata)
	WorkflowID               string
	WorkflowOwner            string
	WorkflowExecutionID      string
	WorkflowName             string
	WorkflowDonID            uint32
	WorkflowDonConfigVersion uint32
	ReferenceID              string
	// Execution Context - Capability
	CapabilityType           string
	CapabilityID             string
	CapabilityTimestampStart uint32
	CapabilityTimestampEmit  uint32
}

TODO: Refactor as a proto referenced from the other proto files (telemetry messages)

func (ExecutionMetadata) Attributes

func (m ExecutionMetadata) Attributes() []attribute.KeyValue

Attributes returns common attributes used for metrics

type GaugeAccBalance

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

GaugeAccBalance defines a new gauge metric for account balance

func NewGaugeAccBalance

func NewGaugeAccBalance(unitStr string) (*GaugeAccBalance, error)

func (*GaugeAccBalance) GetAttributes

func (g *GaugeAccBalance) GetAttributes(account string, chainInfo ChainInfo) attribute.Set

func (*GaugeAccBalance) Record

func (g *GaugeAccBalance) Record(ctx context.Context, balance float64, account string, chainInfo ChainInfo)

type GenericBalanceClient

type GenericBalanceClient interface {
	GetAccountBalance(addr string) (float64, error)
}

GenericBalanceClient defines the interface for getting account balances.

type GenericBalanceConfig

type GenericBalanceConfig struct {
	BalancePollPeriod config.Duration
}

Config defines the balance monitor configuration.

type GenericBalanceMonitorOpts

type GenericBalanceMonitorOpts struct {
	ChainInfo           ChainInfo
	ChainNativeCurrency string

	Config                  GenericBalanceConfig
	Logger                  logger.Logger
	Keystore                core.Keystore
	NewGenericBalanceClient func() (GenericBalanceClient, error)

	// Maps a public key to an account address (optional, can return key as is)
	KeyToAccountMapper func(context.Context, string) (string, error)
}

GenericBalanceMonitorOpts contains the options for creating a new balance monitor.

Jump to

Keyboard shortcuts

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