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);
};
Storage.prototype.fetchCopayerLookup = function(copayerId, cb) {
Storage.prototype.fetchCopayerLookup2 = function(copayerId, cb) {
this.db.collection(collections.WALLETS).findOne({
'copayers.id': copayerId
}, {
fields: {
id: 1,
copayers: 1,
},
}, function(err, result) {
if (err) return cb(err);
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
Storage.prototype._completeTxData = function(walletId, txs, cb) {
var txList = [].concat(txs);

15
test/integration/server.js

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

Loading…
Cancel
Save