Merge pull request #1239 from braydonf/bug/getdata
Added test case for an empty OP_RETURN for script.getData() Fixes #1237
This commit is contained in:
commit
83103cb5e2
@ -365,7 +365,11 @@ Script.prototype.isDataOut = function() {
|
|||||||
*/
|
*/
|
||||||
Script.prototype.getData = function() {
|
Script.prototype.getData = function() {
|
||||||
if (this.isDataOut() || this.isScriptHashOut()) {
|
if (this.isDataOut() || this.isScriptHashOut()) {
|
||||||
return new Buffer(this.chunks[1].buf);
|
if (_.isUndefined(this.chunks[1])) {
|
||||||
|
return new Buffer(0);
|
||||||
|
} else {
|
||||||
|
return new Buffer(this.chunks[1].buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.isPublicKeyHashOut()) {
|
if (this.isPublicKeyHashOut()) {
|
||||||
return new Buffer(this.chunks[2].buf);
|
return new Buffer(this.chunks[2].buf);
|
||||||
|
|||||||
@ -658,6 +658,15 @@ describe('Script', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('getData returns associated data', function() {
|
describe('getData returns associated data', function() {
|
||||||
|
it('works with this testnet transaction', function() {
|
||||||
|
// testnet block: 00000000a36400fc06440512354515964bc36ecb0020bd0b0fd48ae201965f54
|
||||||
|
// txhash: e362e21ff1d2ef78379d401d89b42ce3e0ce3e245f74b1f4cb624a8baa5d53ad (output 0);
|
||||||
|
var script = Script.fromBuffer(new Buffer('6a', 'hex'));
|
||||||
|
var dataout = script.isDataOut();
|
||||||
|
dataout.should.equal(true);
|
||||||
|
var data = script.getData();
|
||||||
|
data.should.deep.equal(new Buffer(0));
|
||||||
|
});
|
||||||
it('for a P2PKH address', function() {
|
it('for a P2PKH address', function() {
|
||||||
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
|
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
|
||||||
var script = Script.buildPublicKeyHashOut(address);
|
var script = Script.buildPublicKeyHashOut(address);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user