From e5590c8693ad65fa5b5dfaf2e99ce152da55927a Mon Sep 17 00:00:00 2001 From: Petar Tonev Date: Wed, 1 Feb 2023 12:55:12 +0200 Subject: [PATCH 1/2] fix inaccurate cost calculation Signed-off-by: Petar Tonev --- src/query/Query.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/query/Query.js b/src/query/Query.js index 88da3b9a4..ba9dc4aa3 100644 --- a/src/query/Query.js +++ b/src/query/Query.js @@ -173,7 +173,7 @@ export default class Query extends Executable { * @param {import("../client/Client.js").default} client * @returns {Promise} */ - getCost(client) { + async getCost(client) { // The node account IDs must be set to execute a cost query if (this._nodeAccountIds.isEmpty) { this._nodeAccountIds.setList( @@ -187,8 +187,9 @@ export default class Query extends Executable { // Change the timestamp. Should we be doing this? this._timestamp = Date.now(); + const cost = await COST_QUERY[0](this).execute(client); - return COST_QUERY[0](this).execute(client); + return Hbar.fromString(cost.toBigNumber().plus(0.001).toString()); } /** @@ -343,9 +344,7 @@ export default class Query extends Executable { // Not sure if we should be overwritting this field tbh. this._timestamp = Date.now(); - if (!this._nodeAccountIds.locked) { - return; - } + this._nodeAccountIds.setLocked(); // Generate the payment transactions for (const node of this._nodeAccountIds.list) { @@ -357,7 +356,7 @@ export default class Query extends Executable { ), node, this._isPaymentRequired() ? this._operator : null, - /** @type {Hbar} */ (cost) + /** @type {Hbar} */ (this._queryPayment) ) ); } From c82618f5b351db9022ee9bc3e4d63a3250b630c9 Mon Sep 17 00:00:00 2001 From: Petar Tonev Date: Wed, 1 Feb 2023 13:06:35 +0200 Subject: [PATCH 2/2] rename misleading comment Signed-off-by: Petar Tonev --- examples/create-stateful-contract.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/create-stateful-contract.js b/examples/create-stateful-contract.js index eebc5b2ba..bdebd9e47 100644 --- a/examples/create-stateful-contract.js +++ b/examples/create-stateful-contract.js @@ -155,8 +155,7 @@ async function main() { .setGas(75000) // Set the function to call on the contract .setFunction("get_message") - // Set the query payment explicitly since sometimes automatic payment calculated - // is too low + // Set query payment explicitly .setQueryPayment(new Hbar(3)) .executeWithSigner(wallet);