Browse Source

Merge pull request #16 from isocolsky/ref/copayer_index

add copayer lookup table
activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
a04a94dba2
  1. 2
      lib/server.js
  2. 23
      lib/storage.js

2
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);
});
});

23
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) {

Loading…
Cancel
Save