Adrian Clarke 7bb3102c2b feat: add errors.Is wrapper and implement prometheus metrics gathering
- Add Is() function to errors package wrapping stdlib errors.Is
- Uncomment and fix Prometheus metrics gathering in telemetry package
  using prometheus DefaultGatherer and expfmt.MetricFamilyToText
- Update telemetry tests to validate working Prometheus output
- Update import paths in README to reflect utils module restructure
2026-04-15 13:48:13 +08:00
2025-11-15 02:15:21 +08:00
2025-11-15 02:15:21 +08:00

Utils

Melodia SDK Unified Utilities Framework

Overview

This package provides unified utilities for the entire Melodia SDK ecosystem, consolidating:

  • log - Structured logging interface and implementations
  • errors - Standardized error handling and error codes
  • math - Mathematical types and operations (from melodiasdk-math)
  • rand - Cryptographic random number generation (from hotbeat/libs/rand)
  • sync - Concurrency utilities (from hotbeat/libs/sync)

Installation

import "sdk.melodia.network/utils"

Packages

  • log/ - Logging utilities
  • errors/ - Error handling utilities
  • math/ - Mathematical types and operations
  • rand/ - Random number generation
  • sync/ - Concurrency utilities

Math Package Details

The math package provides custom mathematical types for arithmetic operations in the Melodia SDK:

Types

  • Int - 256-bit signed integer (based on big.Int)
  • Uint - 256-bit unsigned integer (based on big.Uint)
  • LegacyDec - 18-precision decimal for financial calculations

Usage Examples

import "sdk.melodia.network/math"

// Integer operations
i := math.NewInt(100)
i2 := i.Add(math.NewInt(50))

// Unsigned integer operations
u := math.NewUint(100)
u2 := u.Add(math.NewUint(50))

// Decimal operations
d := math.LegacyNewDecWithPrec(12345, 5) // 0.12345
d2 := d.Add(math.LegacyOneDec())

Key Features

  • Safety: Overflow checking and division by zero protection
  • Precision: 256-bit integers for blockchain calculations
  • Compatibility: Full API compatibility with melodiasdk-math
  • Performance: Optimized for high-frequency operations

Migration Status

This package consolidates functionality from:

  • sdk.melodia.network/melodiasdk/log
  • sdk.melodia.network/melodiasdk/errors
  • sdk.melodia.network/math
  • sdk.melodia.network/hotbeat/libs/rand
  • sdk.melodia.network/hotbeat/libs/sync

License

Description
No description provided
Readme 197 KiB
Languages
Go 63.2%
HTML 36.8%