coinview: remove old serialization methods.
This commit is contained in:
parent
15d0b88308
commit
3f3516ca18
@ -379,7 +379,7 @@ CoinView.prototype.toArray = function toArray() {
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
CoinView.prototype.getFastSize = function getFastSize(tx) {
|
||||
CoinView.prototype.getSize = function getSize(tx) {
|
||||
let size = 0;
|
||||
|
||||
size += tx.inputs.length;
|
||||
@ -403,7 +403,7 @@ CoinView.prototype.getFastSize = function getFastSize(tx) {
|
||||
* @param {TX} tx
|
||||
*/
|
||||
|
||||
CoinView.prototype.toFast = function toFast(bw, tx) {
|
||||
CoinView.prototype.toWriter = function toWriter(bw, tx) {
|
||||
for (let input of tx.inputs) {
|
||||
let prevout = input.prevout;
|
||||
let coins = this.get(prevout.hash);
|
||||
@ -436,7 +436,7 @@ CoinView.prototype.toFast = function toFast(bw, tx) {
|
||||
* @param {TX} tx
|
||||
*/
|
||||
|
||||
CoinView.prototype.fromFast = function fromFast(br, tx) {
|
||||
CoinView.prototype.fromReader = function fromReader(br, tx) {
|
||||
for (let input of tx.inputs) {
|
||||
let prevout = input.prevout;
|
||||
let coins, entry;
|
||||
@ -460,119 +460,6 @@ CoinView.prototype.fromFast = function fromFast(br, tx) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Read serialized view data from a buffer
|
||||
* reader as it pertains to a transaction.
|
||||
* @param {BufferReader} br
|
||||
* @param {TX} tx
|
||||
* @returns {CoinView}
|
||||
*/
|
||||
|
||||
CoinView.fromFast = function fromFast(br, tx) {
|
||||
return new CoinView().fromFast(br, tx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Write coin data to buffer writer
|
||||
* as it pertains to a transaction.
|
||||
* @param {BufferWriter} bw
|
||||
* @param {TX} tx
|
||||
*/
|
||||
|
||||
CoinView.prototype.toWriter = function toWriter(bw, tx) {
|
||||
let map = {};
|
||||
|
||||
for (let input of tx.inputs) {
|
||||
let prevout = input.prevout;
|
||||
let coins = this.get(prevout.hash);
|
||||
let entry;
|
||||
|
||||
if (!coins) {
|
||||
bw.writeU8(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
entry = coins.get(prevout.index);
|
||||
|
||||
if (!entry) {
|
||||
bw.writeU8(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
bw.writeU8(1);
|
||||
|
||||
if (!map[prevout.hash]) {
|
||||
let height = coins.height;
|
||||
if (height === -1)
|
||||
height = 0;
|
||||
bw.writeVarint(height * 2 + (coins.coinbase ? 1 : 0));
|
||||
bw.writeVarint(coins.version);
|
||||
map[prevout.hash] = true;
|
||||
}
|
||||
|
||||
entry.toWriter(bw);
|
||||
}
|
||||
|
||||
return bw;
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize coin data to as it
|
||||
* pertains to a transaction.
|
||||
* @param {TX} tx
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
CoinView.prototype.toRaw = function toRaw(tx) {
|
||||
return this.toWriter(new BufferWriter()).render();
|
||||
};
|
||||
|
||||
/**
|
||||
* Read serialized view data from a buffer
|
||||
* reader as it pertains to a transaction.
|
||||
* @private
|
||||
* @param {BufferReader} br
|
||||
* @param {TX} tx
|
||||
*/
|
||||
|
||||
CoinView.prototype.fromReader = function fromReader(br, tx) {
|
||||
|
||||
for (let input of tx.inputs) {
|
||||
let prevout = input.prevout;
|
||||
let coins, entry;
|
||||
|
||||
if (br.readU8() === 0)
|
||||
continue;
|
||||
|
||||
coins = this.get(prevout.hash);
|
||||
|
||||
if (!coins) {
|
||||
let height;
|
||||
|
||||
coins = new Coins();
|
||||
coins.hash = prevout.hash;
|
||||
|
||||
height = br.readVarint();
|
||||
coins.coinbase = (height & 1) !== 0;
|
||||
|
||||
height = height / 2 | 0;
|
||||
|
||||
if (height === 0)
|
||||
height = -1;
|
||||
|
||||
coins.height = height;
|
||||
coins.version = br.readVarint();
|
||||
|
||||
this.add(coins);
|
||||
}
|
||||
|
||||
entry = CoinEntry.fromReader(br);
|
||||
coins.add(prevout.index, entry);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Read serialized view data from a buffer
|
||||
* reader as it pertains to a transaction.
|
||||
@ -585,18 +472,6 @@ CoinView.fromReader = function fromReader(br, tx) {
|
||||
return new CoinView().fromReader(br, tx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Read serialized view data from a buffer
|
||||
* as it pertains to a transaction.
|
||||
* @param {Buffer} data
|
||||
* @param {TX} tx
|
||||
* @returns {CoinView}
|
||||
*/
|
||||
|
||||
CoinView.fromRaw = function fromRaw(data, tx) {
|
||||
return new CoinView().fromReader(new BufferReader(data), tx);
|
||||
};
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
@ -110,12 +110,10 @@ CompactBlock.fromOptions = function fromOptions(options) {
|
||||
|
||||
/**
|
||||
* Verify the block.
|
||||
* @param {Object?} ret - Return object, may be
|
||||
* set with properties `reason` and `score`.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
CompactBlock.prototype.verifyBody = function verifyBody(ret) {
|
||||
CompactBlock.prototype.verifyBody = function verifyBody() {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@ -238,12 +238,10 @@ AbstractBlock.prototype.verifyPOW = function verifyPOW() {
|
||||
|
||||
/**
|
||||
* Verify the block.
|
||||
* @param {Object?} ret - Return object, may be
|
||||
* set with properties `reason` and `score`.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
AbstractBlock.prototype.verifyBody = function verifyBody(ret) {
|
||||
AbstractBlock.prototype.verifyBody = function verifyBody() {
|
||||
throw new Error('Abstract method.');
|
||||
};
|
||||
|
||||
|
||||
@ -74,12 +74,10 @@ MemBlock.prototype.getSize = function getSize() {
|
||||
|
||||
/**
|
||||
* Verify the block.
|
||||
* @param {Object?} ret - Return object, may be
|
||||
* set with properties `reason` and `score`.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
MemBlock.prototype.verifyBody = function verifyBody(ret) {
|
||||
MemBlock.prototype.verifyBody = function verifyBody() {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@ -212,12 +212,12 @@ util.inherits(VerifyPacket, Packet);
|
||||
VerifyPacket.prototype.cmd = packetTypes.VERIFY;
|
||||
|
||||
VerifyPacket.prototype.getSize = function getSize() {
|
||||
return this.tx.getSize() + this.view.getFastSize(this.tx) + 4;
|
||||
return this.tx.getSize() + this.view.getSize(this.tx) + 4;
|
||||
};
|
||||
|
||||
VerifyPacket.prototype.toWriter = function toWriter(bw) {
|
||||
this.tx.toWriter(bw);
|
||||
this.view.toFast(bw, this.tx);
|
||||
this.view.toWriter(bw, this.tx);
|
||||
bw.write32(this.flags != null ? this.flags : -1);
|
||||
};
|
||||
|
||||
@ -226,7 +226,7 @@ VerifyPacket.fromRaw = function fromRaw(TX, CoinView, data) {
|
||||
let packet = new VerifyPacket();
|
||||
|
||||
packet.tx = TX.fromReader(br);
|
||||
packet.view = CoinView.fromFast(br, packet.tx);
|
||||
packet.view = CoinView.fromReader(br, packet.tx);
|
||||
|
||||
packet.flags = br.read32();
|
||||
|
||||
@ -286,7 +286,7 @@ SignPacket.prototype.getSize = function getSize() {
|
||||
let ring;
|
||||
|
||||
size += this.tx.getSize();
|
||||
size += this.tx.view.getFastSize(this.tx);
|
||||
size += this.tx.view.getSize(this.tx);
|
||||
size += encoding.sizeVarint(this.rings.length);
|
||||
|
||||
for (ring of this.rings)
|
||||
@ -301,7 +301,7 @@ SignPacket.prototype.toWriter = function toWriter(bw) {
|
||||
let ring;
|
||||
|
||||
this.tx.toWriter(bw);
|
||||
this.tx.view.toFast(bw, this.tx);
|
||||
this.tx.view.toWriter(bw, this.tx);
|
||||
|
||||
bw.writeVarint(this.rings.length);
|
||||
|
||||
@ -317,7 +317,7 @@ SignPacket.fromRaw = function fromRaw(MTX, KeyRing, data) {
|
||||
let count;
|
||||
|
||||
packet.tx = MTX.fromReader(br);
|
||||
packet.tx.view.fromFast(br, packet.tx);
|
||||
packet.tx.view.fromReader(br, packet.tx);
|
||||
|
||||
count = br.readVarint();
|
||||
|
||||
|
||||
@ -111,11 +111,11 @@ describe('Coins', function() {
|
||||
view.addTX(tx, 1);
|
||||
}
|
||||
|
||||
size = view.getFastSize(tx1);
|
||||
size = view.getSize(tx1);
|
||||
bw = new StaticWriter(size);
|
||||
raw = view.toFast(bw, tx1).render();
|
||||
raw = view.toWriter(bw, tx1).render();
|
||||
br = new BufferReader(raw);
|
||||
res = CoinView.fromFast(br, tx1);
|
||||
res = CoinView.fromReader(br, tx1);
|
||||
|
||||
prev = tx1.inputs[0].prevout;
|
||||
coins = res.get(prev.hash);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user