Merge pull request #1084 from eordano/update/opreturn80

Script: Update max length for standard opreturn to 80
This commit is contained in:
Braydon Fuller 2015-02-18 09:09:28 -05:00
commit cb5648cbe4
2 changed files with 16 additions and 4 deletions

View File

@ -324,7 +324,7 @@ Script.prototype.isMultisigIn = function() {
};
/**
* @returns {boolean} if this is an OP_RETURN data script
* @returns {boolean} true if this is a valid standard OP_RETURN output
*/
Script.prototype.isDataOut = function() {
return this.chunks.length >= 1 &&
@ -332,7 +332,7 @@ Script.prototype.isDataOut = function() {
(this.chunks.length === 1 ||
(this.chunks.length === 2 &&
this.chunks[1].buf &&
this.chunks[1].buf.length <= 40 &&
this.chunks[1].buf.length <= Script.OP_RETURN_STANDARD_SIZE &&
this.chunks[1].length === this.chunks.len));
};
@ -375,6 +375,8 @@ Script.types.MULTISIG_OUT = 'Pay to multisig';
Script.types.MULTISIG_IN = 'Spend from multisig';
Script.types.DATA_OUT = 'Data push';
Script.OP_RETURN_STANDARD_SIZE = 80;
Script.identifiers = {};
Script.identifiers.PUBKEY_OUT = Script.prototype.isPublicKeyOut;
Script.identifiers.PUBKEY_IN = Script.prototype.isPublicKeyIn;

View File

@ -207,18 +207,28 @@ describe('Script', function() {
Script('OP_RETURN').isDataOut().should.equal(true);
});
it('should know this is an OP_RETURN script', function() {
it('validates that this 40-byte OP_RETURN is standard', function() {
var buf = new Buffer(40);
buf.fill(0);
Script('OP_RETURN 40 0x' + buf.toString('hex')).isDataOut().should.equal(true);
});
it('validates that this 80-byte OP_RETURN is standard', function() {
var buf = new Buffer(80);
buf.fill(0);
Script('OP_RETURN OP_PUSHDATA1 80 0x' + buf.toString('hex')).isDataOut().should.equal(true);
});
it('should know this is not an OP_RETURN script', function() {
it('validates that this 40-byte long OP_CHECKMULTISIG is not standard op_return', function() {
var buf = new Buffer(40);
buf.fill(0);
Script('OP_CHECKMULTISIG 40 0x' + buf.toString('hex')).isDataOut().should.equal(false);
});
it('validates that this 81-byte OP_RETURN is not a valid standard OP_RETURN', function() {
var buf = new Buffer(81);
buf.fill(0);
Script('OP_RETURN OP_PUSHDATA1 81 0x' + buf.toString('hex')).isDataOut().should.equal(false);
});
});
describe('#isPublicKeyHashIn', function() {