wallet: fix tests and add compat routes.

This commit is contained in:
Christopher Jeffrey 2017-03-14 06:28:55 -07:00
parent 1d6bd6dbe4
commit 42da82e007
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 52 additions and 8 deletions

View File

@ -202,6 +202,26 @@ HTTPServer.prototype.initRouter = function initRouter() {
res.send(200, req.wallet.master.toJSON(true));
});
// Create wallet (compat)
this.post('/', co(function* (req, res) {
var valid = req.valid();
var wallet;
wallet = yield this.walletdb.create({
id: valid.str('id'),
type: valid.str('type'),
m: valid.u32('m'),
n: valid.u32('n'),
passphrase: valid.str('passphrase'),
master: valid.str('master'),
mnemonic: valid.str('mnemonic'),
accountKey: valid.str('accountKey'),
watchOnly: valid.bool('watchOnly')
});
res.send(200, wallet.toJSON());
}));
// Create wallet
this.put('/:id', co(function* (req, res) {
var valid = req.valid();
@ -242,6 +262,32 @@ HTTPServer.prototype.initRouter = function initRouter() {
res.send(200, account.toJSON());
}));
// Create account (compat)
this.post('/:id/account', co(function* (req, res) {
var valid = req.valid();
var passphrase = valid.str('passphrase');
var options, account;
options = {
name: valid.str(['account', 'name']),
witness: valid.bool('witness'),
watchOnly: valid.bool('watchOnly'),
type: valid.str('type'),
m: valid.u32('m'),
n: valid.u32('n'),
lookahead: valid.u32('lookahead')
};
account = yield req.wallet.createAccount(options, passphrase);
if (!account) {
res.send(404);
return;
}
res.send(200, account.toJSON());
}));
// Create account
this.put('/:id/account/:account', co(function* (req, res) {
var valid = req.valid();

View File

@ -11,6 +11,7 @@ var MTX = require('../lib/primitives/mtx');
var HTTP = require('../lib/http');
var FullNode = require('../lib/node/fullnode');
var pkg = require('../lib/pkg');
var plugin = require('../lib/wallet/plugin');
describe('HTTP', function() {
var node, wallet, walletdb, addr, hash;
@ -19,9 +20,7 @@ describe('HTTP', function() {
network: 'regtest',
apiKey: 'foo',
walletAuth: true,
db: 'memory',
loader: require,
plugins: ['walletdb']
db: 'memory'
});
wallet = new HTTP.Wallet({
@ -29,7 +28,7 @@ describe('HTTP', function() {
apiKey: 'foo'
});
walletdb = node.require('walletdb');
walletdb = node.use(plugin);
node.on('error', function() {});

View File

@ -8,17 +8,16 @@ var Coin = require('../lib/primitives/coin');
var Script = require('../lib/script/script');
var FullNode = require('../lib/node/fullnode');
var MTX = require('../lib/primitives/mtx');
var plugin = require('../lib/wallet/plugin');
describe('Node', function() {
var node = new FullNode({
db: 'memory',
apiKey: 'foo',
network: 'regtest',
loader: require,
plugins: ['../lib/wallet/plugin']
network: 'regtest'
});
var chain = node.chain;
var walletdb = node.require('walletdb');
var walletdb = node.use(plugin);
var miner = node.miner;
var wallet, tip1, tip2, cb1, cb2, mineBlock;