diff --git a/lib/bcoin/keyring.js b/lib/bcoin/keyring.js index 521754ae..1f61a467 100644 --- a/lib/bcoin/keyring.js +++ b/lib/bcoin/keyring.js @@ -66,12 +66,12 @@ KeyRing.prototype.fromOptions = function fromOptions(options, network) { key = toKey(options.key); - if (options.privateKey) - key = toKey(options.privateKey); - if (options.publicKey) key = toKey(options.publicKey); + if (options.privateKey) + key = toKey(options.privateKey); + if (options.network) this.network = bcoin.network.get(options.network); diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 3359decb..6e1da733 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -834,6 +834,9 @@ Wallet.prototype.importKey = function importKey(account, ring, passphrase, callb if (!account) return callback(new Error('Account not found.')); + if (account.type !== Account.types.PUBKEYHASH) + return callback(new Error('Cannot import into non-pkh account.')); + self.unlock(passphrase, null, function(err) { if (err) return callback(err); @@ -1401,37 +1404,18 @@ Wallet.prototype.handleTX = function handleTX(info, callback) { Wallet.prototype.getRedeem = function getRedeem(hash, callback) { var self = this; - var ring; if (typeof hash === 'string') hash = new Buffer(hash, 'hex'); - this.getPath(hash.toString('hex'), function(err, path) { + this.getKeyring(hash.toString('hex'), function(err, ring) { if (err) return callback(err); - if (!path) + if (!ring) return callback(); - self.getAccount(path.account, function(err, account) { - if (err) - return callback(err); - - if (!account) - return callback(); - - ring = account.derivePath(path, self.master); - - if (!ring) - return callback(); - - if (ring.program && hash.length === 20) { - if (utils.equal(hash, ring.programHash)) - return callback(null, ring.program); - } - - callback(null, ring.script); - }); + callback(null, ring.getRedeem(hash)); }); };