Documentation ¶
Overview ¶
Package utils implements helper functions for the Go NEAR API.
Index ¶
- Constants
- Variables
- func Ed25519PrivateKeyFromString(ed25519PrivateKey string) (ed25519.PrivateKey, error)
- func Ed25519PrivateKeyToString(pk ed25519.PrivateKey) string
- func Ed25519PublicKeyFromString(ed25519PublicKey string) (ed25519.PublicKey, error)
- func Ed25519PublicKeyToString(pk ed25519.PublicKey) string
- func ExponentialBackoff(startWaitTime, retryNumber int, waitBackoff float64, fn GetResult) ([]byte, error)
- func FormatNearAmount(balance string) (string, error)
- func ParseNearAmount(amount string) (string, error)
- func ParseNearAmountAsBigInt(amount string) (*big.Int, error)
- func PrettyPrintResponse(res map[string]interface{})
- type GetResult
- type PublicKey
Constants ¶
const (
ED25519 = 0
)
All supported key types
const NearNominationExp = 24
NearNominationExp defines the exponent for calculating how many indivisible units are there in one NEAR. See NearNomination.
Variables ¶
var ErrRetriesExceeded = errors.New("utils: exceeded retry attempts for request")
ErrRetriesExceeded if the maximum number of retry attempts have been exceeded for request.
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
Ed25519PublicKeyFromString derives an ed25519 public key from its base58 string representation prefixed with 'ed25519:'.
func Ed25519PublicKeyToString ¶ added in v0.0.19
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 ¶
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 ¶
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 ¶
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.