packets: more serialization nonsense.

This commit is contained in:
Christopher Jeffrey 2016-12-12 22:10:13 -08:00
parent fcc7f41438
commit 14c9a37cd9
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 985 additions and 328 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1321,7 +1321,7 @@ MTX.prototype.inspect = function inspect() {
*/
MTX.prototype.format = function format() {
return TX.prototype.inspect.call(this, this.view);
return TX.prototype.format.call(this, this.view);
};
/**

View File

@ -188,16 +188,37 @@ Bloom.prototype.getSize = function getSize() {
* @returns {Buffer}
*/
Bloom.prototype.toRaw = function toRaw() {
var size = this.getSize();
var bw = new StaticWriter(size);
Bloom.prototype.toWriter = function toWriter(bw) {
bw.writeVarBytes(this.filter);
bw.writeU32(this.n);
bw.writeU32(this.tweak);
bw.writeU8(this.update);
return bw;
};
return bw.render();
/**
* Serialize bloom filter.
* @returns {Buffer}
*/
Bloom.prototype.toRaw = function toRaw() {
var size = this.getSize();
return this.toWriter(new StaticWriter(size)).render();
};
/**
* Inject properties from buffer reader.
* @private
* @param {BufferReader} br
*/
Bloom.prototype.fromReader = function fromReader(br) {
this.filter = br.readVarBytes();
this.n = br.readU32();
this.tweak = br.readU32();
this.update = br.readU8();
assert(constants.filterFlagsByVal[this.update] != null, 'Bad filter flag.');
return this;
};
/**
@ -207,16 +228,17 @@ Bloom.prototype.toRaw = function toRaw() {
*/
Bloom.prototype.fromRaw = function fromRaw(data) {
var br = new BufferReader(data);
return this.fromReader(new BufferReader(data));
};
this.filter = br.readVarBytes();
this.n = br.readU32();
this.tweak = br.readU32();
this.update = br.readU8();
/**
* Instantiate bloom filter from buffer reader.
* @param {BufferReader} br
* @returns {Bloom}
*/
assert(constants.filterFlagsByVal[this.update] != null, 'Bad filter flag.');
return this;
Bloom.fromReader = function fromReader(br) {
return new Bloom().fromReader(br);
};
/**

View File

@ -2577,9 +2577,7 @@ Wallet.prototype.toRaw = function toRaw() {
Wallet.prototype.fromRaw = function fromRaw(data) {
var br = new BufferReader(data);
var network;
network = Network.fromMagic(br.readU32());
var network = Network.fromMagic(br.readU32());
this.wid = br.readU32();
this.id = br.readVarString('ascii');