tx: do not track flags byte.
This commit is contained in:
parent
3bc47f5a3c
commit
36523e2f56
@ -70,11 +70,6 @@ MTX.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.version = options.version;
|
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) {
|
if (options.inputs) {
|
||||||
assert(Array.isArray(options.inputs), 'Inputs must be an array.');
|
assert(Array.isArray(options.inputs), 'Inputs must be an array.');
|
||||||
for (const input of options.inputs)
|
for (const input of options.inputs)
|
||||||
|
|||||||
@ -47,7 +47,6 @@ function TX(options) {
|
|||||||
return new TX(options);
|
return new TX(options);
|
||||||
|
|
||||||
this.version = 1;
|
this.version = 1;
|
||||||
this.flag = 1;
|
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
this.outputs = [];
|
this.outputs = [];
|
||||||
this.locktime = 0;
|
this.locktime = 0;
|
||||||
@ -84,11 +83,6 @@ TX.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.version = options.version;
|
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) {
|
if (options.inputs) {
|
||||||
assert(Array.isArray(options.inputs), 'Inputs must be an array.');
|
assert(Array.isArray(options.inputs), 'Inputs must be an array.');
|
||||||
for (const input of options.inputs)
|
for (const input of options.inputs)
|
||||||
@ -138,7 +132,6 @@ TX.prototype.clone = function clone() {
|
|||||||
|
|
||||||
TX.prototype.inject = function inject(tx) {
|
TX.prototype.inject = function inject(tx) {
|
||||||
this.version = tx.version;
|
this.version = tx.version;
|
||||||
this.flag = tx.flag;
|
|
||||||
|
|
||||||
for (const input of tx.inputs)
|
for (const input of tx.inputs)
|
||||||
this.inputs.push(input.clone());
|
this.inputs.push(input.clone());
|
||||||
@ -2095,7 +2088,6 @@ TX.prototype.format = function format(view, entry, index) {
|
|||||||
date: date,
|
date: date,
|
||||||
index: index,
|
index: index,
|
||||||
version: this.version,
|
version: this.version,
|
||||||
flag: this.flag,
|
|
||||||
inputs: this.inputs.map((input) => {
|
inputs: this.inputs.map((input) => {
|
||||||
const coin = view ? view.getOutputFor(input) : null;
|
const coin = view ? view.getOutputFor(input) : null;
|
||||||
return input.format(coin);
|
return input.format(coin);
|
||||||
@ -2160,7 +2152,6 @@ TX.prototype.getJSON = function getJSON(network, view, entry, index) {
|
|||||||
date: date,
|
date: date,
|
||||||
index: index,
|
index: index,
|
||||||
version: this.version,
|
version: this.version,
|
||||||
flag: this.flag,
|
|
||||||
inputs: this.inputs.map((input) => {
|
inputs: this.inputs.map((input) => {
|
||||||
const coin = view ? view.getCoinFor(input) : null;
|
const coin = view ? view.getCoinFor(input) : null;
|
||||||
return input.getJSON(network, coin);
|
return input.getJSON(network, coin);
|
||||||
@ -2182,13 +2173,11 @@ TX.prototype.getJSON = function getJSON(network, view, entry, index) {
|
|||||||
TX.prototype.fromJSON = function fromJSON(json) {
|
TX.prototype.fromJSON = function fromJSON(json) {
|
||||||
assert(json, 'TX data is required.');
|
assert(json, 'TX data is required.');
|
||||||
assert(util.isU32(json.version), 'Version must be a uint32.');
|
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.inputs), 'Inputs must be an array.');
|
||||||
assert(Array.isArray(json.outputs), 'Outputs must be an array.');
|
assert(Array.isArray(json.outputs), 'Outputs must be an array.');
|
||||||
assert(util.isU32(json.locktime), 'Locktime must be a uint32.');
|
assert(util.isU32(json.locktime), 'Locktime must be a uint32.');
|
||||||
|
|
||||||
this.version = json.version;
|
this.version = json.version;
|
||||||
this.flag = json.flag;
|
|
||||||
|
|
||||||
for (const input of json.inputs)
|
for (const input of json.inputs)
|
||||||
this.inputs.push(Input.fromJSON(input));
|
this.inputs.push(Input.fromJSON(input));
|
||||||
@ -2296,11 +2285,9 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) {
|
|||||||
|
|
||||||
assert(br.readU8() === 0, 'Non-zero marker.');
|
assert(br.readU8() === 0, 'Non-zero marker.');
|
||||||
|
|
||||||
let flag = br.readU8();
|
let flags = br.readU8();
|
||||||
|
|
||||||
assert(flag !== 0, 'Flag byte is zero.');
|
assert(flags !== 0, 'Flags byte is zero.');
|
||||||
|
|
||||||
this.flag = flag;
|
|
||||||
|
|
||||||
const inCount = br.readVarint();
|
const inCount = br.readVarint();
|
||||||
|
|
||||||
@ -2315,8 +2302,8 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) {
|
|||||||
let witness = 0;
|
let witness = 0;
|
||||||
let hasWitness = false;
|
let hasWitness = false;
|
||||||
|
|
||||||
if (flag & 1) {
|
if (flags & 1) {
|
||||||
flag ^= 1;
|
flags ^= 1;
|
||||||
|
|
||||||
witness = br.offset;
|
witness = br.offset;
|
||||||
|
|
||||||
@ -2329,7 +2316,7 @@ TX.prototype.fromWitnessReader = function fromWitnessReader(br) {
|
|||||||
witness = (br.offset - witness) + 2;
|
witness = (br.offset - witness) + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag !== 0)
|
if (flags !== 0)
|
||||||
throw new Error('Unknown witness flag.');
|
throw new Error('Unknown witness flag.');
|
||||||
|
|
||||||
// We'll never be able to reserialize
|
// We'll never be able to reserialize
|
||||||
@ -2422,7 +2409,7 @@ TX.prototype.writeWitness = function writeWitness(bw) {
|
|||||||
|
|
||||||
bw.writeU32(this.version);
|
bw.writeU32(this.version);
|
||||||
bw.writeU8(0);
|
bw.writeU8(0);
|
||||||
bw.writeU8(this.flag);
|
bw.writeU8(1);
|
||||||
|
|
||||||
bw.writeVarint(this.inputs.length);
|
bw.writeVarint(this.inputs.length);
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,6 @@ function createGenesisBlock(options) {
|
|||||||
|
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [{
|
inputs: [{
|
||||||
prevout: {
|
prevout: {
|
||||||
hash: encoding.NULL_HASH,
|
hash: encoding.NULL_HASH,
|
||||||
|
|||||||
@ -287,7 +287,6 @@ describe('Script', function() {
|
|||||||
// Funding transaction.
|
// Funding transaction.
|
||||||
const prev = new TX({
|
const prev = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [{
|
inputs: [{
|
||||||
prevout: {
|
prevout: {
|
||||||
hash: encoding.NULL_HASH,
|
hash: encoding.NULL_HASH,
|
||||||
@ -307,7 +306,6 @@ describe('Script', function() {
|
|||||||
// Spending transaction.
|
// Spending transaction.
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [{
|
inputs: [{
|
||||||
prevout: {
|
prevout: {
|
||||||
hash: prev.hash('hex'),
|
hash: prev.hash('hex'),
|
||||||
@ -329,8 +327,7 @@ describe('Script', function() {
|
|||||||
tx.refresh();
|
tx.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
let err;
|
let err, res;
|
||||||
let res;
|
|
||||||
try {
|
try {
|
||||||
res = Script.verify(input, witness, output, tx, 0, amount, flags);
|
res = Script.verify(input, witness, output, tx, 0, amount, flags);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -340,7 +340,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY + 1);
|
const [input, view] = createInput(consensus.MAX_MONEY + 1);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -356,7 +355,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY);
|
const [input, view] = createInput(consensus.MAX_MONEY);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -372,7 +370,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY);
|
const [input, view] = createInput(consensus.MAX_MONEY);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -388,7 +385,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY);
|
const [input, view] = createInput(consensus.MAX_MONEY);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -404,7 +400,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY + 1);
|
const [input, view] = createInput(consensus.MAX_MONEY + 1);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -420,7 +415,6 @@ describe('TX', function() {
|
|||||||
const view = new CoinView();
|
const view = new CoinView();
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [
|
inputs: [
|
||||||
createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0],
|
createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0],
|
||||||
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 [input, view] = createInput(consensus.MAX_MONEY);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
@ -466,7 +459,6 @@ describe('TX', function() {
|
|||||||
const view = new CoinView();
|
const view = new CoinView();
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [
|
inputs: [
|
||||||
createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0],
|
createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0],
|
||||||
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({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -515,7 +506,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(MAX_SAFE_INTEGER);
|
const [input, view] = createInput(MAX_SAFE_INTEGER);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -531,7 +521,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY);
|
const [input, view] = createInput(consensus.MAX_MONEY);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -547,7 +536,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(MAX_SAFE_INTEGER);
|
const [input, view] = createInput(MAX_SAFE_INTEGER);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [{
|
outputs: [{
|
||||||
script: [],
|
script: [],
|
||||||
@ -564,7 +552,6 @@ describe('TX', function() {
|
|||||||
const view = new CoinView();
|
const view = new CoinView();
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [
|
inputs: [
|
||||||
createInput(MAX, view)[0],
|
createInput(MAX, view)[0],
|
||||||
createInput(MAX, view)[0],
|
createInput(MAX, view)[0],
|
||||||
@ -584,7 +571,6 @@ describe('TX', function() {
|
|||||||
const [input, view] = createInput(consensus.MAX_MONEY);
|
const [input, view] = createInput(consensus.MAX_MONEY);
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [input],
|
inputs: [input],
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
@ -610,7 +596,6 @@ describe('TX', function() {
|
|||||||
const view = new CoinView();
|
const view = new CoinView();
|
||||||
const tx = new TX({
|
const tx = new TX({
|
||||||
version: 1,
|
version: 1,
|
||||||
flag: 1,
|
|
||||||
inputs: [
|
inputs: [
|
||||||
createInput(MAX, view)[0],
|
createInput(MAX, view)[0],
|
||||||
createInput(MAX, view)[0],
|
createInput(MAX, view)[0],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user