From 3b287fc629b2c6b10f8117604a277d8a4f613bc0 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 11 Dec 2020 20:38:18 +0200 Subject: [PATCH] Make sure database is closed properly --- package.json | 2 +- src/levelUtils.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7cb210b..45c901f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ezerous/eth-identity-provider", - "version": "0.1.1", + "version": "0.1.2", "description": "An Ethereum orbit-db-identity-provider.", "license": "MIT", "author": "Ezerous ", diff --git a/src/levelUtils.js b/src/levelUtils.js index 0d49850..14dc4f2 100644 --- a/src/levelUtils.js +++ b/src/levelUtils.js @@ -3,20 +3,25 @@ import level from 'level'; /* Used in development only to store the identity.signatures.publicKey so developers don't have to repeatedly sign theOrbitDB creation transaction in MetaMask when React development server reloads the app */ -const ethProviderDB = level('ethprovider/identities'); +const ethProviderDBName = 'ethprovider/identities'; async function storeIdentitySignaturePubKey(key, signaturePubKey) { + const ethProviderDB = level(ethProviderDBName); await ethProviderDB.put(key, signaturePubKey); + ethProviderDB.close(); } // If it exists, it returns the identity.signatures.publicKey for the given key (key is the // concatenation of identity.publicKey + identity.signatures.id) async function getIdentitySignaturePubKey(key) { + const ethProviderDB = level(ethProviderDBName); try { return await ethProviderDB.get(key); } catch (err) { if (err && err.notFound) return null; // Not found throw err; + } finally { + ethProviderDB.close(); } }