From f1f07cf3ec7f33700d0abc7cb73424a16899b9af Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 6 Feb 2015 10:46:41 -0300 Subject: [PATCH] add copayer lookup --- lib/server.js | 2 +- lib/storage.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index a52793b..bc9224c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -151,7 +151,7 @@ CopayServer.prototype.joinWallet = function(opts, cb) { wallet.addCopayer(copayer); - self.storage.storeWallet(wallet, function(err) { + self.storage.storeWalletAndUpdateCopayersLookup(wallet, function(err) { return cb(err); }); }); diff --git a/lib/storage.js b/lib/storage.js index 7eb1789..8c1610d 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -32,6 +32,29 @@ Storage.prototype.storeWallet = function (wallet, cb) { this.db.put('wallet-' + wallet.id, wallet, cb); }; +Storage.prototype.storeWalletAndUpdateCopayersLookup = function (wallet, cb) { + var ops = []; + ops.push({ type: 'put', key: 'wallet-' + wallet.id, value: wallet }); + _.each(wallet.copayers, function (copayer) { + var value = { + walletId: wallet.id, + signingPubKey: copayer.signingPubKey, + }; + ops.push({ type: 'put', key: 'copayer-' + copayer.id, value: value }); + }); + this.db.batch(ops, cb); +}; + +Storage.prototype.fetchCopayerLookup = function (copayerId, cb) { + this.db.get('copayer-' + copayerId, function (err, data) { + if (err) { + if (err.notFound) return cb(); + return cb(err); + } + return cb(null, data); + }); +}; + Storage.prototype.fetchTx = function (walletId, txProposalId, cb) { this.db.get('wallet-' + walletId + '-txp-' + txProposalId, function (err, data) { if (err) {