diff --git a/bin/cli b/bin/cli index ba82e19e..13a608ff 100755 --- a/bin/cli +++ b/bin/cli @@ -105,7 +105,8 @@ CLI.prototype.getAccount = co(function* getAccount() { }); CLI.prototype.createAccount = co(function* createAccount() { - var options = { name: this.config.str(0) }; + var name = this.config.str(0); + var options = {}; var account; options.type = this.config.str('type'); @@ -114,7 +115,7 @@ CLI.prototype.createAccount = co(function* createAccount() { options.witness = this.config.bool('witness'); options.accountKey = this.config.str('watch'); - account = yield this.wallet.createAccount(options); + account = yield this.wallet.createAccount(name, options); this.log(account); }); diff --git a/lib/http/client.js b/lib/http/client.js index 44ec7be0..84c26304 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -927,7 +927,7 @@ HTTPClient.prototype.getMaster = function getMaster(id) { * Get wallet account. * @param {WalletID} id * @param {String} account - * @returns {Promise} - Returns Array. + * @returns {Promise} */ HTTPClient.prototype.getAccount = function getAccount(id, account) { @@ -938,22 +938,14 @@ HTTPClient.prototype.getAccount = function getAccount(id, account) { /** * Create account. * @param {WalletID} id + * @param {String} name * @param {Object} options - * @returns {Promise} - Returns Array. + * @returns {Promise} */ -HTTPClient.prototype.createAccount = function createAccount(id, options) { - var path; - - if (!options) - options = {}; - - if (typeof options === 'string') - options = { account: options }; - - path = '/wallet/' + id + '/account' + options.account; - - return this._put(path, options); +HTTPClient.prototype.createAccount = function createAccount(id, name, options) { + var path = '/wallet/' + id + '/account/' + name; + return this._put(path, options || {}); }; /** diff --git a/lib/http/wallet.js b/lib/http/wallet.js index e2bf6294..2d3f8001 100644 --- a/lib/http/wallet.js +++ b/lib/http/wallet.js @@ -310,8 +310,8 @@ HTTPWallet.prototype.getAccount = function getAccount(account) { * @see Wallet#createAccount */ -HTTPWallet.prototype.createAccount = function createAccount(options) { - return this.client.createAccount(this.id, options); +HTTPWallet.prototype.createAccount = function createAccount(name, options) { + return this.client.createAccount(this.id, name, options); }; /** diff --git a/lib/node/node.js b/lib/node/node.js index 559b8f25..d7014239 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -17,7 +17,6 @@ var workerPool = require('../workers/workerpool').pool; var ec = require('../crypto/ec'); var native = require('../utils/native'); var Config = require('./config'); -var SigCache = require('../script/sigcache'); /** * Base class from which every other diff --git a/lib/wallet/http.js b/lib/wallet/http.js index baebf223..b9b8ec05 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -275,6 +275,7 @@ HTTPServer.prototype.initRouter = function initRouter() { type: valid.str('type'), m: valid.u32('m'), n: valid.u32('n'), + accountKey: valid.str('accountKey'), lookahead: valid.u32('lookahead') }; @@ -301,6 +302,7 @@ HTTPServer.prototype.initRouter = function initRouter() { type: valid.str('type'), m: valid.u32('m'), n: valid.u32('n'), + accountKey: valid.str('accountKey'), lookahead: valid.u32('lookahead') }; diff --git a/test/http-test.js b/test/http-test.js index b73734f4..d0c1573d 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -154,6 +154,30 @@ describe('HTTP', function() { assert.equal(info.blocks, 0); })); + it('should create account', co(function* () { + var info = yield wallet.createAccount('foo1'); + assert(info); + assert(info.initialized); + assert.equal(info.name, 'foo1'); + assert.equal(info.accountIndex, 1); + assert.equal(info.m, 1); + assert.equal(info.n, 1); + })); + + it('should create account', co(function* () { + var info = yield wallet.createAccount('foo2', { + type: 'multisig', + m: 1, + n: 2 + }); + assert(info); + assert(!info.initialized); + assert.equal(info.name, 'foo2'); + assert.equal(info.accountIndex, 2); + assert.equal(info.m, 1); + assert.equal(info.n, 2); + })); + it('should get a block template', co(function* () { var json = yield wallet.client.rpc.execute('getblocktemplate', []); assert.deepStrictEqual(json, {