Skip to content

Commit

Permalink
tx: do not track flags byte.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 7, 2017
1 parent 3bc47f5 commit 36523e2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 44 deletions.
5 changes: 0 additions & 5 deletions lib/primitives/mtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 6 additions & 19 deletions lib/primitives/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function TX(options) {
return new TX(options);

this.version = 1;
this.flag = 1;
this.inputs = [];
this.outputs = [];
this.locktime = 0;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -2296,11 +2285,9 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) {

assert(br.readU8() === 0, 'Non-zero marker.');

let flag = br.readU8();

assert(flag !== 0, 'Flag byte is zero.');
let flags = br.readU8();

this.flag = flag;
assert(flags !== 0, 'Flags byte is zero.');

const inCount = br.readVarint();

Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion scripts/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function createGenesisBlock(options) {

const tx = new TX({
version: 1,
flag: 1,
inputs: [{
prevout: {
hash: encoding.NULL_HASH,
Expand Down
5 changes: 1 addition & 4 deletions test/script-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ describe('Script', function() {
// Funding transaction.
const prev = new TX({
version: 1,
flag: 1,
inputs: [{
prevout: {
hash: encoding.NULL_HASH,
Expand All @@ -307,7 +306,6 @@ describe('Script', function() {
// Spending transaction.
const tx = new TX({
version: 1,
flag: 1,
inputs: [{
prevout: {
hash: prev.hash('hex'),
Expand All @@ -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) {
Expand Down
15 changes: 0 additions & 15 deletions test/tx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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: [],
Expand All @@ -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: [],
Expand All @@ -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: [],
Expand All @@ -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: [],
Expand All @@ -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],
Expand All @@ -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: [
{
Expand All @@ -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],
Expand All @@ -487,7 +479,6 @@ describe('TX', function() {

const tx = new TX({
version: 1,
flag: 1,
inputs: [input],
outputs: [{
script: [],
Expand Down Expand Up @@ -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: [],
Expand All @@ -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: [],
Expand All @@ -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: [],
Expand All @@ -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],
Expand All @@ -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: [
{
Expand All @@ -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],
Expand Down

0 comments on commit 36523e2

Please sign in to comment.