Skip to content

Commit

Permalink
fix: useone of preselected nodes to execute the transaction (#2165)
Browse files Browse the repository at this point in the history
Signed-off-by: svetoslav-nikol0v <[email protected]>
  • Loading branch information
svetoslav-nikol0v authored Feb 22, 2024
1 parent b3ea831 commit cee33ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
11 changes: 4 additions & 7 deletions src/Executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,13 @@ export default class Executable {
let nodeAccountId;
let node;

// If node account IDs is locked then use the node account IDs
// from the list, otherwise build a new list of one node account ID
// using the entire network
if (this._nodeAccountIds.locked) {
nodeAccountId = this._nodeAccountIds.current;
node = client._network.getNode(nodeAccountId);
} else {
if (this._nodeAccountIds.isEmpty) {
node = client._network.getNode();
nodeAccountId = node.accountId;
this._nodeAccountIds.setList([nodeAccountId]);
} else {
nodeAccountId = this._nodeAccountIds.current;
node = client._network.getNode(nodeAccountId);
}

if (node == null) {
Expand Down
8 changes: 6 additions & 2 deletions src/client/ManagedNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ export default class ManagedNetwork {

// Add the selected node in array for execution
nodes.push(selectedNode);
// Remove the selected node from array
healthyNodes.splice(nodeIndex, 1);
// Remove all nodes with the same account id as
// the selected node account id from the array
healthyNodes = healthyNodes.filter(
// eslint-disable-next-line ie11/no-loop-func
(node) => node.getKey() !== selectedNode.getKey(),
);
}

return nodes;
Expand Down
16 changes: 9 additions & 7 deletions src/transaction/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,14 @@ export default class Transaction extends Executable {
// be regenerated if more signatures are added
transaction._transactions.setList(transactions);

// Set the signed transactions accordingly, and lock the list since signed transaction
// will not be regenerated. Although, they can be manipulated if for instance more
// signatures are added
// Set the signed transactions accordingly. Although, they
// can be manipulated if for instance more signatures are added
transaction._signedTransactions.setList(signedTransactions);

// Set the transaction IDs accordingly, and lock the list. Transaction IDs should not
// be regenerated if we're deserializing a request from bytes
// Set the transaction IDs accordingly
transaction._transactionIds.setList(transactionIds);

// Set the node account IDs accordingly, and lock the list. Node account IDs should
// never be changed if we're deserializing a request from bytes
// Set the node account IDs accordingly
transaction._nodeAccountIds.setList(nodeIds);

// Make sure to update the rest of the fields
Expand Down Expand Up @@ -701,6 +698,11 @@ export default class Transaction extends Executable {
* @returns {Promise<this>}
*/
async signWith(publicKey, transactionSigner) {
// If signing on demand is disabled, we need to make sure
// the request is frozen
if (!this._signOnDemand) {
this._requireFrozen();
}
const publicKeyData = publicKey.toBytesRaw();

// note: this omits the DER prefix on purpose because Hedera doesn't
Expand Down

0 comments on commit cee33ac

Please sign in to comment.