Transaction: rename type to hashType

This commit is contained in:
Daniel Cousens 2014-06-13 16:25:41 +10:00
parent a2d581dec5
commit 8e5fdb78a8

View file

@ -285,26 +285,26 @@ Transaction.fromHex = function(hex) {
/** /**
* Signs a pubKeyHash output at some index with the given key * Signs a pubKeyHash output at some index with the given key
*/ */
Transaction.prototype.sign = function(index, key, type) { Transaction.prototype.sign = function(index, key, hashType) {
var prevOutScript = key.pub.getAddress().toOutputScript() var prevOutScript = key.pub.getAddress().toOutputScript()
var signature = this.signInput(index, prevOutScript, key, type) var signature = this.signInput(index, prevOutScript, key, hashType)
// FIXME: Assumed prior TX was pay-to-pubkey-hash // FIXME: Assumed prior TX was pay-to-pubkey-hash
var scriptSig = scripts.pubKeyHashInput(signature, key.pub) var scriptSig = scripts.pubKeyHashInput(signature, key.pub)
this.setInputScript(index, scriptSig) this.setInputScript(index, scriptSig)
} }
Transaction.prototype.signInput = function(index, prevOutScript, key, type) { Transaction.prototype.signInput = function(index, prevOutScript, key, hashType) {
type = type || SIGHASH_ALL hashType = hashType || SIGHASH_ALL
assert(key instanceof ECKey, 'Invalid private key') assert(key instanceof ECKey, 'Invalid private key')
var hash = this.hashForSignature(prevOutScript, index, type) var hash = this.hashForSignature(prevOutScript, index, hashType)
var signature = key.sign(hash) var signature = key.sign(hash)
var DERencoded = ecdsa.serializeSig(signature) var DERencoded = ecdsa.serializeSig(signature)
return Buffer.concat([ return Buffer.concat([
new Buffer(DERencoded), new Buffer(DERencoded),
new Buffer([type]) new Buffer([hashType])
]) ])
} }