Skip to content

Commit 6ec687d

Browse files
committed
rename scripts to script
1 parent 18e9cdc commit 6ec687d

File tree

13 files changed

+120
-123
lines changed

13 files changed

+120
-123
lines changed

src/address.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var base58check = require('bs58check')
1+
var bs58check = require('bs58check')
2+
var script = require('./script')
23
var networks = require('./networks')
3-
var scripts = require('./scripts')
44
var typeforce = require('typeforce')
55
var types = require('./types')
66

77
function fromBase58Check (address) {
8-
var payload = base58check.decode(address)
8+
var payload = bs58check.decode(address)
99
if (payload.length < 21) throw new TypeError(address + ' is too short')
1010
if (payload.length > 21) throw new TypeError(address + ' is too long')
1111

@@ -15,14 +15,14 @@ function fromBase58Check (address) {
1515
return { hash: hash, version: version }
1616
}
1717

18-
function fromOutputScript (script, network) {
18+
function fromOutputScript (scriptPubKey, network) {
1919
network = network || networks.bitcoin
2020

21-
var chunks = scripts.decompile(script)
22-
if (scripts.isPubKeyHashOutput(chunks)) return toBase58Check(chunks[2], network.pubKeyHash)
23-
if (scripts.isScriptHashOutput(chunks)) return toBase58Check(chunks[1], network.scriptHash)
21+
var chunks = script.decompile(scriptPubKey)
22+
if (script.isPubKeyHashOutput(chunks)) return toBase58Check(chunks[2], network.pubKeyHash)
23+
if (script.isScriptHashOutput(chunks)) return toBase58Check(chunks[1], network.scriptHash)
2424

25-
throw new Error(scripts.toASM(chunks) + ' has no matching Address')
25+
throw new Error(script.toASM(chunks) + ' has no matching Address')
2626
}
2727

2828
function toBase58Check (hash, version) {
@@ -32,21 +32,21 @@ function toBase58Check (hash, version) {
3232
payload.writeUInt8(version, 0)
3333
hash.copy(payload, 1)
3434

35-
return base58check.encode(payload)
35+
return bs58check.encode(payload)
3636
}
3737

3838
function toOutputScript (address, network) {
3939
network = network || networks.bitcoin
4040

41-
var payload = base58check.decode(address)
41+
var payload = bs58check.decode(address)
4242
if (payload.length < 21) throw new TypeError(address + ' is too short')
4343
if (payload.length > 21) throw new TypeError(address + ' is too long')
4444

4545
var version = payload.readUInt8(0)
4646
var hash = payload.slice(1)
4747

48-
if (version === network.pubKeyHash) return scripts.pubKeyHashOutput(hash)
49-
if (version === network.scriptHash) return scripts.scriptHashOutput(hash)
48+
if (version === network.pubKeyHash) return script.pubKeyHashOutput(hash)
49+
if (version === network.scriptHash) return script.scriptHashOutput(hash)
5050

5151
throw new Error(address + ' has no matching Script')
5252
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ module.exports = {
1212
message: require('./message'),
1313
networks: require('./networks'),
1414
opcodes: require('./opcodes'),
15-
scripts: require('./scripts')
15+
script: require('./script')
1616
}
File renamed without changes.

src/transaction.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var bufferutils = require('./bufferutils')
22
var crypto = require('./crypto')
33
var opcodes = require('./opcodes')
4-
var scripts = require('./scripts')
4+
var script = require('./script')
55
var typeforce = require('typeforce')
66
var types = require('./types')
77

@@ -99,7 +99,7 @@ Transaction.isCoinbaseHash = function (buffer) {
9999

100100
var EMPTY_SCRIPT = new Buffer(0)
101101

102-
Transaction.prototype.addInput = function (hash, index, sequence, script) {
102+
Transaction.prototype.addInput = function (hash, index, sequence, scriptSig) {
103103
typeforce(types.tuple(
104104
types.Hash256bit,
105105
types.UInt32,
@@ -111,13 +111,11 @@ Transaction.prototype.addInput = function (hash, index, sequence, script) {
111111
sequence = Transaction.DEFAULT_SEQUENCE
112112
}
113113

114-
script = script || EMPTY_SCRIPT
115-
116114
// Add the input and return the input's index
117115
return (this.ins.push({
118116
hash: hash,
119117
index: index,
120-
script: script,
118+
script: scriptSig || EMPTY_SCRIPT,
121119
sequence: sequence
122120
}) - 1)
123121
}
@@ -133,8 +131,8 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
133131
}
134132

135133
Transaction.prototype.byteLength = function () {
136-
function scriptSize (script) {
137-
var length = script.length
134+
function scriptSize (someScript) {
135+
var length = someScript.length
138136

139137
return bufferutils.varIntSize(length) + length
140138
}
@@ -193,7 +191,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
193191

194192
// in case concatenating two scripts ends up with two codeseparators,
195193
// or an extra one at the end, this prevents all those possible incompatibilities.
196-
var hashScript = scripts.compile(scripts.decompile(prevOutScript).filter(function (x) {
194+
var hashScript = script.compile(script.decompile(prevOutScript).filter(function (x) {
197195
return x !== opcodes.OP_CODESEPARATOR
198196
}))
199197
var i
@@ -320,10 +318,10 @@ Transaction.prototype.toHex = function () {
320318
return this.toBuffer().toString('hex')
321319
}
322320

323-
Transaction.prototype.setInputScript = function (index, script) {
321+
Transaction.prototype.setInputScript = function (index, scriptSig) {
324322
typeforce(types.tuple(types.Number, types.Buffer), arguments)
325323

326-
this.ins[index].script = script
324+
this.ins[index].script = scriptSig
327325
}
328326

329327
module.exports = Transaction

src/transaction_builder.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var bcrypto = require('./crypto')
33
var bufferutils = require('./bufferutils')
44
var networks = require('./networks')
55
var ops = require('./opcodes')
6-
var scripts = require('./scripts')
6+
var script = require('./script')
77

88
var ECPair = require('./ecpair')
99
var ECSignature = require('./ecsignature')
@@ -12,29 +12,29 @@ var Transaction = require('./transaction')
1212
function extractInput (txIn) {
1313
var redeemScript
1414
var scriptSig = txIn.script
15-
var scriptSigChunks = scripts.decompile(scriptSig)
15+
var scriptSigChunks = script.decompile(scriptSig)
1616

1717
var prevOutScript
18-
var prevOutType = scripts.classifyInput(scriptSig, true)
18+
var prevOutType = script.classifyInput(scriptSig, true)
1919
var scriptType
2020

2121
// Re-classify if scriptHash
2222
if (prevOutType === 'scripthash') {
2323
redeemScript = scriptSigChunks.slice(-1)[0]
24-
prevOutScript = scripts.scriptHashOutput(bcrypto.hash160(redeemScript))
24+
prevOutScript = script.scriptHashOutput(bcrypto.hash160(redeemScript))
2525

26-
scriptSig = scripts.compile(scriptSigChunks.slice(0, -1))
26+
scriptSig = script.compile(scriptSigChunks.slice(0, -1))
2727
scriptSigChunks = scriptSigChunks.slice(0, -1)
2828

29-
scriptType = scripts.classifyInput(scriptSig, true)
29+
scriptType = script.classifyInput(scriptSig, true)
3030
} else {
3131
scriptType = prevOutType
3232
}
3333

3434
// pre-empt redeemScript decompilation
3535
var redeemScriptChunks
3636
if (redeemScript) {
37-
redeemScriptChunks = scripts.decompile(redeemScript)
37+
redeemScriptChunks = script.decompile(redeemScript)
3838
}
3939

4040
// Extract hashType, pubKeys and signatures
@@ -46,7 +46,7 @@ function extractInput (txIn) {
4646
hashType = parsed.hashType
4747
pubKeys = scriptSigChunks.slice(1)
4848
signatures = [parsed.signature]
49-
prevOutScript = scripts.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
49+
prevOutScript = script.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
5050

5151
break
5252

@@ -147,8 +147,8 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
147147

148148
var input = {}
149149
if (prevOutScript) {
150-
var prevOutScriptChunks = scripts.decompile(prevOutScript)
151-
var prevOutType = scripts.classifyOutput(prevOutScriptChunks)
150+
var prevOutScriptChunks = script.decompile(prevOutScript)
151+
var prevOutType = script.classifyOutput(prevOutScriptChunks)
152152

153153
// if we can, extract pubKey information
154154
switch (prevOutType) {
@@ -240,7 +240,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
240240
switch (scriptType) {
241241
case 'pubkeyhash':
242242
var pkhSignature = input.signatures[0].toScriptSignature(input.hashType)
243-
scriptSig = scripts.pubKeyHashInput(pkhSignature, input.pubKeys[0])
243+
scriptSig = script.pubKeyHashInput(pkhSignature, input.pubKeys[0])
244244
break
245245

246246
case 'multisig':
@@ -262,12 +262,12 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
262262
}
263263

264264
var redeemScript = allowIncomplete ? undefined : input.redeemScript
265-
scriptSig = scripts.multisigInput(msSignatures, redeemScript)
265+
scriptSig = script.multisigInput(msSignatures, redeemScript)
266266
break
267267

268268
case 'pubkey':
269269
var pkSignature = input.signatures[0].toScriptSignature(input.hashType)
270-
scriptSig = scripts.pubKeyInput(pkSignature)
270+
scriptSig = script.pubKeyInput(pkSignature)
271271
break
272272
}
273273
}
@@ -276,7 +276,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
276276
if (scriptSig) {
277277
// wrap as scriptHash if necessary
278278
if (input.prevOutType === 'scripthash') {
279-
scriptSig = scripts.scriptHashInput(scriptSig, input.redeemScript)
279+
scriptSig = script.scriptHashInput(scriptSig, input.redeemScript)
280280
}
281281

282282
tx.setInputScript(index, scriptSig)
@@ -318,14 +318,14 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
318318
if (input.prevOutScript) {
319319
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')
320320

321-
var scriptHash = scripts.decompile(input.prevOutScript)[1]
321+
var scriptHash = script.decompile(input.prevOutScript)[1]
322322
if (!bufferutils.equal(scriptHash, bcrypto.hash160(redeemScript))) throw new Error('RedeemScript does not match ' + scriptHash.toString('hex'))
323323
}
324324

325-
var scriptType = scripts.classifyOutput(redeemScript)
325+
var scriptType = script.classifyOutput(redeemScript)
326326
if (!canSignTypes[scriptType]) throw new Error('RedeemScript not supported (' + scriptType + ')')
327327

328-
var redeemScriptChunks = scripts.decompile(redeemScript)
328+
var redeemScriptChunks = script.decompile(redeemScript)
329329
var pubKeys = []
330330
switch (scriptType) {
331331
case 'multisig':
@@ -347,7 +347,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
347347

348348
// if we don't have a prevOutScript, generate a P2SH script
349349
if (!input.prevOutScript) {
350-
input.prevOutScript = scripts.scriptHashOutput(bcrypto.hash160(redeemScript))
350+
input.prevOutScript = script.scriptHashOutput(bcrypto.hash160(redeemScript))
351351
input.prevOutType = 'scripthash'
352352
}
353353

@@ -365,7 +365,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
365365

366366
// we know nothin' Jon Snow, assume pubKeyHash
367367
} else {
368-
input.prevOutScript = scripts.pubKeyHashOutput(bcrypto.hash160(keyPair.getPublicKeyBuffer()))
368+
input.prevOutScript = script.pubKeyHashOutput(bcrypto.hash160(keyPair.getPublicKeyBuffer()))
369369
input.prevOutType = 'pubkeyhash'
370370
input.pubKeys = [kpPubKey]
371371
input.scriptType = input.prevOutType

test/address.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var assert = require('assert')
44
var baddress = require('../src/address')
55
var networks = require('../src/networks')
6-
var scripts = require('../src/scripts')
6+
var bscript = require('../src/script')
77
var fixtures = require('./fixtures/address.json')
88

99
describe('address', function () {
@@ -29,7 +29,7 @@ describe('address', function () {
2929
describe('fromOutputScript', function () {
3030
fixtures.valid.forEach(function (f) {
3131
it('parses ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
32-
var script = scripts.fromASM(f.script)
32+
var script = bscript.fromASM(f.script)
3333
var address = baddress.fromOutputScript(script, networks[f.network])
3434

3535
assert.strictEqual(address, f.base58check)
@@ -38,7 +38,7 @@ describe('address', function () {
3838

3939
fixtures.invalid.fromOutputScript.forEach(function (f) {
4040
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
41-
var script = scripts.fromASM(f.script)
41+
var script = bscript.fromASM(f.script)
4242

4343
assert.throws(function () {
4444
baddress.fromOutputScript(script)
@@ -64,7 +64,7 @@ describe('address', function () {
6464
it('exports ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
6565
var script = baddress.toOutputScript(f.base58check, network)
6666

67-
assert.strictEqual(scripts.toASM(script), f.script)
67+
assert.strictEqual(bscript.toASM(script), f.script)
6868
})
6969
})
7070

test/bitcoin.core.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe('Bitcoin-core', function () {
162162
})
163163
})
164164

165-
describe('scripts.fromASM', function () {
165+
describe('script.fromASM', function () {
166166
tx_valid.forEach(function (f) {
167167
// Objects that are only a single string are ignored
168168
if (f.length === 1) return
@@ -185,7 +185,7 @@ describe('Bitcoin-core', function () {
185185

186186
it('can parse ' + prevOutScriptPubKey, function () {
187187
// TODO: we can probably do better validation than this
188-
bitcoin.scripts.fromASM(prevOutScriptPubKey)
188+
bitcoin.script.fromASM(prevOutScriptPubKey)
189189
})
190190
})
191191
})
@@ -218,8 +218,8 @@ describe('Bitcoin-core', function () {
218218
assert.strictEqual(transaction.toHex(), txHex)
219219

220220
var script = new Buffer(scriptHex, 'hex')
221-
var scriptChunks = bitcoin.scripts.decompile(script)
222-
assert.strictEqual(bitcoin.scripts.compile(scriptChunks).toString('hex'), scriptHex)
221+
var scriptChunks = bitcoin.script.decompile(script)
222+
assert.strictEqual(bitcoin.script.compile(scriptChunks).toString('hex'), scriptHex)
223223

224224
var hash = transaction.hashForSignature(inIndex, script, hashType)
225225
assert.deepEqual(hash, expectedHash)
File renamed without changes.

test/integration/advanced.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('bitcoinjs-lib (advanced)', function () {
3636

3737
var tx = new bitcoin.TransactionBuilder(network)
3838
var data = new Buffer('bitcoinjs-lib')
39-
var dataScript = bitcoin.scripts.nullDataOutput(data)
39+
var dataScript = bitcoin.script.nullDataOutput(data)
4040

4141
var unspent = unspents.pop()
4242

@@ -55,7 +55,7 @@ describe('bitcoinjs-lib (advanced)', function () {
5555

5656
var actual = bitcoin.Transaction.fromHex(transaction.txHex)
5757
var dataScript2 = actual.outs[0].script
58-
var data2 = bitcoin.scripts.decompile(dataScript2)[1]
58+
var data2 = bitcoin.script.decompile(dataScript2)[1]
5959

6060
assert.deepEqual(dataScript, dataScript2)
6161
assert.deepEqual(data, data2)

test/integration/crypto.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ describe('bitcoinjs-lib (crypto)', function () {
132132
inputs.forEach(function (input) {
133133
var transaction = transactions[input.txId]
134134
var script = transaction.ins[input.vout].script
135-
var scriptChunks = bitcoin.scripts.decompile(script)
135+
var scriptChunks = bitcoin.script.decompile(script)
136136

137-
assert(bitcoin.scripts.isPubKeyHashInput(scriptChunks), 'Expected pubKeyHash script')
137+
assert(bitcoin.script.isPubKeyHashInput(scriptChunks), 'Expected pubKeyHash script')
138138

139139
var prevOutTxId = bitcoin.bufferutils.reverse(transaction.ins[input.vout].hash).toString('hex')
140140
var prevVout = transaction.ins[input.vout].index

0 commit comments

Comments
 (0)