Browse Source

Make sure database is closed properly

develop
Ezerous 4 years ago
parent
commit
3b287fc629
  1. 2
      package.json
  2. 7
      src/levelUtils.js

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@ezerous/eth-identity-provider", "name": "@ezerous/eth-identity-provider",
"version": "0.1.1", "version": "0.1.2",
"description": "An Ethereum orbit-db-identity-provider.", "description": "An Ethereum orbit-db-identity-provider.",
"license": "MIT", "license": "MIT",
"author": "Ezerous <ezerous@gmail.com>", "author": "Ezerous <ezerous@gmail.com>",

7
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 /* 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 repeatedly sign theOrbitDB creation transaction in MetaMask when React development server reloads
the app */ the app */
const ethProviderDB = level('ethprovider/identities'); const ethProviderDBName = 'ethprovider/identities';
async function storeIdentitySignaturePubKey(key, signaturePubKey) { async function storeIdentitySignaturePubKey(key, signaturePubKey) {
const ethProviderDB = level(ethProviderDBName);
await ethProviderDB.put(key, signaturePubKey); await ethProviderDB.put(key, signaturePubKey);
ethProviderDB.close();
} }
// If it exists, it returns the identity.signatures.publicKey for the given key (key is the // If it exists, it returns the identity.signatures.publicKey for the given key (key is the
// concatenation of identity.publicKey + identity.signatures.id) // concatenation of identity.publicKey + identity.signatures.id)
async function getIdentitySignaturePubKey(key) { async function getIdentitySignaturePubKey(key) {
const ethProviderDB = level(ethProviderDBName);
try { try {
return await ethProviderDB.get(key); return await ethProviderDB.get(key);
} catch (err) { } catch (err) {
if (err && err.notFound) return null; // Not found if (err && err.notFound) return null; // Not found
throw err; throw err;
} finally {
ethProviderDB.close();
} }
} }

Loading…
Cancel
Save