script fromJSON. mempool test.
This commit is contained in:
parent
402b47a940
commit
05b83fe1c8
@ -160,7 +160,7 @@ Coin.prototype.toJSON = function toJSON() {
|
||||
version: this.version,
|
||||
height: this.height,
|
||||
value: utils.btc(this.value),
|
||||
script: this.script.toRaw().toString('hex'),
|
||||
script: this.script.toJSON(),
|
||||
coinbase: this.coinbase,
|
||||
hash: this.hash ? utils.revHex(this.hash) : null,
|
||||
index: this.index
|
||||
@ -195,7 +195,7 @@ Coin.prototype.fromJSON = function fromJSON(json) {
|
||||
this.version = json.version;
|
||||
this.height = json.height;
|
||||
this.value = utils.satoshi(json.value);
|
||||
this.script = bcoin.script.fromRaw(new Buffer(json.script, 'hex'));
|
||||
this.script = bcoin.script.fromJSON(json.script);
|
||||
this.coinbase = json.coinbase;
|
||||
this.hash = json.hash ? utils.revHex(json.hash) : null;
|
||||
this.index = json.index;
|
||||
|
||||
@ -310,6 +310,17 @@ Witness.prototype.toJSON = function toJSON() {
|
||||
return this.toRaw().toString('hex');
|
||||
};
|
||||
|
||||
/**
|
||||
* Inject properties from json object.
|
||||
* @private
|
||||
* @param {String} json
|
||||
*/
|
||||
|
||||
Witness.prototype.fromJSON = function fromJSON(json) {
|
||||
assert(typeof json === 'string');
|
||||
return this.fromRaw(new Buffer(json, 'hex'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Insantiate witness from a hex string.
|
||||
* @param {String} json
|
||||
@ -317,7 +328,7 @@ Witness.prototype.toJSON = function toJSON() {
|
||||
*/
|
||||
|
||||
Witness.fromJSON = function fromJSON(json) {
|
||||
return Witness.fromRaw(json, 'hex');
|
||||
return new Witness().fromJSON(json);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1257,6 +1268,17 @@ Script.prototype.toJSON = function toJSON() {
|
||||
return this.toRaw().toString('hex');
|
||||
};
|
||||
|
||||
/**
|
||||
* Inject properties from json object.
|
||||
* @private
|
||||
* @param {String} json
|
||||
*/
|
||||
|
||||
Script.prototype.fromJSON = function fromJSON(json) {
|
||||
assert(typeof json === 'string');
|
||||
return this.fromRaw(new Buffer(json, 'hex'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate script from a hex string.
|
||||
* @params {String} json
|
||||
@ -1264,7 +1286,7 @@ Script.prototype.toJSON = function toJSON() {
|
||||
*/
|
||||
|
||||
Script.fromJSON = function fromJSON(json) {
|
||||
return Script.fromRaw(json, 'hex');
|
||||
return new Script().fromJSON(json);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -101,7 +101,8 @@ describe('Mempool', function() {
|
||||
w.scriptInputs(fake, function(err) {
|
||||
assert.ifError(err);
|
||||
// Fake signature
|
||||
fake.inputs[0].script.code[0] = new Buffer([0,0,0,0,0,0,0,0,0]);
|
||||
fake.inputs[0].script.set(0, new Buffer([0,0,0,0,0,0,0,0,0]));
|
||||
fake.inputs[0].script.compile();
|
||||
// balance: 11000
|
||||
[t2, t3, t4, f1, fake].forEach(function(tx) {
|
||||
tx.inputs.forEach(function(input) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user