Skip to content
Snippets Groups Projects
Commit ef862af4 authored by Bartek Wrona's avatar Bartek Wrona
Browse files

hiveToHbd added to wax TS interface

parent 250cf894
No related branches found
No related tags found
1 merge request!203Support for Hive -> HBD conversion
......@@ -107,6 +107,23 @@ export class WaxBaseApi implements IWaxBaseInterface {
return this.proto.cpp_hbd_to_hive(hbdAsset, baseAsset, quoteAsset) as NaiAsset;
}
public hiveToHbd(amount: number | string | BigInt | Long | NaiAsset, base: number | string | BigInt | Long | NaiAsset, quote: number | string | BigInt | Long | NaiAsset): NaiAsset {
const amountAsset = isNaiAsset(amount) ? amount as NaiAsset : this.hive(amount as number | string | BigInt | Long);
const baseAsset = isNaiAsset(base) ? base as NaiAsset : this.hbd(base as number | string | BigInt | Long);
const quoteAsset = isNaiAsset(quote) ? quote as NaiAsset : this.hive(quote as number | string | BigInt | Long);
if (amountAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for HBD');
if (baseAsset.nai !== this.ASSETS.HBD.nai)
throw new WaxError('Invalid asset type for base');
if (quoteAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for quote');
return this.proto.cpp_hive_to_hbd(amountAsset, baseAsset, quoteAsset) as NaiAsset;
}
public extract(res: result): string {
if(res.value !== this.wax.error_code.ok)
throw new WaxError(`Wax API error: "${String(res.exception_message as string)}"`);
......
......@@ -518,8 +518,18 @@ export interface IWaxBaseInterface {
* @param {NaiAsset} hbd HBD asset
* @param {NaiAsset} base HBD asset price base
* @param {NaiAsset} quote HIVE asset price quote
* @returns {NaiAsset} HIVE in nai form
*/
hbdToHive(hbd: number | string | BigInt | Long | NaiAsset, base: number | string | BigInt | Long | NaiAsset, quote: number | string | BigInt | Long | NaiAsset): NaiAsset;
/**
* Converts given amount of HIVE asset to HBD (nai form)
* @param {NaiAsset} amount HIVE asset
* @param {NaiAsset} base HBD asset price base taken i.e. from database_api.get_current_price_feed call
* @param {NaiAsset} quote HIVE asset price quote taken i.e. from database_api.get_current_price_feed call
* @returns {NaiAsset} HBD in nai form
*/
hbdToHive(hbd: number | string | BigInt | Long | NaiAsset, base: number | string | BigInt | Long | NaiAsset, quote: number | string | BigInt | Long | NaiAsset): NaiAsset
hiveToHbd(amount: number | string | BigInt | Long | NaiAsset, base: number | string | BigInt | Long | NaiAsset, quote: number | string | BigInt | Long | NaiAsset): NaiAsset;
/**
* Retrieves the public key in wif format from the given sig digest and signature in hexadecimal format
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment