diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index f81fd308..e3141fac 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -70,11 +70,6 @@ MTX.prototype.fromOptions = function fromOptions(options) { this.version = options.version; } - if (options.flag != null) { - assert(util.isU8(options.flag), 'Flag must be a uint8.'); - this.flag = options.flag; - } - if (options.inputs) { assert(Array.isArray(options.inputs), 'Inputs must be an array.'); for (const input of options.inputs) diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index d9de4ba1..fc3bce78 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -47,7 +47,6 @@ function TX(options) { return new TX(options); this.version = 1; - this.flag = 1; this.inputs = []; this.outputs = []; this.locktime = 0; @@ -84,11 +83,6 @@ TX.prototype.fromOptions = function fromOptions(options) { this.version = options.version; } - if (options.flag != null) { - assert(util.isU8(options.flag), 'Flag must be a uint8.'); - this.flag = options.flag; - } - if (options.inputs) { assert(Array.isArray(options.inputs), 'Inputs must be an array.'); for (const input of options.inputs) @@ -138,7 +132,6 @@ TX.prototype.clone = function clone() { TX.prototype.inject = function inject(tx) { this.version = tx.version; - this.flag = tx.flag; for (const input of tx.inputs) this.inputs.push(input.clone()); @@ -2095,7 +2088,6 @@ TX.prototype.format = function format(view, entry, index) { date: date, index: index, version: this.version, - flag: this.flag, inputs: this.inputs.map((input) => { const coin = view ? view.getOutputFor(input) : null; return input.format(coin); @@ -2160,7 +2152,6 @@ TX.prototype.getJSON = function getJSON(network, view, entry, index) { date: date, index: index, version: this.version, - flag: this.flag, inputs: this.inputs.map((input) => { const coin = view ? view.getCoinFor(input) : null; return input.getJSON(network, coin); @@ -2182,13 +2173,11 @@ TX.prototype.getJSON = function getJSON(network, view, entry, index) { TX.prototype.fromJSON = function fromJSON(json) { assert(json, 'TX data is required.'); assert(util.isU32(json.version), 'Version must be a uint32.'); - assert(util.isU8(json.flag), 'Flag must be a uint8.'); assert(Array.isArray(json.inputs), 'Inputs must be an array.'); assert(Array.isArray(json.outputs), 'Outputs must be an array.'); assert(util.isU32(json.locktime), 'Locktime must be a uint32.'); this.version = json.version; - this.flag = json.flag; for (const input of json.inputs) this.inputs.push(Input.fromJSON(input)); @@ -2296,11 +2285,9 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) { assert(br.readU8() === 0, 'Non-zero marker.'); - let flag = br.readU8(); + let flags = br.readU8(); - assert(flag !== 0, 'Flag byte is zero.'); - - this.flag = flag; + assert(flags !== 0, 'Flags byte is zero.'); const inCount = br.readVarint(); @@ -2315,8 +2302,8 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) { let witness = 0; let hasWitness = false; - if (flag & 1) { - flag ^= 1; + if (flags & 1) { + flags ^= 1; witness = br.offset; @@ -2329,7 +2316,7 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) { witness = (br.offset - witness) + 2; } - if (flag !== 0) + if (flags !== 0) throw new Error('Unknown witness flag.'); // We'll never be able to reserialize @@ -2422,7 +2409,7 @@ TX.prototype.writeWitness = function writeWitness(bw) { bw.writeU32(this.version); bw.writeU8(0); - bw.writeU8(this.flag); + bw.writeU8(1); bw.writeVarint(this.inputs.length); diff --git a/scripts/gen.js b/scripts/gen.js index 00e94d9e..2489d591 100644 --- a/scripts/gen.js +++ b/scripts/gen.js @@ -35,7 +35,6 @@ function createGenesisBlock(options) { const tx = new TX({ version: 1, - flag: 1, inputs: [{ prevout: { hash: encoding.NULL_HASH, diff --git a/test/script-test.js b/test/script-test.js index 8cb3a900..cabac13c 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -287,7 +287,6 @@ describe('Script', function() { // Funding transaction. const prev = new TX({ version: 1, - flag: 1, inputs: [{ prevout: { hash: encoding.NULL_HASH, @@ -307,7 +306,6 @@ describe('Script', function() { // Spending transaction. const tx = new TX({ version: 1, - flag: 1, inputs: [{ prevout: { hash: prev.hash('hex'), @@ -329,8 +327,7 @@ describe('Script', function() { tx.refresh(); } - let err; - let res; + let err, res; try { res = Script.verify(input, witness, output, tx, 0, amount, flags); } catch (e) { diff --git a/test/tx-test.js b/test/tx-test.js index 8d62a8e2..6f1735ea 100644 --- a/test/tx-test.js +++ b/test/tx-test.js @@ -340,7 +340,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY + 1); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -356,7 +355,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -372,7 +370,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -388,7 +385,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -404,7 +400,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY + 1); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -420,7 +415,6 @@ describe('TX', function() { const view = new CoinView(); const tx = new TX({ version: 1, - flag: 1, inputs: [ createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], @@ -440,7 +434,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [ { @@ -466,7 +459,6 @@ describe('TX', function() { const view = new CoinView(); const tx = new TX({ version: 1, - flag: 1, inputs: [ createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], @@ -487,7 +479,6 @@ describe('TX', function() { const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -515,7 +506,6 @@ describe('TX', function() { const [input, view] = createInput(MAX_SAFE_INTEGER); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -531,7 +521,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -547,7 +536,6 @@ describe('TX', function() { const [input, view] = createInput(MAX_SAFE_INTEGER); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [{ script: [], @@ -564,7 +552,6 @@ describe('TX', function() { const view = new CoinView(); const tx = new TX({ version: 1, - flag: 1, inputs: [ createInput(MAX, view)[0], createInput(MAX, view)[0], @@ -584,7 +571,6 @@ describe('TX', function() { const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, - flag: 1, inputs: [input], outputs: [ { @@ -610,7 +596,6 @@ describe('TX', function() { const view = new CoinView(); const tx = new TX({ version: 1, - flag: 1, inputs: [ createInput(MAX, view)[0], createInput(MAX, view)[0],