utils

package
v0.0.0-...-8fa53af Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: CC0-1.0 Imports: 6 Imported by: 0

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 ExponentialBackoff

func ExponentialBackoff(
	startWaitTime, retryNumber int,
	waitBackoff float64,
	fn GetResult,
) (map[string]interface{}, 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() (map[string]interface{}, 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