Module: utils
#
Index#
Variables#
Functions- buildApiUrl
- buildUrl
- buildWsApiUrl
- calcRaw
- calcValue
- calculateDelegationFees
- calculateDelegationFeesAmount
- checkAddress
- convertEthToWei
- convertHexStringToNumber
- convertToAmount
- convertToDelegationFees
- convertToHexString
- fetchUrl
- formatEndpoint
- formatEvent
- formatExchangeEvent
- formatToAmount
- formatToAmountInternal
- formatToDelegationFeesInternal
- formatToFeePayer
- generateRandomNumber
- getRandomNonce
- isURL
- trimUrl
- websocketStream
#
Variables#
DELEGATION_GAS_PRICE_DIVISOR• Const
DELEGATION_GAS_PRICE_DIVISOR: 1000000 = 1000000
Defined in src/utils.ts:319
#
defaultBaseUrl• Const
defaultBaseUrl: "trustlines://" = "trustlines://"
Defined in src/utils.ts:40
#
Functions#
buildApiUrlâ–¸ Const
buildApiUrl(UrlObject
: ProviderUrl): string
Defined in src/utils.ts:505
Returns URL by concatenating protocol, host, port and path from ProviderUrl object.
#
Parameters:Name | Type |
---|---|
UrlObject | ProviderUrl |
Returns: string
#
buildUrlâ–¸ Const
buildUrl(baseUrl?
: string, options?
: { path?: string[] ; query?: object }): string
Defined in src/utils.ts:138
Encodes URI components and returns a URL.
#
Parameters:Name | Type | Default value | Description |
---|---|---|---|
baseUrl | string | defaultBaseUrl | base 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â–¸ Const
buildWsApiUrl(UrlObject
: ProviderUrl): string
Defined in src/utils.ts:517
Returns URL by concatenating protocol, host, port and path.
#
Parameters:Name | Type |
---|---|
UrlObject | ProviderUrl |
Returns: string
#
calcRawâ–¸ Const
calcRaw(value
: number | string | BigNumber, decimals
: number): BigNumber
Defined in src/utils.ts:176
Returns the smallest representation of a number.
#
Parameters:Name | Type | Description |
---|---|---|
value | number | string | BigNumber | Representation of number in biggest unit. |
decimals | number | Number of decimals. |
Returns: BigNumber
#
calcValueâ–¸ Const
calcValue(raw
: number | string | BigNumber, decimals
: number): BigNumber
Defined in src/utils.ts:189
Returns the biggest representation of a number.
#
Parameters:Name | Type | Description |
---|---|---|
raw | number | string | BigNumber | Representation of number in smallest unit. |
decimals | number | Number of decimals. |
Returns: BigNumber
#
calculateDelegationFeesâ–¸ Const
calculateDelegationFees(baseFee
: number | string | BigNumber, gasPrice
: number | string | BigNumber, gasLimit
: number | string | BigNumber): BigNumber
Defined in src/utils.ts:302
#
Parameters:Name | Type |
---|---|
baseFee | number | string | BigNumber |
gasPrice | number | string | BigNumber |
gasLimit | number | string | BigNumber |
Returns: BigNumber
#
calculateDelegationFeesAmountâ–¸ Const
calculateDelegationFeesAmount(delegationFees
: DelegationFeesInternal, gasLimit
: number): Amount
Defined in src/utils.ts:286
#
Parameters:Name | Type |
---|---|
delegationFees | DelegationFeesInternal |
gasLimit | number |
Returns: Amount
#
checkAddressâ–¸ Const
checkAddress(address
: string): boolean
Defined in src/utils.ts:400
Checks if given address is a valid address
#
Parameters:Name | Type | Description |
---|---|---|
address | string | ethereum address |
Returns: boolean
#
convertEthToWeiâ–¸ Const
convertEthToWei(value
: number | string): number
Defined in src/utils.ts:412
Converts eth to wei
#
Parameters:Name | Type | Description |
---|---|---|
value | number | string | value in eth |
Returns: number
#
convertHexStringToNumberâ–¸ Const
convertHexStringToNumber(hexString
: string): number
Defined in src/utils.ts:451
Return the number representation of the given hex string.
#
Parameters:Name | Type | Description |
---|---|---|
hexString | string |
Returns: number
#
convertToAmountâ–¸ Const
convertToAmount(amount
: AmountInternal): Amount
Defined in src/utils.ts:217
Converts an AmountInternal to Amount object.
#
Parameters:Name | Type | Description |
---|---|---|
amount | AmountInternal | AmountInternal object. |
Returns: Amount
#
convertToDelegationFeesâ–¸ Const
convertToDelegationFees(delegationFees
: DelegationFeesInternal): DelegationFeesObject
Defined in src/utils.ts:276
Formats DelegationFeesInternal into a DelegationFeesObject.
#
Parameters:Name | Type | Description |
---|---|---|
delegationFees | DelegationFeesInternal | DelegationFeesInternal object. |
Returns: DelegationFeesObject
#
convertToHexStringâ–¸ Const
convertToHexString(decimalStr
: string | number | BigNumber): string
Defined in src/utils.ts:422
Returns the hexdecimal representation of given decimal string. The value has to be an integer.
#
Parameters:Name | Type | Description |
---|---|---|
decimalStr | string | number | BigNumber | Decimal string representation of number. |
Returns: string
#
fetchUrlâ–¸ Const
fetchUrl<T>(url
: string, options?
: object): Promise<T>
Defined in src/utils.ts:47
Returns a Promise
with a JSON object from given URL.
#
Type parameters:Name |
---|
T |
#
Parameters:Name | Type | Description |
---|---|---|
url | string | |
options? | object | (optional) |
Returns: Promise<T>
#
formatEndpointâ–¸ Const
formatEndpoint(endpoint
: string): string
Defined in src/utils.ts:528
Adds a slash to the endpoint if it does not start with it.
#
Parameters:Name | Type | Description |
---|---|---|
endpoint | string | Endpoint to format. |
Returns: string
#
formatEventâ–¸ Const
formatEvent<T>(event
: any, networkDecimals
: number, interestRateDecimals
: number): T
Defined in src/utils.ts:327
Formats the number values of a raw event returned by the relay.
#
Type parameters:Name |
---|
T |
#
Parameters:Name | Type | Description |
---|---|---|
event | any | raw event |
networkDecimals | number | decimals of currency network |
interestRateDecimals | number | interest rate decimals of currency network |
Returns: T
#
formatExchangeEventâ–¸ Const
formatExchangeEvent(exchangeEvent
: AnyExchangeEventRaw, makerDecimals
: number, takerDecimals
: number): AnyExchangeEvent
Defined in src/utils.ts:361
Formats the number values of a raw Exchange event as returned by the relay.
#
Parameters:Name | Type | Description |
---|---|---|
exchangeEvent | AnyExchangeEventRaw | raw exchange event: LogFill or LogCancel |
makerDecimals | number | decimals in maker token |
takerDecimals | number | decimals in taker token |
Returns: AnyExchangeEvent
#
formatToAmountâ–¸ Const
formatToAmount(raw
: number | string | BigNumber, decimals
: number): Amount
Defined in src/utils.ts:230
Formats raw representation of number into a Amount object.
#
Parameters:Name | Type | Description |
---|---|---|
raw | number | string | BigNumber | Representation of number in smallest unit. |
decimals | number | Number of decimals. |
Returns: Amount
#
formatToAmountInternalâ–¸ Const
formatToAmountInternal(raw
: number | string | BigNumber, decimals
: number): AmountInternal
Defined in src/utils.ts:202
Formats number into an AmountInternal object which is intended for internal use.
#
Parameters:Name | Type | Description |
---|---|---|
raw | number | string | BigNumber | Representation of number in smallest unit. |
decimals | number | Number of decimals. |
Returns: AmountInternal
#
formatToDelegationFeesInternalâ–¸ Const
formatToDelegationFeesInternal(baseFee
: number | string | BigNumber, decimals
: number, gasPrice
: number | string | BigNumber, currencyNetworkOfFees
: string): DelegationFeesInternal
Defined in src/utils.ts:247
Formats number into an AmountInternal object which is intended for internal use.
#
Parameters:Name | Type | Description |
---|---|---|
baseFee | number | string | BigNumber | - |
decimals | number | Number of decimals. |
gasPrice | number | string | BigNumber | - |
currencyNetworkOfFees | string | the currency network corresponding to the delegation fees |
Returns: DelegationFeesInternal
#
formatToFeePayerâ–¸ Const
formatToFeePayer(feePayer
: string): FeePayer
Defined in src/utils.ts:268
#
Parameters:Name | Type |
---|---|
feePayer | string |
Returns: FeePayer
#
generateRandomNumberâ–¸ Const
generateRandomNumber(decimals
: number): BigNumber
Defined in src/utils.ts:472
Generates a random number with specified decimals.
#
Parameters:Name | Type | Description |
---|---|---|
decimals | number | Decimals which determine size of generated number. |
Returns: BigNumber
#
getRandomNonceâ–¸ getRandomNonce(): string
Defined in src/utils.ts:552
Generates a random nonce to use for meta transactions. The nonce fits into the range of ]2^255, 2^256[. This is an alternative to the up counting nonce (]0, 2^255[) without the need to query a TLProvider.
Returns: string
#
isURLâ–¸ Const
isURL(str
: any): boolean
Defined in src/utils.ts:485
Checks if given string is a valid url.
#
Parameters:Name | Type | Description |
---|---|---|
str | any | String to check. |
Returns: boolean
#
trimUrlâ–¸ Const
trimUrl(url
: string): string
Defined in src/utils.ts:539
Trims url from slashes.
#
Parameters:Name | Type | Description |
---|---|---|
url | string | URL to be trimmed from slashes. |
Returns: string
#
websocketStreamâ–¸ Const
websocketStream(url
: string, functionName
: string, args
: object, reconnectingOptions?
: ReconnectingWSOptions): Observable<any>
Defined in src/utils.ts:71
Returns an Observable for a websocket stream.
#
Parameters:Name | Type | Default value | Description |
---|---|---|---|
url | string | - | URL to open websocket stream to. |
functionName | string | - | Name of function to call on opened websocket. |
args | object | - | Arguments for above function. |
reconnectingOptions | ReconnectingWSOptions | {} | - |
Returns: Observable<any>