Transaction: move constants to Transaction
This commit is contained in:
parent
4850570955
commit
d07cfccbc1
2 changed files with 11 additions and 11 deletions
|
@ -9,11 +9,11 @@ var ECKey = require('./eckey')
|
||||||
var ECSignature = require('./ecsignature')
|
var ECSignature = require('./ecsignature')
|
||||||
var Script = require('./script')
|
var Script = require('./script')
|
||||||
|
|
||||||
var DEFAULT_SEQUENCE = 0xffffffff
|
Transaction.DEFAULT_SEQUENCE = 0xffffffff
|
||||||
var SIGHASH_ALL = 0x01
|
Transaction.SIGHASH_ALL = 0x01
|
||||||
var SIGHASH_NONE = 0x02
|
Transaction.SIGHASH_NONE = 0x02
|
||||||
var SIGHASH_SINGLE = 0x03
|
Transaction.SIGHASH_SINGLE = 0x03
|
||||||
var SIGHASH_ANYONECANPAY = 0x80
|
Transaction.SIGHASH_ANYONECANPAY = 0x80
|
||||||
|
|
||||||
function Transaction() {
|
function Transaction() {
|
||||||
this.version = 1
|
this.version = 1
|
||||||
|
@ -33,7 +33,7 @@ function Transaction() {
|
||||||
* Note that this method does not sign the created input.
|
* Note that this method does not sign the created input.
|
||||||
*/
|
*/
|
||||||
Transaction.prototype.addInput = function(tx, index, sequence) {
|
Transaction.prototype.addInput = function(tx, index, sequence) {
|
||||||
if (sequence == undefined) sequence = DEFAULT_SEQUENCE
|
if (sequence == undefined) sequence = Transaction.DEFAULT_SEQUENCE
|
||||||
|
|
||||||
var hash
|
var hash
|
||||||
|
|
||||||
|
@ -175,15 +175,15 @@ Transaction.prototype.hashForSignature = function(prevOutScript, inIndex, hashTy
|
||||||
txTmp.ins[inIndex].script = hashScript
|
txTmp.ins[inIndex].script = hashScript
|
||||||
|
|
||||||
var hashTypeModifier = hashType & 0x1f
|
var hashTypeModifier = hashType & 0x1f
|
||||||
if (hashTypeModifier === SIGHASH_NONE) {
|
if (hashTypeModifier === Transaction.SIGHASH_NONE) {
|
||||||
assert(false, 'SIGHASH_NONE not yet supported')
|
assert(false, 'SIGHASH_NONE not yet supported')
|
||||||
|
|
||||||
} else if (hashTypeModifier === SIGHASH_SINGLE) {
|
} else if (hashTypeModifier === Transaction.SIGHASH_SINGLE) {
|
||||||
assert(false, 'SIGHASH_SINGLE not yet supported')
|
assert(false, 'SIGHASH_SINGLE not yet supported')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashType & SIGHASH_ANYONECANPAY) {
|
if (hashType & Transaction.SIGHASH_ANYONECANPAY) {
|
||||||
assert(false, 'SIGHASH_ANYONECANPAY not yet supported')
|
assert(false, 'SIGHASH_ANYONECANPAY not yet supported')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ Transaction.prototype.sign = function(index, privKey, hashType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.signInput = function(index, prevOutScript, privKey, hashType) {
|
Transaction.prototype.signInput = function(index, prevOutScript, privKey, hashType) {
|
||||||
hashType = hashType || SIGHASH_ALL
|
hashType = hashType || Transaction.SIGHASH_ALL
|
||||||
|
|
||||||
var hash = this.hashForSignature(prevOutScript, index, hashType)
|
var hash = this.hashForSignature(prevOutScript, index, hashType)
|
||||||
var signature = privKey.sign(hash)
|
var signature = privKey.sign(hash)
|
||||||
|
|
|
@ -93,7 +93,7 @@ describe('Transaction', function() {
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
tx.addInput(prevTxHash, 0)
|
tx.addInput(prevTxHash, 0)
|
||||||
|
|
||||||
assert.equal(tx.ins[0].sequence, 0xffffffff)
|
assert.equal(tx.ins[0].sequence, Transaction.DEFAULT_SEQUENCE)
|
||||||
})
|
})
|
||||||
|
|
||||||
fixtures.valid.forEach(function(f) {
|
fixtures.valid.forEach(function(f) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue