utils

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 21 Imported by: 65

Documentation

Index

Constants

View Source
const Native = "native"

Native is the string representing the type for the native lumen asset

View Source
const SdexPrecision int8 = 7

SdexPrecision defines the number of decimals used in SDEX

Variables

View Source
var NativeAsset = hProtocol.Asset{Type: Native}

NativeAsset represents the native asset

Functions

func AmountStringAsFloat

func AmountStringAsFloat(amount string) float64

AmountStringAsFloat converts a string amount to a float amount

func Asset2Asset

func Asset2Asset(Asset hProtocol.Asset) txnbuild.Asset

Asset2Asset converts a horizon.Asset to a txnbuild.Asset.

func Asset2Asset2

func Asset2Asset2(Asset txnbuild.Asset) hProtocol.Asset

Asset2Asset2 converts a txnbuild.Asset to a horizon.Asset.

func Asset2CodeString added in v1.3.0

func Asset2CodeString(asset hProtocol.Asset) string

Asset2CodeString extracts the code out of a horizon.Asset

func Asset2String

func Asset2String(asset hProtocol.Asset) string

Asset2String converts a horizon.Asset to a string representation, using "native" for the native XLM

func AssetFloatEquals added in v1.10.0

func AssetFloatEquals(t *testing.T, want float64, actual float64)

AssetFloatEquals is a float comparison within a pre-defined epsilon error

func AssetOnlyCodeEquals added in v1.8.0

func AssetOnlyCodeEquals(hAsset hProtocol.Asset, txnAsset txnbuild.Asset) (bool, error)

AssetOnlyCodeEquals only checks the type and code of these assets, i.e. insensitive to asset issuer

func AssetsEqual

func AssetsEqual(baseAsset base.Asset, horizonAsset hProtocol.Asset) bool

AssetsEqual is a convenience method to compare horizon.Asset and base.Asset because they are not type aliased

func CheckConfigError

func CheckConfigError(cfg fmt.Stringer, e error, filename string)

CheckConfigError checks configs for errors, crashes app if there's an error

func CheckFetchFloat added in v1.1.1

func CheckFetchFloat(m map[string]interface{}, key string) (float64, error)

CheckFetchFloat tries to fetch and then cast the value for the provided key

func CheckedFloatPtr added in v1.8.0

func CheckedFloatPtr(v *float64) string

CheckedFloatPtr returns "<nil>" if the object is nil, otherwise calls the String() function on the object

func CheckedString added in v1.2.0

func CheckedString(v interface{}) string

CheckedString returns "<nil>" if the object is nil, otherwise calls the String() function on the object

func Dedupe added in v1.8.0

func Dedupe(list []string) []string

Dedupe removes duplicates from the list

func FilterOffers

func FilterOffers(offers []hProtocol.Offer, sellAsset hProtocol.Asset, buyAsset hProtocol.Asset) (sellOffers []hProtocol.Offer, buyOffers []hProtocol.Offer)

FilterOffers filters out the offers into selling and buying, where sellOffers sells the sellAsset and buyOffers buys the sellAsset

func GetCreditBalance

func GetCreditBalance(a hProtocol.Account, code string, issuer string) *string

GetCreditBalance is a drop-in for the function in the GoSDK, we want it to return nil if there's no balance (as opposed to "0")

func GetInvertedPrice

func GetInvertedPrice(offer hProtocol.Offer) float64

GetInvertedPrice gets the inverted price from an offer

func GetJSON

func GetJSON(client http.Client, url string, target interface{}) error

GetJSON is a helper method to get json from a URL

func GetPrice

func GetPrice(offer hProtocol.Offer) float64

GetPrice gets the price from an offer

func HashString added in v1.10.0

func HashString(s string) (uint32, error)

HashString hashes a string using the FNV-1 hash function.

func Hide added in v1.3.0

func Hide(i interface{}) interface{}

Hide returns an empty string

func IsSelling added in v1.6.0

func IsSelling(sdexBase hProtocol.Asset, sdexQuote hProtocol.Asset, selling txnbuild.Asset, buying txnbuild.Asset) (bool, error)

IsSelling helper method TODO DS Add tests for the various possible errors.

func LoadAllOffers

func LoadAllOffers(account string, api *horizonclient.Client) ([]hProtocol.Offer, error)

LoadAllOffers loads all the offers for a given account

func LogConfig added in v1.2.0

func LogConfig(cfg fmt.Stringer)

LogConfig logs out the config file

func MergeMaps added in v1.11.0

func MergeMaps(original map[string]interface{}, overrides map[string]interface{}) (map[string]interface{}, error)

MergeMaps combines two arbitrary maps. Note that values from the second would override the first.

func MustParseAsset added in v1.11.0

func MustParseAsset(code string, issuer string) *hProtocol.Asset

MustParseAsset returns a horizon asset or panics

func Offer2TxnBuildSellOffer added in v1.9.0

func Offer2TxnBuildSellOffer(offer hProtocol.Offer) txnbuild.ManageSellOffer

Offer2TxnBuildSellOffer converts an hProtocol.Offer to a txnbuild.ManageSellOffer

func ParseAsset added in v1.4.0

func ParseAsset(code string, issuer string) (*hProtocol.Asset, error)

ParseAsset returns a horizon asset

func ParseMaybeFloat added in v1.8.0

func ParseMaybeFloat(valueString string) (*float64, error)

ParseMaybeFloat parses an optional string value as a float pointer

func ParseNetwork

func ParseNetwork(horizonURL string) string

ParseNetwork checks the horizon url and returns the test network if it contains "test"

func ParseOfferAmount added in v1.6.0

func ParseOfferAmount(amt string) (float64, error)

ParseOfferAmount is a convenience method to parse an offer amount

func ParseSecret

func ParseSecret(secret string) (*string, error)

ParseSecret returns the address from the secret

func PriceAsFloat

func PriceAsFloat(price string) float64

PriceAsFloat converts a string price to a float price

func PrintErrorHintf added in v1.8.0

func PrintErrorHintf(message string, args ...interface{})

PrintErrorHintf shows a helpful hint for the user when there is an error (likely recoverable)

func SecretKey2PublicKey

func SecretKey2PublicKey(i interface{}) interface{}

SecretKey2PublicKey converts a secret key to a public key

func Shuffle added in v1.8.0

func Shuffle(slice []string)

Shuffle any string slice

func SignWithSeed added in v1.8.0

func SignWithSeed(tx *txnbuild.Transaction, network string, seeds ...string) (*txnbuild.Transaction, error)

SignWithSeed returns a new tx with the signatures of the passed in seeds

func String2Asset

func String2Asset(code string, issuer string) hProtocol.Asset

String2Asset converts a code:issuer to a horizon.Asset

func StringSet added in v1.8.0

func StringSet(list []string) map[string]bool

StringSet converts a string slice to a map of string to bool values to represent a Set

func StructString

func StructString(s interface{}, indentLevel uint8, transforms map[string]func(interface{}) interface{}) string

StructString is a helper method that serizlies configs; the transform keys are always flattened, i.e specify the key meant to be on an inner object at a top level key on the transform map

func ToJSONHash added in v1.11.0

func ToJSONHash(v interface{}) (uint32, error)

ToJSONHash converts to json first and then takes the hash

func ToMapStringInterface added in v1.11.0

func ToMapStringInterface(v interface{}) (map[string]interface{}, error)

ToMapStringInterface converts an arbitrary struct to a map[string]interface{}, through serializing to and deserializing from JSON.

Types

type ByPrice

type ByPrice []hProtocol.Offer

ByPrice implements sort.Interface for []horizon.Offer based on the price

func (ByPrice) Len

func (a ByPrice) Len() int

func (ByPrice) Less

func (a ByPrice) Less(i, j int) bool

func (ByPrice) Swap

func (a ByPrice) Swap(i, j int)

Jump to

Keyboard shortcuts

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