Skip to content
Snippets Groups Projects
Verified Commit f51329b0 authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Add utility function for assertions

parent 4502d19e
No related branches found
No related tags found
1 merge request!210Add `estimate_hive_collateral` to python/TS interface
...@@ -789,6 +789,23 @@ test.describe('Wax complex operation tests', () => { ...@@ -789,6 +789,23 @@ test.describe('Wax complex operation tests', () => {
]); ]);
}); });
test('Should fail to set invalid asset in max accepted payout in BlogPostOperation', async ({ waxTest }) => {
await expect(waxTest(({ wax, chain }) => {
const tx = chain.createTransactionWithTaPoS('04c507a8c7fe5be96be64ce7c86855e1806cbde3', '2023-11-09T21:51:27');
tx.pushOperation(new wax.BlogPostOperation({
category: "test-category",
author: "gtg",
title: "Set max accepted payout",
body: "Set max accepted payout",
permlink: "set-max-accepted-payout",
maxAcceptedPayout: chain.hiveSatoshis(100),
}));
return tx.toApi();
})).rejects.toThrow('Invalid asset provided: "{"amount":"100","precision":3,"nai":"@@000000021"}". Expected asset symbol(s): ""@@000000013" (HBD) with precision: 3".');
});
test('Should be able to set max accepted payout in BlogPostOperation', async ({ waxTest }) => { test('Should be able to set max accepted payout in BlogPostOperation', async ({ waxTest }) => {
const retVal = await waxTest(({ wax, chain }) => { const retVal = await waxTest(({ wax, chain }) => {
const tx = chain.createTransactionWithTaPoS('04c507a8c7fe5be96be64ce7c86855e1806cbde3', '2023-11-09T21:51:27'); const tx = chain.createTransactionWithTaPoS('04c507a8c7fe5be96be64ce7c86855e1806cbde3', '2023-11-09T21:51:27');
...@@ -799,7 +816,7 @@ test.describe('Wax complex operation tests', () => { ...@@ -799,7 +816,7 @@ test.describe('Wax complex operation tests', () => {
title: "Set max accepted payout", title: "Set max accepted payout",
body: "Set max accepted payout", body: "Set max accepted payout",
permlink: "set-max-accepted-payout", permlink: "set-max-accepted-payout",
maxAcceptedPayout: chain.hiveSatoshis(100), maxAcceptedPayout: chain.hbdSatoshis(100),
})); }));
return tx.toApi(); return tx.toApi();
...@@ -824,7 +841,7 @@ test.describe('Wax complex operation tests', () => { ...@@ -824,7 +841,7 @@ test.describe('Wax complex operation tests', () => {
allow_curation_rewards: true, allow_curation_rewards: true,
allow_votes: true, allow_votes: true,
author: 'gtg', author: 'gtg',
max_accepted_payout: { amount: '100', nai: '@@000000021', precision: 3 }, max_accepted_payout: { amount: '100', nai: '@@000000013', precision: 3 },
percent_hbd: 10000, percent_hbd: 10000,
permlink:'set-max-accepted-payout', permlink:'set-max-accepted-payout',
} }
...@@ -964,7 +981,7 @@ test.describe('Wax complex operation tests', () => { ...@@ -964,7 +981,7 @@ test.describe('Wax complex operation tests', () => {
images: ['test.png'], images: ['test.png'],
links: ['https://test.com'], links: ['https://test.com'],
tags: ['spam'], tags: ['spam'],
maxAcceptedPayout: chain.hiveSatoshis(100), maxAcceptedPayout: chain.hbdSatoshis(100),
percentHbd: 20, percentHbd: 20,
beneficiaries: [{ account: 'guest4test7', weight: 40 }], beneficiaries: [{ account: 'guest4test7', weight: 40 }],
description: 'Push links, images, tags, set allow votes, set max accepted payout, set percent HBD, add beneficiaries' description: 'Push links, images, tags, set allow votes, set max accepted payout, set percent HBD, add beneficiaries'
...@@ -1005,7 +1022,7 @@ test.describe('Wax complex operation tests', () => { ...@@ -1005,7 +1022,7 @@ test.describe('Wax complex operation tests', () => {
} }
} }
], ],
max_accepted_payout: { amount: '100', nai: '@@000000021', precision: 3 }, max_accepted_payout: { amount: '100', nai: '@@000000013', precision: 3 },
percent_hbd: 20, percent_hbd: 20,
permlink:'push-and-set-multiple-properites', permlink:'push-and-set-multiple-properites',
} }
......
...@@ -368,13 +368,24 @@ test.describe('Wax object interface foundation tests', () => { ...@@ -368,13 +368,24 @@ test.describe('Wax object interface foundation tests', () => {
]); ]);
}); });
test('Should be able to create an update proposal with underlying extensions using transaction interface', async ({ waxTest }) => { test('Should fail when invalid asset is provided', async ({ waxTest }) => {
const retVal = await waxTest(async({ base, wax }) => { await expect(waxTest(async({ base, wax }) => {
const tx = base.createTransactionWithTaPoS("04c1c7a566fc0da66aee465714acee7346b48ac2", "2023-08-01T15:38:48"); const tx = base.createTransactionWithTaPoS("04c1c7a566fc0da66aee465714acee7346b48ac2", "2023-08-01T15:38:48");
tx.pushOperation(new wax.UpdateProposalOperation({ proposalId: 100, creator: "initminer", dailyPay: base.hiveSatoshis(0), subject: "subject", permlink: "permlink", endDate: "2023-08-01T15:38:48" })); tx.pushOperation(new wax.UpdateProposalOperation({ proposalId: 100, creator: "initminer", dailyPay: base.hiveSatoshis(0), subject: "subject", permlink: "permlink", endDate: "2023-08-01T15:38:48" }));
tx.pushOperation(new wax.UpdateProposalOperation({ proposalId: 100, creator: "initminer", dailyPay: base.hiveSatoshis(0), subject: "subject", permlink: "permlink" })); tx.pushOperation(new wax.UpdateProposalOperation({ proposalId: 100, creator: "initminer", dailyPay: base.hiveSatoshis(0), subject: "subject", permlink: "permlink" }));
return tx.transaction.operations;
})).rejects.toThrow('Invalid asset provided: "{"amount":"0","precision":3,"nai":"@@000000021"}". Expected asset symbol(s): ""@@000000013" (HBD) with precision: 3".');
});
test('Should be able to create an update proposal with underlying extensions using transaction interface', async ({ waxTest }) => {
const retVal = await waxTest(async({ base, wax }) => {
const tx = base.createTransactionWithTaPoS("04c1c7a566fc0da66aee465714acee7346b48ac2", "2023-08-01T15:38:48");
tx.pushOperation(new wax.UpdateProposalOperation({ proposalId: 100, creator: "initminer", dailyPay: base.hbdSatoshis(0), subject: "subject", permlink: "permlink", endDate: "2023-08-01T15:38:48" }));
tx.pushOperation(new wax.UpdateProposalOperation({ proposalId: 100, creator: "initminer", dailyPay: base.hbdSatoshis(0), subject: "subject", permlink: "permlink" }));
return tx.transaction.operations; return tx.transaction.operations;
}); });
...@@ -384,7 +395,7 @@ test.describe('Wax object interface foundation tests', () => { ...@@ -384,7 +395,7 @@ test.describe('Wax object interface foundation tests', () => {
creator: "initminer", creator: "initminer",
daily_pay: { daily_pay: {
amount: "0", amount: "0",
nai: "@@000000021", nai: "@@000000013",
precision: 3 precision: 3
}, },
permlink: "permlink", permlink: "permlink",
...@@ -400,7 +411,7 @@ test.describe('Wax object interface foundation tests', () => { ...@@ -400,7 +411,7 @@ test.describe('Wax object interface foundation tests', () => {
creator: "initminer", creator: "initminer",
daily_pay: { daily_pay: {
amount: "0", amount: "0",
nai: "@@000000021", nai: "@@000000013",
precision: 3 precision: 3
}, },
permlink: "permlink", permlink: "permlink",
......
...@@ -31,33 +31,31 @@ export class WaxBaseApi implements IWaxBaseInterface { ...@@ -31,33 +31,31 @@ export class WaxBaseApi implements IWaxBaseInterface {
return this.formatter.waxify.bind(this.formatter); return this.formatter.waxify.bind(this.formatter);
} }
// Public for our internal usage among i.e. complex operation sinks or formatters (this method is not exposed in the IWaxBaseInterface)
public assertAssetSymbol(requiredSymbolType: EAssetName[] | EAssetName, asset: NaiAsset): NaiAsset {
const stringifyAsset = (assetType: EAssetName) => `"${this.ASSETS[assetType].nai}" (${assetType}) with precision: ${this.ASSETS[assetType].precision}`;
const assets = Array.isArray(requiredSymbolType) ? requiredSymbolType : [ requiredSymbolType ];
for (const symbolType of assets)
if (this.ASSETS[symbolType].nai === asset.nai && this.ASSETS[symbolType].precision === asset.precision)
return asset;
throw new WaxError(`Invalid asset provided: "${JSON.stringify(asset)}". Expected asset symbol(s): "${assets.map(stringifyAsset).join(" or ")}".`);
}
public estimateHiveCollateral(currentMedianHistoryBase: TNaiAssetConvertible | NaiAsset, currentMedianHistoryQuote: TNaiAssetConvertible | NaiAsset, currentMinHistoryBase: TNaiAssetConvertible | NaiAsset, currentMinHistoryQuote: TNaiAssetConvertible | NaiAsset, hbdAmountToGet: TNaiAssetConvertible | NaiAsset): NaiAsset { public estimateHiveCollateral(currentMedianHistoryBase: TNaiAssetConvertible | NaiAsset, currentMedianHistoryQuote: TNaiAssetConvertible | NaiAsset, currentMinHistoryBase: TNaiAssetConvertible | NaiAsset, currentMinHistoryQuote: TNaiAssetConvertible | NaiAsset, hbdAmountToGet: TNaiAssetConvertible | NaiAsset): NaiAsset {
const currentMedianHistory: json_price = { const currentMedianHistory: json_price = {
base: isNaiAsset(currentMedianHistoryBase) ? currentMedianHistoryBase as NaiAsset : this.hbdSatoshis(currentMedianHistoryBase as number | string | BigInt | Long), base: isNaiAsset(currentMedianHistoryBase) ? this.assertAssetSymbol(EAssetName.HBD, currentMedianHistoryBase as NaiAsset) : this.hbdSatoshis(currentMedianHistoryBase as number | string | BigInt | Long),
quote: isNaiAsset(currentMedianHistoryQuote) ? currentMedianHistoryQuote as NaiAsset : this.hiveSatoshis(currentMedianHistoryQuote as number | string | BigInt | Long) quote: isNaiAsset(currentMedianHistoryQuote) ? this.assertAssetSymbol(EAssetName.HIVE, currentMedianHistoryQuote as NaiAsset) : this.hiveSatoshis(currentMedianHistoryQuote as number | string | BigInt | Long)
}; };
if (currentMedianHistory.base.nai !== this.ASSETS.HBD.nai)
throw new WaxError('Invalid asset type for currentMedianHistoryBase');
if (currentMedianHistory.quote.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for currentMedianHistoryQuote');
const currentMinHistory: json_price = { const currentMinHistory: json_price = {
base: isNaiAsset(currentMinHistoryBase) ? currentMinHistoryBase as NaiAsset : this.hbdSatoshis(currentMinHistoryBase as number | string | BigInt | Long), base: isNaiAsset(currentMinHistoryBase) ? this.assertAssetSymbol(EAssetName.HBD, currentMinHistoryBase as NaiAsset) : this.hbdSatoshis(currentMinHistoryBase as number | string | BigInt | Long),
quote: isNaiAsset(currentMinHistoryQuote) ? currentMinHistoryQuote as NaiAsset : this.hiveSatoshis(currentMinHistoryQuote as number | string | BigInt | Long) quote: isNaiAsset(currentMinHistoryQuote) ? this.assertAssetSymbol(EAssetName.HIVE, currentMinHistoryQuote as NaiAsset) : this.hiveSatoshis(currentMinHistoryQuote as number | string | BigInt | Long)
}; };
if (currentMinHistory.base.nai !== this.ASSETS.HBD.nai) const actualHbdAmountToGet = isNaiAsset(hbdAmountToGet) ? this.assertAssetSymbol(EAssetName.HBD, hbdAmountToGet as NaiAsset) : this.hbdSatoshis(hbdAmountToGet as number | string | BigInt | Long);
throw new WaxError('Invalid asset type for currentMinHistoryBase');
if (currentMinHistory.quote.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for currentMinHistoryQuote');
const actualHbdAmountToGet = isNaiAsset(hbdAmountToGet) ? hbdAmountToGet as NaiAsset : this.hbdSatoshis(hbdAmountToGet as number | string | BigInt | Long);
if (actualHbdAmountToGet.nai !== this.ASSETS.HBD.nai)
throw new WaxError('Invalid asset type for actualHbdAmountToGet');
return this.proto.cpp_estimate_hive_collateral(currentMedianHistory, currentMinHistory, actualHbdAmountToGet) as NaiAsset; return this.proto.cpp_estimate_hive_collateral(currentMedianHistory, currentMinHistory, actualHbdAmountToGet) as NaiAsset;
} }
...@@ -139,52 +137,25 @@ export class WaxBaseApi implements IWaxBaseInterface { ...@@ -139,52 +137,25 @@ export class WaxBaseApi implements IWaxBaseInterface {
} }
public vestsToHp(vests: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset { public vestsToHp(vests: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset {
const vestsAsset = isNaiAsset(vests) ? vests as NaiAsset : this.vestsSatoshis(vests as number | string | BigInt | Long); const vestsAsset = isNaiAsset(vests) ? this.assertAssetSymbol(EAssetName.VESTS, vests as NaiAsset) : this.vestsSatoshis(vests as number | string | BigInt | Long);
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long); const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? this.assertAssetSymbol(EAssetName.HIVE, totalVestingFundHive as NaiAsset) : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long);
const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? totalVestingShares as NaiAsset : this.vestsSatoshis(totalVestingShares as number | string | BigInt | Long); const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? this.assertAssetSymbol(EAssetName.VESTS, totalVestingShares as NaiAsset) : this.vestsSatoshis(totalVestingShares as number | string | BigInt | Long);
if (vestsAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for vests');
if (totalVestingFundHiveAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for totalVestingFundHive');
if (totalVestingSharesAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for totalVestingShares');
return this.proto.cpp_vests_to_hp(vestsAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset; return this.proto.cpp_vests_to_hp(vestsAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset;
} }
public hbdToHive(hbd: number | string | BigInt | Long | NaiAsset, base: number | string | BigInt | Long | NaiAsset, quote: number | string | BigInt | Long | NaiAsset): NaiAsset { public hbdToHive(hbd: number | string | BigInt | Long | NaiAsset, base: number | string | BigInt | Long | NaiAsset, quote: number | string | BigInt | Long | NaiAsset): NaiAsset {
const hbdAsset = isNaiAsset(hbd) ? hbd as NaiAsset : this.hbdSatoshis(hbd as number | string | BigInt | Long); const hbdAsset = isNaiAsset(hbd) ? this.assertAssetSymbol(EAssetName.HBD, hbd as NaiAsset) : this.hbdSatoshis(hbd as number | string | BigInt | Long);
const baseAsset = isNaiAsset(base) ? base as NaiAsset : this.hbdSatoshis(base as number | string | BigInt | Long); const baseAsset = isNaiAsset(base) ? this.assertAssetSymbol(EAssetName.HBD, base as NaiAsset) : this.hbdSatoshis(base as number | string | BigInt | Long);
const quoteAsset = isNaiAsset(quote) ? quote as NaiAsset : this.hiveSatoshis(quote as number | string | BigInt | Long); const quoteAsset = isNaiAsset(quote) ? this.assertAssetSymbol(EAssetName.HIVE, quote as NaiAsset) : this.hiveSatoshis(quote as number | string | BigInt | Long);
if (hbdAsset.nai !== this.ASSETS.HBD.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_hbd_to_hive(hbdAsset, baseAsset, quoteAsset) as NaiAsset; 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 { 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.hiveSatoshis(amount as number | string | BigInt | Long); const amountAsset = isNaiAsset(amount) ? this.assertAssetSymbol(EAssetName.HIVE, amount as NaiAsset) : this.hiveSatoshis(amount as number | string | BigInt | Long);
const baseAsset = isNaiAsset(base) ? base as NaiAsset : this.hbdSatoshis(base as number | string | BigInt | Long); const baseAsset = isNaiAsset(base) ? this.assertAssetSymbol(EAssetName.HBD, base as NaiAsset) : this.hbdSatoshis(base as number | string | BigInt | Long);
const quoteAsset = isNaiAsset(quote) ? quote as NaiAsset : this.hiveSatoshis(quote as number | string | BigInt | Long); const quoteAsset = isNaiAsset(quote) ? this.assertAssetSymbol(EAssetName.HIVE, quote as NaiAsset) : this.hiveSatoshis(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; return this.proto.cpp_hive_to_hbd(amountAsset, baseAsset, quoteAsset) as NaiAsset;
} }
...@@ -331,38 +302,23 @@ export class WaxBaseApi implements IWaxBaseInterface { ...@@ -331,38 +302,23 @@ export class WaxBaseApi implements IWaxBaseInterface {
} }
public calculateAccountHp(vests: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset { public calculateAccountHp(vests: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset {
const vestsAsset = isNaiAsset(vests) ? vests as NaiAsset : this.vestsSatoshis(vests as number | string | BigInt | Long); const vestsAsset = isNaiAsset(vests) ? this.assertAssetSymbol(EAssetName.VESTS, vests as NaiAsset) : this.vestsSatoshis(vests as number | string | BigInt | Long);
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long); const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? this.assertAssetSymbol(EAssetName.HIVE, totalVestingFundHive as NaiAsset) : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long);
const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? totalVestingShares as NaiAsset : this.vestsSatoshis(totalVestingShares as number | string | BigInt | Long); const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? this.assertAssetSymbol(EAssetName.VESTS, totalVestingShares as NaiAsset) : this.vestsSatoshis(totalVestingShares as number | string | BigInt | Long);
if (vestsAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for vests');
if (totalVestingFundHiveAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for totalVestingFundHive');
if (totalVestingSharesAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for totalVestingShares');
return this.proto.cpp_calculate_account_hp(vestsAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset; return this.proto.cpp_calculate_account_hp(vestsAsset, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset;
} }
public calculateWitnessVotesHp(votes: number, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset { public calculateWitnessVotesHp(votes: number, totalVestingFundHive: number | string | BigInt | Long | NaiAsset, totalVestingShares: number | string | BigInt | Long | NaiAsset): NaiAsset {
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long); const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? this.assertAssetSymbol(EAssetName.HIVE, totalVestingFundHive as NaiAsset) : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long);
const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? totalVestingShares as NaiAsset : this.vestsSatoshis(totalVestingShares as number | string | BigInt | Long); const totalVestingSharesAsset = isNaiAsset(totalVestingShares) ? this.assertAssetSymbol(EAssetName.VESTS, totalVestingShares as NaiAsset) : this.vestsSatoshis(totalVestingShares as number | string | BigInt | Long);
if (totalVestingFundHiveAsset.nai !== this.ASSETS.HIVE.nai)
throw new WaxError('Invalid asset type for totalVestingFundHive');
if (totalVestingSharesAsset.nai !== this.ASSETS.VESTS.nai)
throw new WaxError('Invalid asset type for totalVestingShares');
return this.proto.cpp_calculate_witness_votes_hp(votes, votes, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset; return this.proto.cpp_calculate_witness_votes_hp(votes, votes, totalVestingFundHiveAsset, totalVestingSharesAsset) as NaiAsset;
} }
public calculateHpApr(headBlockNum: number, vestingRewardPercent: number, virtualSupply: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset): number { public calculateHpApr(headBlockNum: number, vestingRewardPercent: number, virtualSupply: number | string | BigInt | Long | NaiAsset, totalVestingFundHive: number | string | BigInt | Long | NaiAsset): number {
const virtualSupplyAsset = isNaiAsset(virtualSupply) ? virtualSupply as NaiAsset : this.hiveSatoshis(virtualSupply as number | string | BigInt | Long); const virtualSupplyAsset = isNaiAsset(virtualSupply) ? this.assertAssetSymbol(EAssetName.HIVE, virtualSupply as NaiAsset) : this.hiveSatoshis(virtualSupply as number | string | BigInt | Long);
const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? totalVestingFundHive as NaiAsset : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long); const totalVestingFundHiveAsset = isNaiAsset(totalVestingFundHive) ? this.assertAssetSymbol(EAssetName.HIVE, totalVestingFundHive as NaiAsset) : this.hiveSatoshis(totalVestingFundHive as number | string | BigInt | Long);
return Number.parseFloat(this.extract(this.proto.cpp_calculate_hp_apr(headBlockNum, vestingRewardPercent, virtualSupplyAsset, totalVestingFundHiveAsset))); return Number.parseFloat(this.extract(this.proto.cpp_calculate_hp_apr(headBlockNum, vestingRewardPercent, virtualSupplyAsset, totalVestingFundHiveAsset)));
} }
......
...@@ -5,6 +5,7 @@ import { WaxError } from "../../errors.js"; ...@@ -5,6 +5,7 @@ import { WaxError } from "../../errors.js";
import { OperationBase, IOperationSink } from "../operation_base.js"; import { OperationBase, IOperationSink } from "../operation_base.js";
import Long from "long"; import Long from "long";
import { isNaiAsset } from "../util/asset_util.js"; import { isNaiAsset } from "../util/asset_util.js";
import { EAssetName, type WaxBaseApi } from '../base_api.js';
export enum ECommentFormat { export enum ECommentFormat {
HTML = "html", HTML = "html",
...@@ -158,7 +159,7 @@ class CommentOperation extends OperationBase { ...@@ -158,7 +159,7 @@ class CommentOperation extends OperationBase {
let payout: asset; let payout: asset;
if (isNaiAsset(this.maxAcceptedPayoutToSet)) if (isNaiAsset(this.maxAcceptedPayoutToSet))
payout = this.maxAcceptedPayoutToSet as asset; payout = (sink.api as WaxBaseApi).assertAssetSymbol(EAssetName.HBD, this.maxAcceptedPayoutToSet as asset);
else else
payout = sink.api.hbdSatoshis(this.maxAcceptedPayoutToSet as number | string | BigInt | Long); payout = sink.api.hbdSatoshis(this.maxAcceptedPayoutToSet as number | string | BigInt | Long);
......
...@@ -3,6 +3,7 @@ import type { asset, operation } from "../../protocol.js"; ...@@ -3,6 +3,7 @@ import type { asset, operation } from "../../protocol.js";
import { recurrent_transfer } from "../../proto/recurrent_transfer.js"; import { recurrent_transfer } from "../../proto/recurrent_transfer.js";
import { OperationBase, type IOperationSink } from "../operation_base.js"; import { OperationBase, type IOperationSink } from "../operation_base.js";
import { WaxError } from "../../errors.js"; import { WaxError } from "../../errors.js";
import { EAssetName, type WaxBaseApi } from "../base_api.js";
export interface IRecurrentTransferBaseData { export interface IRecurrentTransferBaseData {
/** /**
...@@ -60,7 +61,9 @@ class RecurrentTransferOperationBase extends OperationBase { ...@@ -60,7 +61,9 @@ class RecurrentTransferOperationBase extends OperationBase {
/** /**
* @internal * @internal
*/ */
public finalize(_sink: IOperationSink): Iterable<operation> { public finalize(sink: IOperationSink): Iterable<operation> {
(sink.api as WaxBaseApi).assertAssetSymbol([EAssetName.HBD, EAssetName.HIVE], this.recurrentTransfer.amount as asset);
return [{ recurrent_transfer: this.recurrentTransfer }]; return [{ recurrent_transfer: this.recurrentTransfer }];
} }
......
...@@ -2,6 +2,7 @@ import { asset, operation } from "../../protocol.js"; ...@@ -2,6 +2,7 @@ import { asset, operation } from "../../protocol.js";
import type { TAccountName } from "../hive_apps_operations/index.js"; import type { TAccountName } from "../hive_apps_operations/index.js";
import { update_proposal } from "../../proto/update_proposal.js"; import { update_proposal } from "../../proto/update_proposal.js";
import { OperationBase, IOperationSink } from "../operation_base.js"; import { OperationBase, IOperationSink } from "../operation_base.js";
import { EAssetName, type WaxBaseApi } from '../base_api.js';
export interface IUpdateProposalData { export interface IUpdateProposalData {
/** /**
...@@ -74,7 +75,9 @@ export class UpdateProposalOperation extends OperationBase { ...@@ -74,7 +75,9 @@ export class UpdateProposalOperation extends OperationBase {
/** /**
* @internal * @internal
*/ */
public finalize(_sink: IOperationSink): Iterable<operation> { public finalize(sink: IOperationSink): Iterable<operation> {
(sink.api as WaxBaseApi).assertAssetSymbol(EAssetName.HBD, this.updateProposal.daily_pay as asset);
return [{ update_proposal: this.updateProposal }]; return [{ update_proposal: this.updateProposal }];
} }
} }
...@@ -2,7 +2,7 @@ import { asset, operation, witness_set_properties } from "../../protocol.js"; ...@@ -2,7 +2,7 @@ import { asset, operation, witness_set_properties } from "../../protocol.js";
import { OperationBase, IOperationSink } from "../operation_base.js"; import { OperationBase, IOperationSink } from "../operation_base.js";
import { type witness_set_properties_data } from "../../wax_module.js"; import { type witness_set_properties_data } from "../../wax_module.js";
import { type TPublicKey } from "@hiveio/beekeeper"; import { type TPublicKey } from "@hiveio/beekeeper";
import { WaxBaseApi } from "../base_api.js"; import { EAssetName, type WaxBaseApi } from '../base_api.js';
import type Long from "long"; import type Long from "long";
import { TAccountName } from "../hive_apps_operations/index.js"; import { TAccountName } from "../hive_apps_operations/index.js";
import { isNaiAsset } from "../util/asset_util.js"; import { isNaiAsset } from "../util/asset_util.js";
...@@ -92,12 +92,12 @@ export class WitnessSetPropertiesOperation extends OperationBase { ...@@ -92,12 +92,12 @@ export class WitnessSetPropertiesOperation extends OperationBase {
if (this.hbdExchangeRate !== undefined) { if (this.hbdExchangeRate !== undefined) {
let base: asset, quote: asset; let base: asset, quote: asset;
if (isNaiAsset(this.hbdExchangeRate.base)) if (isNaiAsset(this.hbdExchangeRate.base))
base = this.hbdExchangeRate.base as asset; base = (sink.api as WaxBaseApi).assertAssetSymbol(EAssetName.HBD, this.hbdExchangeRate.base as asset);
else else
base = sink.api.hbdSatoshis(this.hbdExchangeRate.base as number | string | BigInt | Long); base = sink.api.hbdSatoshis(this.hbdExchangeRate.base as number | string | BigInt | Long);
if (isNaiAsset(this.hbdExchangeRate.quote)) if (isNaiAsset(this.hbdExchangeRate.quote))
quote = this.hbdExchangeRate.quote as asset; quote = (sink.api as WaxBaseApi).assertAssetSymbol(EAssetName.HIVE, this.hbdExchangeRate.quote as asset);
else else
quote = sink.api.hiveSatoshis(this.hbdExchangeRate.quote as number | string | BigInt | Long); quote = sink.api.hiveSatoshis(this.hbdExchangeRate.quote as number | string | BigInt | Long);
...@@ -108,7 +108,7 @@ export class WitnessSetPropertiesOperation extends OperationBase { ...@@ -108,7 +108,7 @@ export class WitnessSetPropertiesOperation extends OperationBase {
let fee: asset; let fee: asset;
if (isNaiAsset(this.accountCreationFee)) if (isNaiAsset(this.accountCreationFee))
fee = this.accountCreationFee as asset; fee = (sink.api as WaxBaseApi).assertAssetSymbol(EAssetName.HIVE, this.accountCreationFee as asset);
else else
fee = sink.api.hiveSatoshis(this.accountCreationFee as number | string | BigInt | Long); fee = sink.api.hiveSatoshis(this.accountCreationFee as number | string | BigInt | Long);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment