workers: drop all static methods for packets.
This commit is contained in:
parent
d871751bba
commit
bc25bdb016
@ -88,14 +88,18 @@ EnvPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
EnvPacket.prototype.toWriter = function toWriter(bw) {
|
EnvPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarString(this.json, 'utf8');
|
bw.writeVarString(this.json, 'utf8');
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
EnvPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.json = br.readVarString('utf8');
|
||||||
|
this.env = JSON.parse(this.json);
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
EnvPacket.fromRaw = function fromRaw(data) {
|
EnvPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new EnvPacket().fromRaw(data);
|
||||||
const packet = new EnvPacket();
|
|
||||||
packet.json = br.readVarString('utf8');
|
|
||||||
packet.env = JSON.parse(packet.json);
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,14 +123,18 @@ EventPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
EventPacket.prototype.toWriter = function toWriter(bw) {
|
EventPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarString(this.json, 'utf8');
|
bw.writeVarString(this.json, 'utf8');
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
EventPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.json = br.readVarString('utf8');
|
||||||
|
this.items = JSON.parse(this.json);
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
EventPacket.fromRaw = function fromRaw(data) {
|
EventPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new EventPacket().fromRaw(data);
|
||||||
const packet = new EventPacket();
|
|
||||||
packet.json = br.readVarString('utf8');
|
|
||||||
packet.items = JSON.parse(packet.json);
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,13 +157,17 @@ LogPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
LogPacket.prototype.toWriter = function toWriter(bw) {
|
LogPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarString(this.text, 'utf8');
|
bw.writeVarString(this.text, 'utf8');
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
LogPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.text = br.readVarString('utf8');
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
LogPacket.fromRaw = function fromRaw(data) {
|
LogPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new LogPacket().fromRaw(data);
|
||||||
const packet = new LogPacket();
|
|
||||||
packet.text = br.readVarString('utf8');
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,20 +185,22 @@ Object.setPrototypeOf(ErrorPacket.prototype, Packet.prototype);
|
|||||||
ErrorPacket.prototype.cmd = packetTypes.ERROR;
|
ErrorPacket.prototype.cmd = packetTypes.ERROR;
|
||||||
|
|
||||||
ErrorPacket.prototype.getSize = function getSize() {
|
ErrorPacket.prototype.getSize = function getSize() {
|
||||||
|
const err = this.error;
|
||||||
|
|
||||||
let size = 0;
|
let size = 0;
|
||||||
|
|
||||||
size += encoding.sizeVarString(String(this.error.message), 'utf8');
|
size += encoding.sizeVarString(stringify(err.message), 'utf8');
|
||||||
size += encoding.sizeVarString(String(this.error.stack), 'utf8');
|
size += encoding.sizeVarString(stringify(err.stack), 'utf8');
|
||||||
size += encoding.sizeVarString(this.error.type || '', 'utf8');
|
size += encoding.sizeVarString(stringify(err.type), 'utf8');
|
||||||
|
|
||||||
switch (typeof this.error.code) {
|
switch (typeof err.code) {
|
||||||
case 'number':
|
case 'number':
|
||||||
size += 1;
|
size += 1;
|
||||||
size += 4;
|
size += 4;
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
size += 1;
|
size += 1;
|
||||||
size += encoding.sizeVarString(this.error.code, 'utf8');
|
size += encoding.sizeVarString(err.code, 'utf8');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
size += 1;
|
size += 1;
|
||||||
@ -197,46 +211,54 @@ ErrorPacket.prototype.getSize = function getSize() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ErrorPacket.prototype.toWriter = function toWriter(bw) {
|
ErrorPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarString(String(this.error.message), 'utf8');
|
const err = this.error;
|
||||||
bw.writeVarString(String(this.error.stack), 'utf8');
|
|
||||||
bw.writeVarString(this.error.type || '', 'utf8');
|
|
||||||
|
|
||||||
switch (typeof this.error.code) {
|
bw.writeVarString(stringify(err.message), 'utf8');
|
||||||
|
bw.writeVarString(stringify(err.stack), 'utf8');
|
||||||
|
bw.writeVarString(stringify(err.type), 'utf8');
|
||||||
|
|
||||||
|
switch (typeof err.code) {
|
||||||
case 'number':
|
case 'number':
|
||||||
bw.writeU8(2);
|
bw.writeU8(2);
|
||||||
bw.writeI32(this.error.code);
|
bw.writeI32(err.code);
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
bw.writeU8(1);
|
bw.writeU8(1);
|
||||||
bw.writeVarString(this.error.code, 'utf8');
|
bw.writeVarString(err.code, 'utf8');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bw.writeU8(0);
|
bw.writeU8(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorPacket.fromRaw = function fromRaw(data) {
|
ErrorPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
const br = new BufferReader(data, true);
|
||||||
const packet = new ErrorPacket();
|
const err = this.error;
|
||||||
|
|
||||||
packet.error.message = br.readVarString('utf8');
|
err.message = br.readVarString('utf8');
|
||||||
packet.error.stack = br.readVarString('utf8');
|
err.stack = br.readVarString('utf8');
|
||||||
packet.error.type = br.readVarString('utf8');
|
err.type = br.readVarString('utf8');
|
||||||
|
|
||||||
switch (br.readU8()) {
|
switch (br.readU8()) {
|
||||||
case 2:
|
case 2:
|
||||||
packet.error.code = br.readI32();
|
err.code = br.readI32();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
packet.error.code = br.readVarString('utf8');
|
err.code = br.readVarString('utf8');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
packet.error.code = null;
|
err.code = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return packet;
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
ErrorPacket.fromRaw = function fromRaw(data) {
|
||||||
|
return new ErrorPacket().fromRaw(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -253,10 +275,7 @@ Object.setPrototypeOf(ErrorResultPacket.prototype, ErrorPacket.prototype);
|
|||||||
ErrorResultPacket.prototype.cmd = packetTypes.ERRORRESULT;
|
ErrorResultPacket.prototype.cmd = packetTypes.ERRORRESULT;
|
||||||
|
|
||||||
ErrorResultPacket.fromRaw = function fromRaw(data) {
|
ErrorResultPacket.fromRaw = function fromRaw(data) {
|
||||||
const packet = new ErrorResultPacket();
|
return new ErrorResultPacket().fromRaw(data);
|
||||||
const p = ErrorPacket.fromRaw(data);
|
|
||||||
packet.error = p.error;
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -283,20 +302,24 @@ CheckPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
this.tx.toWriter(bw);
|
this.tx.toWriter(bw);
|
||||||
this.view.toWriter(bw, this.tx);
|
this.view.toWriter(bw, this.tx);
|
||||||
bw.writeI32(this.flags != null ? this.flags : -1);
|
bw.writeI32(this.flags != null ? this.flags : -1);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
CheckPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
|
||||||
|
this.tx = TX.fromReader(br);
|
||||||
|
this.view = CoinView.fromReader(br, this.tx);
|
||||||
|
this.flags = br.readI32();
|
||||||
|
|
||||||
|
if (this.flags === -1)
|
||||||
|
this.flags = null;
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckPacket.fromRaw = function fromRaw(data) {
|
CheckPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new CheckPacket().fromRaw(data);
|
||||||
const packet = new CheckPacket();
|
|
||||||
|
|
||||||
packet.tx = TX.fromReader(br);
|
|
||||||
packet.view = CoinView.fromReader(br, packet.tx);
|
|
||||||
packet.flags = br.readI32();
|
|
||||||
|
|
||||||
if (packet.flags === -1)
|
|
||||||
packet.flags = null;
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,6 +338,7 @@ CheckResultPacket.prototype.cmd = packetTypes.CHECKRESULT;
|
|||||||
|
|
||||||
CheckResultPacket.prototype.getSize = function getSize() {
|
CheckResultPacket.prototype.getSize = function getSize() {
|
||||||
const err = this.error;
|
const err = this.error;
|
||||||
|
|
||||||
let size = 0;
|
let size = 0;
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@ -323,9 +347,9 @@ CheckResultPacket.prototype.getSize = function getSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size += 1;
|
size += 1;
|
||||||
size += encoding.sizeVarString(err.code, 'utf8');
|
size += encoding.sizeVarString(stringify(err.message), 'utf8');
|
||||||
size += encoding.sizeVarString(err.message, 'utf8');
|
size += encoding.sizeVarString(stringify(err.stack), 'utf8');
|
||||||
size += encoding.sizeVarString(String(err.stack), 'utf8');
|
size += encoding.sizeVarString(stringify(err.code), 'utf8');
|
||||||
size += 1;
|
size += 1;
|
||||||
size += 4;
|
size += 4;
|
||||||
|
|
||||||
@ -341,24 +365,26 @@ CheckResultPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bw.writeU8(1);
|
bw.writeU8(1);
|
||||||
bw.writeVarString(err.code, 'utf8');
|
bw.writeVarString(stringify(err.message), 'utf8');
|
||||||
bw.writeVarString(err.message, 'utf8');
|
bw.writeVarString(stringify(err.stack), 'utf8');
|
||||||
bw.writeVarString(String(err.stack), 'utf8');
|
bw.writeVarString(stringify(err.code), 'utf8');
|
||||||
bw.writeU8(err.op === -1 ? 0xff : err.op);
|
bw.writeU8(err.op === -1 ? 0xff : err.op);
|
||||||
bw.writeU32(err.ip === -1 ? 0xffffffff : err.ip);
|
bw.writeU32(err.ip === -1 ? 0xffffffff : err.ip);
|
||||||
|
|
||||||
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckResultPacket.fromRaw = function fromRaw(data) {
|
CheckResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
const br = new BufferReader(data, true);
|
||||||
const packet = new CheckResultPacket();
|
|
||||||
|
|
||||||
if (br.readU8() === 0)
|
if (br.readU8() === 0)
|
||||||
return packet;
|
return this;
|
||||||
|
|
||||||
const err = new ScriptError('');
|
const err = new ScriptError('');
|
||||||
err.code = br.readVarString('utf8');
|
|
||||||
err.message = br.readVarString('utf8');
|
err.message = br.readVarString('utf8');
|
||||||
err.stack = br.readVarString('utf8');
|
err.stack = br.readVarString('utf8');
|
||||||
|
err.code = br.readVarString('utf8');
|
||||||
err.op = br.readU8();
|
err.op = br.readU8();
|
||||||
err.ip = br.readU32();
|
err.ip = br.readU32();
|
||||||
|
|
||||||
@ -368,9 +394,13 @@ CheckResultPacket.fromRaw = function fromRaw(data) {
|
|||||||
if (err.ip === 0xffffffff)
|
if (err.ip === 0xffffffff)
|
||||||
err.ip = -1;
|
err.ip = -1;
|
||||||
|
|
||||||
packet.error = err;
|
this.error = err;
|
||||||
|
|
||||||
return packet;
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
CheckResultPacket.fromRaw = function fromRaw(data) {
|
||||||
|
return new CheckResultPacket().fromRaw(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -414,25 +444,30 @@ SignPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
ring.toWriter(bw);
|
ring.toWriter(bw);
|
||||||
|
|
||||||
bw.writeU8(this.type);
|
bw.writeU8(this.type);
|
||||||
|
|
||||||
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
SignPacket.fromRaw = function fromRaw(data) {
|
SignPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
const br = new BufferReader(data, true);
|
||||||
const packet = new SignPacket();
|
|
||||||
|
|
||||||
packet.tx = MTX.fromReader(br);
|
this.tx = MTX.fromReader(br);
|
||||||
packet.tx.view.fromReader(br, packet.tx);
|
this.tx.view.fromReader(br, this.tx);
|
||||||
|
|
||||||
const count = br.readVarint();
|
const count = br.readVarint();
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const ring = KeyRing.fromReader(br);
|
const ring = KeyRing.fromReader(br);
|
||||||
packet.rings.push(ring);
|
this.rings.push(ring);
|
||||||
}
|
}
|
||||||
|
|
||||||
packet.type = br.readU8();
|
this.type = br.readU8();
|
||||||
|
|
||||||
return packet;
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
SignPacket.fromRaw = function fromRaw(data) {
|
||||||
|
return new SignPacket().fromRaw(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -451,15 +486,19 @@ Object.setPrototypeOf(SignResultPacket.prototype, Packet.prototype);
|
|||||||
|
|
||||||
SignResultPacket.prototype.cmd = packetTypes.SIGNRESULT;
|
SignResultPacket.prototype.cmd = packetTypes.SIGNRESULT;
|
||||||
|
|
||||||
SignResultPacket.fromTX = function fromTX(tx, total) {
|
SignResultPacket.prototype.fromTX = function fromTX(tx, total) {
|
||||||
const packet = new SignResultPacket(total);
|
this.total = total;
|
||||||
|
|
||||||
for (const input of tx.inputs) {
|
for (const input of tx.inputs) {
|
||||||
packet.script.push(input.script);
|
this.script.push(input.script);
|
||||||
packet.witness.push(input.witness);
|
this.witness.push(input.witness);
|
||||||
}
|
}
|
||||||
|
|
||||||
return packet;
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
SignResultPacket.fromTX = function fromTX(tx, total) {
|
||||||
|
return new SignResultPacket().fromTX(tx, total);
|
||||||
};
|
};
|
||||||
|
|
||||||
SignResultPacket.prototype.getSize = function getSize() {
|
SignResultPacket.prototype.getSize = function getSize() {
|
||||||
@ -488,6 +527,8 @@ SignResultPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
this.script[i].toWriter(bw);
|
this.script[i].toWriter(bw);
|
||||||
this.witness[i].toWriter(bw);
|
this.witness[i].toWriter(bw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
SignResultPacket.prototype.inject = function inject(tx) {
|
SignResultPacket.prototype.inject = function inject(tx) {
|
||||||
@ -501,20 +542,23 @@ SignResultPacket.prototype.inject = function inject(tx) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SignResultPacket.fromRaw = function fromRaw(data) {
|
SignResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
const br = new BufferReader(data, true);
|
||||||
const packet = new SignResultPacket();
|
|
||||||
|
|
||||||
packet.total = br.readVarint();
|
this.total = br.readVarint();
|
||||||
|
|
||||||
const count = br.readVarint();
|
const count = br.readVarint();
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
packet.script.push(Script.fromReader(br));
|
this.script.push(Script.fromReader(br));
|
||||||
packet.witness.push(Witness.fromReader(br));
|
this.witness.push(Witness.fromReader(br));
|
||||||
}
|
}
|
||||||
|
|
||||||
return packet;
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
SignResultPacket.fromRaw = function fromRaw(data) {
|
||||||
|
return new SignResultPacket().fromRaw(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -550,25 +594,29 @@ CheckInputPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
bw.writeVarint(this.coin.value);
|
bw.writeVarint(this.coin.value);
|
||||||
this.coin.script.toWriter(bw);
|
this.coin.script.toWriter(bw);
|
||||||
bw.writeI32(this.flags != null ? this.flags : -1);
|
bw.writeI32(this.flags != null ? this.flags : -1);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
CheckInputPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
|
||||||
|
this.tx = TX.fromReader(br);
|
||||||
|
this.index = br.readVarint();
|
||||||
|
|
||||||
|
this.coin = new Output();
|
||||||
|
this.coin.value = br.readVarint();
|
||||||
|
this.coin.script.fromReader(br);
|
||||||
|
|
||||||
|
this.flags = br.readI32();
|
||||||
|
|
||||||
|
if (this.flags === -1)
|
||||||
|
this.flags = null;
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckInputPacket.fromRaw = function fromRaw(data) {
|
CheckInputPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new CheckInputPacket().fromRaw(data);
|
||||||
const packet = new CheckInputPacket();
|
|
||||||
|
|
||||||
packet.tx = TX.fromReader(br);
|
|
||||||
packet.index = br.readVarint();
|
|
||||||
|
|
||||||
packet.coin = new Output();
|
|
||||||
packet.coin.value = br.readVarint();
|
|
||||||
packet.coin.script.fromReader(br);
|
|
||||||
|
|
||||||
packet.flags = br.readI32();
|
|
||||||
|
|
||||||
if (packet.flags === -1)
|
|
||||||
packet.flags = null;
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -587,10 +635,7 @@ Object.setPrototypeOf(
|
|||||||
CheckInputResultPacket.prototype.cmd = packetTypes.CHECKINPUTRESULT;
|
CheckInputResultPacket.prototype.cmd = packetTypes.CHECKINPUTRESULT;
|
||||||
|
|
||||||
CheckInputResultPacket.fromRaw = function fromRaw(data) {
|
CheckInputResultPacket.fromRaw = function fromRaw(data) {
|
||||||
const p = CheckResultPacket.fromRaw(data);
|
return new CheckInputResultPacket().fromRaw(data);
|
||||||
const packet = new CheckInputResultPacket();
|
|
||||||
packet.error = p.error;
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -629,23 +674,27 @@ SignInputPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
this.coin.script.toWriter(bw);
|
this.coin.script.toWriter(bw);
|
||||||
this.ring.toWriter(bw);
|
this.ring.toWriter(bw);
|
||||||
bw.writeU8(this.type);
|
bw.writeU8(this.type);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
SignInputPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
|
||||||
|
this.tx = MTX.fromReader(br);
|
||||||
|
this.index = br.readVarint();
|
||||||
|
|
||||||
|
this.coin = new Output();
|
||||||
|
this.coin.value = br.readVarint();
|
||||||
|
this.coin.script.fromReader(br);
|
||||||
|
|
||||||
|
this.ring = KeyRing.fromReader(br);
|
||||||
|
this.type = br.readU8();
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
SignInputPacket.fromRaw = function fromRaw(data) {
|
SignInputPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new SignInputPacket().fromRaw(data);
|
||||||
const packet = new SignInputPacket();
|
|
||||||
|
|
||||||
packet.tx = MTX.fromReader(br);
|
|
||||||
packet.index = br.readVarint();
|
|
||||||
|
|
||||||
packet.coin = new Output();
|
|
||||||
packet.coin.value = br.readVarint();
|
|
||||||
packet.coin.script.fromReader(br);
|
|
||||||
|
|
||||||
packet.ring = KeyRing.fromReader(br);
|
|
||||||
packet.type = br.readU8();
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -664,16 +713,20 @@ Object.setPrototypeOf(SignInputResultPacket.prototype, Packet.prototype);
|
|||||||
|
|
||||||
SignInputResultPacket.prototype.cmd = packetTypes.SIGNINPUTRESULT;
|
SignInputResultPacket.prototype.cmd = packetTypes.SIGNINPUTRESULT;
|
||||||
|
|
||||||
SignInputResultPacket.fromTX = function fromTX(tx, i, value) {
|
SignInputResultPacket.prototype.fromTX = function fromTX(tx, i, value) {
|
||||||
const packet = new SignInputResultPacket(value);
|
|
||||||
const input = tx.inputs[i];
|
const input = tx.inputs[i];
|
||||||
|
|
||||||
assert(input);
|
assert(input);
|
||||||
|
|
||||||
packet.script = input.script;
|
this.value = value;
|
||||||
packet.witness = input.witness;
|
this.script = input.script;
|
||||||
|
this.witness = input.witness;
|
||||||
|
|
||||||
return packet;
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
SignInputResultPacket.fromTX = function fromTX(tx, i, value) {
|
||||||
|
return new SignInputResultPacket().fromTX(tx, i, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
SignInputResultPacket.prototype.getSize = function getSize() {
|
SignInputResultPacket.prototype.getSize = function getSize() {
|
||||||
@ -684,6 +737,7 @@ SignInputResultPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
bw.writeU8(this.value ? 1 : 0);
|
bw.writeU8(this.value ? 1 : 0);
|
||||||
this.script.toWriter(bw);
|
this.script.toWriter(bw);
|
||||||
this.witness.toWriter(bw);
|
this.witness.toWriter(bw);
|
||||||
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
SignInputResultPacket.prototype.inject = function inject(tx, i) {
|
SignInputResultPacket.prototype.inject = function inject(tx, i) {
|
||||||
@ -693,13 +747,16 @@ SignInputResultPacket.prototype.inject = function inject(tx, i) {
|
|||||||
input.witness = this.witness;
|
input.witness = this.witness;
|
||||||
};
|
};
|
||||||
|
|
||||||
SignInputResultPacket.fromRaw = function fromRaw(data) {
|
SignInputResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
const br = new BufferReader(data, true);
|
||||||
const packet = new SignInputResultPacket();
|
this.value = br.readU8() === 1;
|
||||||
packet.value = br.readU8() === 1;
|
this.script = Script.fromReader(br);
|
||||||
packet.script = Script.fromReader(br);
|
this.witness = Witness.fromReader(br);
|
||||||
packet.witness = Witness.fromReader(br);
|
return this;
|
||||||
return packet;
|
};
|
||||||
|
|
||||||
|
SignInputResultPacket.fromRaw = function fromRaw(data) {
|
||||||
|
return new SignInputResultPacket().fromRaw(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -730,15 +787,19 @@ ECVerifyPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
bw.writeVarBytes(this.msg);
|
bw.writeVarBytes(this.msg);
|
||||||
bw.writeVarBytes(this.sig);
|
bw.writeVarBytes(this.sig);
|
||||||
bw.writeVarBytes(this.key);
|
bw.writeVarBytes(this.key);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
ECVerifyPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.msg = br.readVarBytes();
|
||||||
|
this.sig = br.readVarBytes();
|
||||||
|
this.key = br.readVarBytes();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ECVerifyPacket.fromRaw = function fromRaw(data) {
|
ECVerifyPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new ECVerifyPacket().fromRaw(data);
|
||||||
const packet = new ECVerifyPacket();
|
|
||||||
packet.msg = br.readVarBytes();
|
|
||||||
packet.sig = br.readVarBytes();
|
|
||||||
packet.key = br.readVarBytes();
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -761,13 +822,17 @@ ECVerifyResultPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
ECVerifyResultPacket.prototype.toWriter = function toWriter(bw) {
|
ECVerifyResultPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeU8(this.value ? 1 : 0);
|
bw.writeU8(this.value ? 1 : 0);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
ECVerifyResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.value = br.readU8() === 1;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ECVerifyResultPacket.fromRaw = function fromRaw(data) {
|
ECVerifyResultPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new ECVerifyResultPacket().fromRaw(data);
|
||||||
const packet = new ECVerifyResultPacket();
|
|
||||||
packet.value = br.readU8() === 1;
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -795,14 +860,18 @@ ECSignPacket.prototype.getSize = function getSize() {
|
|||||||
ECSignPacket.prototype.toWriter = function toWriter(bw) {
|
ECSignPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarBytes(this.msg);
|
bw.writeVarBytes(this.msg);
|
||||||
bw.writeVarBytes(this.key);
|
bw.writeVarBytes(this.key);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
ECSignPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.msg = br.readVarBytes();
|
||||||
|
this.key = br.readVarBytes();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ECSignPacket.fromRaw = function fromRaw(data) {
|
ECSignPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new ECSignPacket().fromRaw(data);
|
||||||
const packet = new ECSignPacket();
|
|
||||||
packet.msg = br.readVarBytes();
|
|
||||||
packet.key = br.readVarBytes();
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -825,13 +894,17 @@ ECSignResultPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
ECSignResultPacket.prototype.toWriter = function toWriter(bw) {
|
ECSignResultPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarBytes(this.sig);
|
bw.writeVarBytes(this.sig);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
ECSignResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.sig = br.readVarBytes();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ECSignResultPacket.fromRaw = function fromRaw(data) {
|
ECSignResultPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new ECSignResultPacket().fromRaw(data);
|
||||||
const packet = new ECSignResultPacket();
|
|
||||||
packet.sig = br.readVarBytes();
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -860,16 +933,20 @@ MinePacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
bw.writeBytes(this.target);
|
bw.writeBytes(this.target);
|
||||||
bw.writeU32(this.min);
|
bw.writeU32(this.min);
|
||||||
bw.writeU32(this.max);
|
bw.writeU32(this.max);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
MinePacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.data = br.readBytes(80);
|
||||||
|
this.target = br.readBytes(32);
|
||||||
|
this.min = br.readU32();
|
||||||
|
this.max = br.readU32();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
MinePacket.fromRaw = function fromRaw(data) {
|
MinePacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new MinePacket().fromRaw(data);
|
||||||
const packet = new MinePacket();
|
|
||||||
packet.data = br.readBytes(80);
|
|
||||||
packet.target = br.readBytes(32);
|
|
||||||
packet.min = br.readU32();
|
|
||||||
packet.max = br.readU32();
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -887,20 +964,25 @@ Object.setPrototypeOf(MineResultPacket.prototype, Packet.prototype);
|
|||||||
MineResultPacket.prototype.cmd = packetTypes.MINERESULT;
|
MineResultPacket.prototype.cmd = packetTypes.MINERESULT;
|
||||||
|
|
||||||
MineResultPacket.prototype.getSize = function getSize() {
|
MineResultPacket.prototype.getSize = function getSize() {
|
||||||
return 4;
|
return 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
MineResultPacket.prototype.toWriter = function toWriter(bw) {
|
MineResultPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
|
bw.writeU8(this.nonce !== -1 ? 1 : 0);
|
||||||
bw.writeU32(this.nonce);
|
bw.writeU32(this.nonce);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
MineResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.nonce = -1;
|
||||||
|
if (br.readU8() === 1)
|
||||||
|
this.nonce = br.readU32();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
MineResultPacket.fromRaw = function fromRaw(data) {
|
MineResultPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new MineResultPacket().fromRaw(data);
|
||||||
const packet = new MineResultPacket();
|
|
||||||
packet.nonce = br.readU32();
|
|
||||||
if ((packet.nonce >> 0) === -1)
|
|
||||||
packet.nonce = -1;
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -937,18 +1019,22 @@ ScryptPacket.prototype.toWriter = function toWriter(bw) {
|
|||||||
bw.writeU32(this.r);
|
bw.writeU32(this.r);
|
||||||
bw.writeU32(this.p);
|
bw.writeU32(this.p);
|
||||||
bw.writeU32(this.len);
|
bw.writeU32(this.len);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
ScryptPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.passwd = br.readVarBytes();
|
||||||
|
this.salt = br.readVarBytes();
|
||||||
|
this.N = br.readU32();
|
||||||
|
this.r = br.readU32();
|
||||||
|
this.p = br.readU32();
|
||||||
|
this.len = br.readU32();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScryptPacket.fromRaw = function fromRaw(data) {
|
ScryptPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new ScryptPacket().fromRaw(data);
|
||||||
const packet = new ScryptPacket();
|
|
||||||
packet.passwd = br.readVarBytes();
|
|
||||||
packet.salt = br.readVarBytes();
|
|
||||||
packet.N = br.readU32();
|
|
||||||
packet.r = br.readU32();
|
|
||||||
packet.p = br.readU32();
|
|
||||||
packet.len = br.readU32();
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -971,15 +1057,29 @@ ScryptResultPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
ScryptResultPacket.prototype.toWriter = function toWriter(bw) {
|
ScryptResultPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.writeVarBytes(this.key);
|
bw.writeVarBytes(this.key);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
|
ScryptResultPacket.prototype.fromRaw = function fromRaw(data) {
|
||||||
|
const br = new BufferReader(data, true);
|
||||||
|
this.key = br.readVarBytes();
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScryptResultPacket.fromRaw = function fromRaw(data) {
|
ScryptResultPacket.fromRaw = function fromRaw(data) {
|
||||||
const br = new BufferReader(data, true);
|
return new ScryptResultPacket().fromRaw(data);
|
||||||
const packet = new ScryptResultPacket();
|
|
||||||
packet.key = br.readVarBytes();
|
|
||||||
return packet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helpers
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stringify(value) {
|
||||||
|
if (typeof value !== 'string')
|
||||||
|
return '';
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -27,7 +27,7 @@ const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp'
|
|||||||
+ 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa';
|
+ 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa';
|
||||||
|
|
||||||
const workers = new WorkerPool({
|
const workers = new WorkerPool({
|
||||||
enabled: false
|
enabled: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const wdb = new WalletDB({
|
const wdb = new WalletDB({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user