Version: 0.13.7

Module: utils

Index#

Variables#

Functions#

Variables#

DELEGATION_GAS_PRICE_DIVISOR#

Const DELEGATION_GAS_PRICE_DIVISOR: 1000000 = 1000000

Defined in src/utils.ts:313


defaultBaseUrl#

Const defaultBaseUrl: "trustlines://" = "trustlines://"

Defined in src/utils.ts:36

Functions#

buildApiUrl#

ConstbuildApiUrl(UrlObject: ProviderUrl): string

Defined in src/utils.ts:491

Returns URL by concatenating protocol, host, port and path from ProviderUrl object.

Parameters:#

NameType
UrlObjectProviderUrl

Returns: string


buildUrl#

ConstbuildUrl(baseUrl?: string, options?: { path?: string[] ; query?: object }): string

Defined in src/utils.ts:132

Encodes URI components and returns a URL.

Parameters:#

NameTypeDefault valueDescription
baseUrlstringdefaultBaseUrlbase URL
options?{ path?: string[] ; query?: object }-additional parts of the URL if provided (path and query) options.path - the path part of the URL options.query - the query part of the URL

Returns: string


buildWsApiUrl#

ConstbuildWsApiUrl(UrlObject: ProviderUrl): string

Defined in src/utils.ts:503

Returns URL by concatenating protocol, host, port and path.

Parameters:#

NameType
UrlObjectProviderUrl

Returns: string


calcRaw#

ConstcalcRaw(value: number | string | BigNumber, decimals: number): BigNumber

Defined in src/utils.ts:170

Returns the smallest representation of a number.

Parameters:#

NameTypeDescription
valuenumber | string | BigNumberRepresentation of number in biggest unit.
decimalsnumberNumber of decimals.

Returns: BigNumber


calcValue#

ConstcalcValue(raw: number | string | BigNumber, decimals: number): BigNumber

Defined in src/utils.ts:183

Returns the biggest representation of a number.

Parameters:#

NameTypeDescription
rawnumber | string | BigNumberRepresentation of number in smallest unit.
decimalsnumberNumber of decimals.

Returns: BigNumber


calculateDelegationFees#

ConstcalculateDelegationFees(baseFee: number | string | BigNumber, gasPrice: number | string | BigNumber, gasLimit: number | string | BigNumber): BigNumber

Defined in src/utils.ts:296

Parameters:#

NameType
baseFeenumber | string | BigNumber
gasPricenumber | string | BigNumber
gasLimitnumber | string | BigNumber

Returns: BigNumber


calculateDelegationFeesAmount#

ConstcalculateDelegationFeesAmount(delegationFees: DelegationFeesInternal, gasLimit: number): Amount

Defined in src/utils.ts:280

Parameters:#

NameType
delegationFeesDelegationFeesInternal
gasLimitnumber

Returns: Amount


checkAddress#

ConstcheckAddress(address: string): boolean

Defined in src/utils.ts:393

Checks if given address is a valid address

Parameters:#

NameTypeDescription
addressstringethereum address

Returns: boolean


convertEthToWei#

ConstconvertEthToWei(value: number | string): number

Defined in src/utils.ts:405

Converts eth to wei

Parameters:#

NameTypeDescription
valuenumber | stringvalue in eth

Returns: number


convertHexStringToNumber#

ConstconvertHexStringToNumber(hexString: string): number

Defined in src/utils.ts:437

Return the number representation of the given hex string.

Parameters:#

NameTypeDescription
hexStringstring

Returns: number


convertToAmount#

ConstconvertToAmount(amount: AmountInternal): Amount

Defined in src/utils.ts:211

Converts an AmountInternal to Amount object.

Parameters:#

NameTypeDescription
amountAmountInternalAmountInternal object.

Returns: Amount


convertToDelegationFees#

ConstconvertToDelegationFees(delegationFees: DelegationFeesInternal): DelegationFeesObject

Defined in src/utils.ts:270

Formats DelegationFeesInternal into a DelegationFeesObject.

Parameters:#

NameTypeDescription
delegationFeesDelegationFeesInternalDelegationFeesInternal object.

Returns: DelegationFeesObject


convertToHexString#

ConstconvertToHexString(decimalStr: string | number | BigNumber): string

Defined in src/utils.ts:415

Returns the hexdecimal representation of given decimal string. The value has to be an integer.

Parameters:#

NameTypeDescription
decimalStrstring | number | BigNumberDecimal string representation of number.

Returns: string


fetchUrl#

ConstfetchUrl<T>(url: string, options?: object): Promise<T>

Defined in src/utils.ts:43

Returns a Promise with a JSON object from given URL.

Type parameters:#

Name
T

Parameters:#

NameTypeDescription
urlstring
options?object(optional)

Returns: Promise<T>


formatEndpoint#

ConstformatEndpoint(endpoint: string): string

Defined in src/utils.ts:514

Adds a slash to the endpoint if it does not start with it.

Parameters:#

NameTypeDescription
endpointstringEndpoint to format.

Returns: string


formatEvent#

ConstformatEvent<T>(event: any, networkDecimals: number, interestRateDecimals: number): T

Defined in src/utils.ts:321

Formats the number values of a raw event returned by the relay.

Type parameters:#

Name
T

Parameters:#

NameTypeDescription
eventanyraw event
networkDecimalsnumberdecimals of currency network
interestRateDecimalsnumberinterest rate decimals of currency network

Returns: T


formatExchangeEvent#

ConstformatExchangeEvent(exchangeEvent: AnyExchangeEventRaw, makerDecimals: number, takerDecimals: number): AnyExchangeEvent

Defined in src/utils.ts:354

Formats the number values of a raw Exchange event as returned by the relay.

Parameters:#

NameTypeDescription
exchangeEventAnyExchangeEventRawraw exchange event: LogFill or LogCancel
makerDecimalsnumberdecimals in maker token
takerDecimalsnumberdecimals in taker token

Returns: AnyExchangeEvent


formatToAmount#

ConstformatToAmount(raw: number | string | BigNumber, decimals: number): Amount

Defined in src/utils.ts:224

Formats raw representation of number into a Amount object.

Parameters:#

NameTypeDescription
rawnumber | string | BigNumberRepresentation of number in smallest unit.
decimalsnumberNumber of decimals.

Returns: Amount


formatToAmountInternal#

ConstformatToAmountInternal(raw: number | string | BigNumber, decimals: number): AmountInternal

Defined in src/utils.ts:196

Formats number into an AmountInternal object which is intended for internal use.

Parameters:#

NameTypeDescription
rawnumber | string | BigNumberRepresentation of number in smallest unit.
decimalsnumberNumber of decimals.

Returns: AmountInternal


formatToDelegationFeesInternal#

ConstformatToDelegationFeesInternal(baseFee: number | string | BigNumber, decimals: number, gasPrice: number | string | BigNumber, currencyNetworkOfFees: string): DelegationFeesInternal

Defined in src/utils.ts:241

Formats number into an AmountInternal object which is intended for internal use.

Parameters:#

NameTypeDescription
baseFeenumber | string | BigNumber-
decimalsnumberNumber of decimals.
gasPricenumber | string | BigNumber-
currencyNetworkOfFeesstringthe currency network corresponding to the delegation fees

Returns: DelegationFeesInternal


formatToFeePayer#

ConstformatToFeePayer(feePayer: string): FeePayer

Defined in src/utils.ts:262

Parameters:#

NameType
feePayerstring

Returns: FeePayer


generateRandomNumber#

ConstgenerateRandomNumber(decimals: number): BigNumber

Defined in src/utils.ts:458

Generates a random number with specified decimals.

Parameters:#

NameTypeDescription
decimalsnumberDecimals which determine size of generated number.

Returns: BigNumber


isURL#

ConstisURL(str: any): boolean

Defined in src/utils.ts:471

Checks if given string is a valid url.

Parameters:#

NameTypeDescription
stranyString to check.

Returns: boolean


trimUrl#

ConsttrimUrl(url: string): string

Defined in src/utils.ts:525

Trims url from slashes.

Parameters:#

NameTypeDescription
urlstringURL to be trimmed from slashes.

Returns: string


websocketStream#

ConstwebsocketStream(url: string, functionName: string, args: object, reconnectingOptions?: ReconnectingWSOptions): Observable<any>

Defined in src/utils.ts:65

Returns an Observable for a websocket stream.

Parameters:#

NameTypeDefault valueDescription
urlstring-URL to open websocket stream to.
functionNamestring-Name of function to call on opened websocket.
argsobject-Arguments for above function.
reconnectingOptionsReconnectingWSOptions{}-

Returns: Observable<any>