Skip to content

Commit

Permalink
Add max execution time setter (hashgraph#1354)
Browse files Browse the repository at this point in the history
Signed-off-by: ochikov <[email protected]>

Signed-off-by: ochikov <[email protected]>
  • Loading branch information
ochikov authored Dec 13, 2022
1 parent a70c077 commit c74258e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/channel/NodeChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export default class NodeChannel extends Channel {
* @internal
* @param {string} address
* @param {string=} cert
* @param {number=} maxExecutionTime
*/
constructor(address, cert) {
constructor(address, cert, maxExecutionTime) {
super();

this.cert = cert;
this.maxExecutionTime = maxExecutionTime;

let security;
let options;
Expand Down Expand Up @@ -96,7 +98,7 @@ export default class NodeChannel extends Channel {
//Removed close of the client because taking more than 10s does not mean that the node is unavailable.
callback(new GrpcServicesError(GrpcStatus.Timeout));
}
}, 10_000);
}, this.maxExecutionTime);

this._client.makeUnaryRequest(
`/proto.${serviceName}/${method.name}`,
Expand Down
17 changes: 16 additions & 1 deletion src/client/NodeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export default class NodeClient extends Client {
constructor(props) {
super(props);

/** @private */
this._maxExecutionTime = 10000;

if (props != null) {
if (typeof props.network === "string") {
this._setNetworkFromName(props.network);
Expand Down Expand Up @@ -220,6 +223,17 @@ export default class NodeClient extends Client {
}
}

/**
* Available only for NodeClient
*
* @param {number} maxExecutionTime
* @returns {this}
*/
setMaxExecutionTime(maxExecutionTime) {
this._maxExecutionTime = maxExecutionTime;
return this;
}

/**
* @private
* @param {string} name
Expand Down Expand Up @@ -302,7 +316,8 @@ export default class NodeClient extends Client {
* @returns {(address: string, cert?: string) => NodeChannel}
*/
_createNetworkChannel() {
return (address, cert) => new NodeChannel(address, cert);
return (address, cert) =>
new NodeChannel(address, cert, this._maxExecutionTime);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/integration/AccountCreateIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe("AccountCreate", function () {
await (await transaction.execute(env.client)).getReceipt(env.client);
});

it("should create account with a single key passed to `KeyList`", async function() {
it("should create account with a single key passed to `KeyList`", async function () {
const env = await IntegrationTestEnv.new();
const publicKey = PrivateKey.generateED25519().publicKey;
const thresholdKey = new KeyList(publicKey, 1);
Expand Down

0 comments on commit c74258e

Please sign in to comment.