wallet: account type check.

This commit is contained in:
Christopher Jeffrey 2016-08-22 15:47:11 -07:00
parent 14da6a0875
commit 908d2eb9a9
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 9 additions and 25 deletions

View File

@ -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);

View File

@ -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));
});
};