parsing

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package parsing provides common utilities for parsing blockchain event data.

This package handles the conversion of string representations of numbers (including scientific notation) to Go numeric types. It's particularly useful for parsing event data from blockchain watchers where numbers may be represented in scientific notation (e.g., "1.2e+21") or as decimal strings with trailing zeros (e.g., "600000000000000000000.000000").

Primary Functions

  • ScientificNotationToBigInt: Converts strings to *big.Int
  • ScientificNotationToUint64: Converts strings to uint64
  • ScientificNotationToUint32: Converts strings to uint32
  • ScientificNotationToUint16: Converts strings to uint16
  • ScientificNotationToUint8: Converts strings to uint8

All functions use arbitrary-precision arithmetic internally to avoid float64 precision loss issues that would occur with naive string parsing.

Example Usage

value, err := parsing.ScientificNotationToBigInt("1.5e+18")
if err != nil {
    log.Fatal(err)
}
// value is 1500000000000000000

Package parsing provides common parsing utilities for event decoding. It handles scientific notation and decimal number parsing for blockchain event data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScientificNotationToBigInt

func ScientificNotationToBigInt(value string) (*big.Int, error)

ScientificNotationToBigInt converts scientific notation strings to big.Int. Handles formats like "1.2e+21", "1e18", "-5e10", etc. that big.Int.SetString cannot parse directly. Also handles decimal numbers like "600000000000000000000.000000". Returns an error if parsing fails.

func ScientificNotationToUint8

func ScientificNotationToUint8(value string) (uint8, error)

ScientificNotationToUint8 converts scientific notation strings to uint8. Handles formats like "1e2", "2.5e+1", etc. that strconv.ParseUint cannot parse directly. Returns an error if the value cannot be parsed or is out of range for uint8.

func ScientificNotationToUint16

func ScientificNotationToUint16(value string) (uint16, error)

ScientificNotationToUint16 converts scientific notation strings to uint16. Handles formats like "1e2", "2.5e+1", etc. that strconv.ParseUint cannot parse directly. Returns an error if the value cannot be parsed or is out of range for uint16.

func ScientificNotationToUint32

func ScientificNotationToUint32(value string) (uint32, error)

ScientificNotationToUint32 converts scientific notation strings to uint32. Handles formats like "1e2", "2.5e+1", etc. that strconv.ParseUint cannot parse directly. Returns an error if the value cannot be parsed or is out of range for uint32.

func ScientificNotationToUint64

func ScientificNotationToUint64(value string) (uint64, error)

ScientificNotationToUint64 converts scientific notation strings to uint64. Handles formats like "1.2e+21", "1e18", etc. that strconv.ParseUint cannot parse directly. Returns an error if the value cannot be parsed or is too large for uint64.

Types

This section is empty.

Jump to

Keyboard shortcuts

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