Transaction: mass rename from SPK/SS to Input/Output
I think it is important we maintain some reasoning that an Input script is actually a script signature, but in the end, these names are more coherent and understandable when reasoning with our code. So I think its OK we break tradition with bitcoind.
This commit is contained in:
parent
5a96df1ec1
commit
7e5af52cd1
8 changed files with 39 additions and 41 deletions
|
@ -35,7 +35,7 @@ Address.fromBase58Check = function(string) {
|
|||
return new Address(hash, version)
|
||||
}
|
||||
|
||||
Address.fromScriptPubKey = function(script, network) {
|
||||
Address.fromOutputScript = function(script, network) {
|
||||
network = network || networks.bitcoin
|
||||
|
||||
var type = scripts.classifyOutput(script)
|
||||
|
@ -59,7 +59,7 @@ Address.prototype.toBase58Check = function () {
|
|||
return base58check.encode(payload)
|
||||
}
|
||||
|
||||
Address.prototype.toScriptPubKey = function() {
|
||||
Address.prototype.toOutputScript = function() {
|
||||
var scriptType = findScriptTypeByVersion(this.version)
|
||||
|
||||
if (scriptType === 'pubkeyhash') {
|
||||
|
|
|
@ -110,7 +110,7 @@ Transaction.prototype.addOutput = function (address, value) {
|
|||
|
||||
this.outs.push(new TransactionOut({
|
||||
value: value,
|
||||
script: address.toScriptPubKey(),
|
||||
script: address.toOutputScript(),
|
||||
address: address // TODO: Remove me
|
||||
}))
|
||||
}
|
||||
|
@ -196,13 +196,13 @@ var SIGHASH_ANYONECANPAY = 0x80
|
|||
* hashType, serializes and finally hashes the result. This hash can then be
|
||||
* used to sign the transaction input in question.
|
||||
*/
|
||||
Transaction.prototype.hashForSignature = function(scriptPubKey, inIndex, hashType) {
|
||||
Transaction.prototype.hashForSignature = function(prevOutScript, inIndex, hashType) {
|
||||
assert(inIndex >= 0, 'Invalid vin index')
|
||||
assert(inIndex < this.ins.length, 'Invalid vin index')
|
||||
assert(scriptPubKey instanceof Script, 'Invalid Script object')
|
||||
assert(prevOutScript instanceof Script, 'Invalid Script object')
|
||||
|
||||
var txTmp = this.clone()
|
||||
var hashScript = scriptPubKey.without(opcodes.OP_CODESEPARATOR)
|
||||
var hashScript = prevOutScript.without(opcodes.OP_CODESEPARATOR)
|
||||
|
||||
// Blank out other inputs' signatures
|
||||
txTmp.ins.forEach(function(txin) {
|
||||
|
@ -239,8 +239,7 @@ Transaction.prototype.getHash = function () {
|
|||
return buffer.toString('hex')
|
||||
}
|
||||
|
||||
Transaction.prototype.clone = function ()
|
||||
{
|
||||
Transaction.prototype.clone = function () {
|
||||
var newTx = new Transaction()
|
||||
newTx.version = this.version
|
||||
newTx.locktime = this.locktime
|
||||
|
@ -337,24 +336,22 @@ Transaction.fromHex = function(hex) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Signs a standard 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) {
|
||||
assert(key instanceof ECKey)
|
||||
|
||||
var script = key.pub.getAddress().toScriptPubKey()
|
||||
var signature = this.signScriptSig(index, script, key, type)
|
||||
var prevOutScript = key.pub.getAddress().toOutputScript()
|
||||
var signature = this.signInput(index, prevOutScript, key, type)
|
||||
|
||||
// FIXME: Assumed prior TX was pay-to-pubkey-hash
|
||||
var scriptSig = scripts.pubKeyHashInput(signature, key.pub)
|
||||
this.setScriptSig(index, scriptSig)
|
||||
this.setInputScript(index, scriptSig)
|
||||
}
|
||||
|
||||
Transaction.prototype.signScriptSig = function(index, scriptPubKey, key, type) {
|
||||
Transaction.prototype.signInput = function(index, prevOutScript, key, type) {
|
||||
type = type || SIGHASH_ALL
|
||||
assert(key instanceof ECKey, 'Invalid private key')
|
||||
|
||||
var hash = this.hashForSignature(scriptPubKey, index, type)
|
||||
var hash = this.hashForSignature(prevOutScript, index, type)
|
||||
var signature = key.sign(hash)
|
||||
var DERencoded = ecdsa.serializeSig(signature)
|
||||
|
||||
|
@ -364,11 +361,12 @@ Transaction.prototype.signScriptSig = function(index, scriptPubKey, key, type) {
|
|||
])
|
||||
}
|
||||
|
||||
Transaction.prototype.setScriptSig = function(index, script) {
|
||||
Transaction.prototype.setInputScript = function(index, script) {
|
||||
this.ins[index].script = script
|
||||
}
|
||||
|
||||
Transaction.prototype.validateSig = function(index, script, pub, DERsig) {
|
||||
// FIXME: should probably be validateInput(index, pub)
|
||||
Transaction.prototype.validateInput = function(index, script, pub, DERsig) {
|
||||
var type = DERsig.readUInt8(DERsig.length - 1)
|
||||
DERsig = DERsig.slice(0, -1)
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ function Wallet(seed, network) {
|
|||
var address
|
||||
|
||||
try {
|
||||
address = Address.fromScriptPubKey(txOut.script, network).toString()
|
||||
address = Address.fromOutputScript(txOut.script, network).toString()
|
||||
} catch(e) {
|
||||
if (!(e.message.match(/has no matching Address/))) throw e
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue