utils

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: CC0-1.0 Imports: 7 Imported by: 3

Documentation

Overview

Package utils implements helper functions for the Go NEAR API.

Index

Constants

View Source
const (
	ED25519 = 0
)

All supported key types

View Source
const NearNominationExp = 24

NearNominationExp defines the exponent for calculating how many indivisible units are there in one NEAR. See NearNomination.

Variables

View Source
var ErrRetriesExceeded = errors.New("utils: exceeded retry attempts for request")

ErrRetriesExceeded if the maximum number of retry attempts have been exceeded for request.

View Source
var NearNomination = big.NewInt(0).Exp(big.NewInt(10), big.NewInt(NearNominationExp), nil)

NearNomination defines the number of indivisible units in one NEAR. Derived from NearNominationExp.

Functions

func Ed25519PrivateKeyFromString added in v0.0.19

func Ed25519PrivateKeyFromString(ed25519PrivateKey string) (ed25519.PrivateKey, error)

Ed25519PrivateKeyFromString derives an ed25519 private key from its base58 string representation prefixed with 'ed25519:'.

func Ed25519PrivateKeyToString added in v0.0.19

func Ed25519PrivateKeyToString(pk ed25519.PrivateKey) string

Ed25519PrivateKeyToString converts ed25519 private key to string.

func Ed25519PublicKeyFromString added in v0.0.19

func Ed25519PublicKeyFromString(ed25519PublicKey string) (ed25519.PublicKey, error)

Ed25519PublicKeyFromString derives an ed25519 public key from its base58 string representation prefixed with 'ed25519:'.

func Ed25519PublicKeyToString added in v0.0.19

func Ed25519PublicKeyToString(pk ed25519.PublicKey) string

Ed25519PublicKeyToString converts ed25519 public key to string.

func ExponentialBackoff

func ExponentialBackoff(
	startWaitTime, retryNumber int,
	waitBackoff float64,
	fn GetResult,
) ([]byte, error)

ExponentialBackoff implements an exponential backoff strategy for calling function fn.

func FormatNearAmount

func FormatNearAmount(balance string) (string, error)

FormatNearAmount converts account balance value from internal indivisible units to NEAR. 1 NEAR is defined by NearNomination. Effectively this divides given amount by NearNomination.

func ParseNearAmount

func ParseNearAmount(amount string) (string, error)

ParseNearAmount converts a human readable NEAR amount (potentially factional) to internal indivisible units. Effectively this multiplies given amount by NearNomination. Returns the parsed yoctoⓃ amount.

func ParseNearAmountAsBigInt

func ParseNearAmountAsBigInt(amount string) (*big.Int, error)

ParseNearAmountAsBigInt converts a human readable NEAR amount (potentially factional) to internal indivisible units. Effectively this multiplies given amount by NearNomination. Returns the parsed yoctoⓃ amount.

func PrettyPrintResponse

func PrettyPrintResponse(res map[string]interface{})

PrettyPrintResponse pretty prints some info from the given JSON result map res.

Types

type GetResult

type GetResult func() ([]byte, error)

GetResult is the function type used for ExponentialBackoff.

type PublicKey

type PublicKey struct {
	KeyType uint8
	Data    [32]byte
}

PublicKey encoding for NEAR.

func PublicKeyFromEd25519

func PublicKeyFromEd25519(pk ed25519.PublicKey) PublicKey

PublicKeyFromEd25519 derives a public key in NEAR encoding from pk.

Jump to

Keyboard shortcuts

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