utils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Native = "native"

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

View Source
const PrefixFieldNotFound = "could not find field in map of PrepareDeposit"
View Source
const SdexPrecision int8 = 7

SdexPrecision defines the number of decimals used in SDEX

Variables

View Source
var NativeAsset = horizon.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 horizon.Asset) build.Asset

Asset2Asset is a Boyz2Men cover band on the blockchain

func Asset2Asset2

func Asset2Asset2(Asset build.Asset) horizon.Asset

Asset2Asset2 converts a build.Asset to a horizon.Asset

func Asset2String

func Asset2String(asset horizon.Asset) string

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

func AssetsEqual

func AssetsEqual(baseAsset base.Asset, horizonAsset horizon.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

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 FilterOffers

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

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

func FloatEquals

func FloatEquals(f1 float64, f2 float64, epsilon float64) bool

FloatEquals returns true if the two floats are equal within the epsilon of error (avoids mismatched equality because of floating point noise)

func GetCreditBalance

func GetCreditBalance(a horizon.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 horizon.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 horizon.Offer) float64

GetPrice gets the price from an offer

func JSONRequest added in v1.1.0

func JSONRequest(
	httpClient *http.Client,
	method string,
	reqURL string,
	data string,
	headers map[string]string,
	responseData interface{},
) error

JSONRequest submits an HTTP web request and parses the response into the responseData object as JSON

func LoadAllOffers

func LoadAllOffers(account string, api *horizon.Client) (offersRet []horizon.Offer, err error)

LoadAllOffers loads all the offers for a given account

func ParseBool

func ParseBool(m map[string]interface{}, key string, methodAPI string) (bool, error)

ParseBool helps to parse a bool value out of the map

func ParseNetwork

func ParseNetwork(horizonURL string) build.Network

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

func ParseNumber

func ParseNumber(m map[string]interface{}, key string, methodAPI string) (*model.Number, error)

ParseNumber helps to parse a model.Number value out of the map

func ParseSecret

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

ParseSecret returns the address from the secret

func ParseString

func ParseString(m map[string]interface{}, key string, methodAPI string) (string, error)

ParseString helps to parse a string value out of the map

func PriceAsFloat

func PriceAsFloat(price string) float64

PriceAsFloat converts a string price to a float price

func SecretKey2PublicKey

func SecretKey2PublicKey(i interface{}) interface{}

SecretKey2PublicKey converts a secret key to a public key

func String2Asset

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

String2Asset converts a code:issuer to a horizon.Asset

func StructString

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

StructString is a helper method that

Types

type ByPrice

type ByPrice []horizon.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