This commit is contained in:
Ivan Socolsky 2015-01-29 15:00:35 -03:00
parent 171f542c97
commit d7a2dcc866
2 changed files with 56 additions and 51 deletions

View File

@ -28,6 +28,10 @@ Storage.prototype.fetchWallet = function (id, cb) {
});
};
Storage.prototype.storeWallet = function (wallet, cb) {
this.db.put('wallet-' + wallet.id, wallet, cb);
};
Storage.prototype.fetchTx = function (walletId, txProposalId, cb) {
this.db.get('wallet-' + walletId + '-txp-' + txProposalId, function (err, data) {
if (err) {
@ -38,12 +42,20 @@ Storage.prototype.fetchTx = function (walletId, txProposalId, cb) {
});
};
Storage.prototype.storeWallet = function (wallet, cb) {
this.db.put('wallet-' + wallet.id, wallet, cb);
};
Storage.prototype.storeAddress = function (walletId, address, cb) {
this.db.put('wallet-' + walletId + '-address-' + address.address, address, cb);
Storage.prototype.fetchTxs = function (walletId, cb) {
var txs = [];
var key = 'wallet-' + walletId + '-txp-';
this.db.createReadStream({ gte: key, lt: key + '~' })
.on('data', function (data) {
txs.push(TxProposal.fromObj(data.value));
})
.on('error', function (err) {
if (err.notFound) return cb();
return cb(err);
})
.on('end', function () {
return cb(null, txs);
});
};
Storage.prototype.storeTx = function (walletId, txp, cb) {
@ -66,22 +78,12 @@ Storage.prototype.fetchAddresses = function (walletId, cb) {
});
};
Storage.prototype.fetchTxs = function (walletId, cb) {
var txs = [];
var key = 'wallet-' + walletId + '-txp-';
this.db.createReadStream({ gte: key, lt: key + '~' })
.on('data', function (data) {
txs.push(TxProposal.fromObj(data.value));
})
.on('error', function (err) {
if (err.notFound) return cb();
return cb(err);
})
.on('end', function () {
return cb(null, txs);
});
Storage.prototype.storeAddress = function (walletId, address, cb) {
this.db.put('wallet-' + walletId + '-address-' + address.address, address, cb);
};
Storage.prototype._dump = function (cb) {
this.db.readStream()
.on('data', console.log)

View File

@ -16,9 +16,43 @@ var Address = require('../lib/model/address');
var Copayer = require('../lib/model/copayer');
var CopayServer = require('../lib/server');
var helpers = {};
helpers.createAndJoinWallet = function (id, m, n, cb) {
var walletOpts = {
id: id,
name: id + ' wallet',
m: m,
n: n,
pubKey: 'dummy',
};
server.createWallet(walletOpts, function(err) {
if (err) return cb(err);
async.each(_.range(1, n + 1), function (i, cb) {
var copayerOpts = {
walletId: id,
id: '' + i,
name: 'copayer ' + i,
xPubKey: 'dummy' + i,
xPubKeySignature: 'dummy',
};
server.joinWallet(copayerOpts, function (err) {
return cb(err);
});
}, function (err) {
if (err) return cb(err);
server.getWallet({ id: id, includeCopayers: true }, function (err, wallet) {
return cb(err, wallet);
});
});
});
};
var db, storage;
var server;
describe('Copay server', function() {
beforeEach(function() {
db = levelup(memdown, { valueEncoding: 'json' });
@ -292,37 +326,6 @@ describe('Copay server', function() {
});
var helpers = {};
helpers.createAndJoinWallet = function (id, m, n, cb) {
var walletOpts = {
id: id,
name: id + ' wallet',
m: m,
n: n,
pubKey: 'dummy',
};
server.createWallet(walletOpts, function(err) {
if (err) return cb(err);
async.each(_.range(1, n + 1), function (i, cb) {
var copayerOpts = {
walletId: id,
id: '' + i,
name: 'copayer ' + i,
xPubKey: 'dummy' + i,
xPubKeySignature: 'dummy',
};
server.joinWallet(copayerOpts, function (err) {
return cb(err);
});
}, function (err) {
if (err) return cb(err);
server.getWallet({ id: id, includeCopayers: true }, function (err, wallet) {
return cb(err, wallet);
});
});
});
};
describe('#verifyMessageSignature', function() {
beforeEach(function() {