Browse Source

first attempt at integrating tingodb

activeAddress
Ivan Socolsky 10 years ago
parent
commit
7a0ec9f111
  1. 29
      lib/storage.js
  2. 15
      test/integration/server.js

29
lib/storage.js

@ -77,14 +77,9 @@ Storage.prototype.storeWalletAndUpdateCopayersLookup = function(wallet, cb) {
return this.storeWallet(wallet, cb); return this.storeWallet(wallet, cb);
}; };
Storage.prototype.fetchCopayerLookup = function(copayerId, cb) { Storage.prototype.fetchCopayerLookup2 = function(copayerId, cb) {
this.db.collection(collections.WALLETS).findOne({ this.db.collection(collections.WALLETS).findOne({
'copayers.id': copayerId 'copayers.id': copayerId
}, {
fields: {
id: 1,
copayers: 1,
},
}, function(err, result) { }, function(err, result) {
if (err) return cb(err); if (err) return cb(err);
if (!result) return cb(); if (!result) return cb();
@ -98,6 +93,28 @@ Storage.prototype.fetchCopayerLookup = function(copayerId, cb) {
}); });
}; };
Storage.prototype.fetchCopayerLookup = function(copayerId, cb) {
this.db.collection(collections.WALLETS).find({}).toArray(function(err, result) {
if (err) return cb(err);
result = _.find(result, function(w) {
return _.any(w.copayers, {
id: copayerId
});
});
if (!result) return cb();
var copayer = _.find(result.copayers, {
id: copayerId
});
return cb(null, {
walletId: result.id,
requestPubKey: copayer.requestPubKey,
});
});
};
// TODO: should be done client-side // TODO: should be done client-side
Storage.prototype._completeTxData = function(walletId, txs, cb) { Storage.prototype._completeTxData = function(walletId, txs, cb) {
var txList = [].concat(txs); var txList = [].concat(txs);

15
test/integration/server.js

@ -10,7 +10,8 @@ var should = chai.should();
var log = require('npmlog'); var log = require('npmlog');
log.debug = log.verbose; log.debug = log.verbose;
var mongodb = require('mongodb'); var fs = require('fs');
var tingodb = require('tingodb')();
var Utils = require('../../lib/utils'); var Utils = require('../../lib/utils');
var WalletUtils = require('bitcore-wallet-utils'); var WalletUtils = require('bitcore-wallet-utils');
@ -211,10 +212,13 @@ helpers.createAddresses = function(server, wallet, main, change, cb) {
var db, storage, blockchainExplorer; var db, storage, blockchainExplorer;
function openDb(cb) { function openDb(cb) {
var url = 'mongodb://localhost:27017/bws'; var tingodb = require('tingodb')();
mongodb.MongoClient.connect(url, function(err, _db) { var dbDir = './db/test/';
should.not.exist(err); fs.mkdir(dbDir, function(err) {
db = _db; if (err && err.code != 'EEXIST') {
throw new Error('Could not create test db directory at ./db/test/');
}
db = new tingodb.Db(dbDir, {});
return cb(); return cb();
}); });
}; };
@ -222,7 +226,6 @@ function openDb(cb) {
function resetDb(cb) { function resetDb(cb) {
if (!db) return cb(); if (!db) return cb();
db.dropDatabase(function(err) { db.dropDatabase(function(err) {
should.not.exist(err);
return cb(); return cb();
}); });
}; };

Loading…
Cancel
Save