From 9682128575f756ddb2699f11276db874b292f25d Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Tue, 29 Oct 2024 15:14:39 +0200 Subject: [PATCH] refactor: extract variables to const Signed-off-by: Ivaylo Nikolov --- src/transaction/NodeAccountIdSignatureMap.js | 7 ++++--- src/transaction/SignatureMap.js | 10 ++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/transaction/NodeAccountIdSignatureMap.js b/src/transaction/NodeAccountIdSignatureMap.js index 342e94060..ed9271f44 100644 --- a/src/transaction/NodeAccountIdSignatureMap.js +++ b/src/transaction/NodeAccountIdSignatureMap.js @@ -68,13 +68,14 @@ export default class NodeAccountIdSignatureMap extends ObjectMap { * @param {Uint8Array} signature */ addSignature(txId, publicKey, signature) { - if (!this.get(txId)) { + const sigPairMap = this.get(txId); + if (sigPairMap) { + sigPairMap.addSignature(publicKey, signature); + } else { this._set( txId, new SignaturePairMap().addSignature(publicKey, signature), ); - } else { - this.get(txId)?.addSignature(publicKey, signature); } } } diff --git a/src/transaction/SignatureMap.js b/src/transaction/SignatureMap.js index afff16b3a..7e6d39d6b 100644 --- a/src/transaction/SignatureMap.js +++ b/src/transaction/SignatureMap.js @@ -85,20 +85,18 @@ export default class SignatureMap extends ObjectMap { * @returns {SignatureMap} */ addSignature(nodeId, txId, publicKey, signature) { - if (!this.get(nodeId)) { - this._set(nodeId, new NodeAccountIdSignatureMap()); - } + let nodeAccountIdSigdMap = this.get(nodeId); - const nodeAccountIdSigdMap = this.get(nodeId); if (!nodeAccountIdSigdMap) { - throw new Error("Node Account ID Signature Map not found"); + nodeAccountIdSigdMap = new NodeAccountIdSignatureMap(); + this._set(nodeId, nodeAccountIdSigdMap); } nodeAccountIdSigdMap.addSignature(txId, publicKey, signature); this._set(nodeId, nodeAccountIdSigdMap); + return this; } - /** * @returns {SignaturePairMap[]} */