Skip to content

Commit

Permalink
Merge pull request #33 from trustenterprises/hotfix/memory-leakage-pt-1
Browse files Browse the repository at this point in the history
Adding a Singleton to load and retain Hedera client
  • Loading branch information
mattsmithies authored Jan 18, 2022
2 parents b47b22a + 1cab825 commit 729c9cb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/hashgraph/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ const networkForEnvironment = {
}
}

// Remove memory leak of creating a new network client
let hederaNetworkClient = null

const getNodeNetworkClient = () => {
const network = networkForEnvironment[Config.network]

if (!network || !network.nodes) {
throw `Network from environment ${Config.network} could not match for any hedera network. Change your "HEDERA_NETWORK" environment variable to either: "testnet", "previewnet" or "mainnet"`
}

return new Client({ network: network.nodes.network }).setOperator(
Config.accountId,
Config.privateKey
)
if (hederaNetworkClient === null) {
hederaNetworkClient = new Client({
network: network.nodes.network
}).setOperator(Config.accountId, Config.privateKey)
}

return hederaNetworkClient
}

export default {
Expand Down

0 comments on commit 729c9cb

Please sign in to comment.