Merge pull request #1293 from braydonf/script-data-encoding
Added encoding type for buildDataOut
This commit is contained in:
commit
6ac7ad9da1
|
@ -682,12 +682,13 @@ Script.buildPublicKeyOut = function(pubkey) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Script} a new OP_RETURN script with data
|
* @returns {Script} a new OP_RETURN script with data
|
||||||
* @param {(string|Buffer)} to - the data to embed in the output
|
* @param {(string|Buffer)} data - the data to embed in the output
|
||||||
|
* @param {(string)} encoding - the type of encoding of the string
|
||||||
*/
|
*/
|
||||||
Script.buildDataOut = function(data) {
|
Script.buildDataOut = function(data, encoding) {
|
||||||
$.checkArgument(_.isUndefined(data) || _.isString(data) || BufferUtil.isBuffer(data));
|
$.checkArgument(_.isUndefined(data) || _.isString(data) || BufferUtil.isBuffer(data));
|
||||||
if (typeof data === 'string') {
|
if (_.isString(data)) {
|
||||||
data = new Buffer(data);
|
data = new Buffer(data, encoding);
|
||||||
}
|
}
|
||||||
var s = new Script();
|
var s = new Script();
|
||||||
s.add(Opcode.OP_RETURN);
|
s.add(Opcode.OP_RETURN);
|
||||||
|
|
|
@ -599,6 +599,13 @@ describe('Script', function() {
|
||||||
s.toString().should.equal('OP_RETURN 14 0x68656c6c6f20776f726c64212121');
|
s.toString().should.equal('OP_RETURN 14 0x68656c6c6f20776f726c64212121');
|
||||||
s.isDataOut().should.equal(true);
|
s.isDataOut().should.equal(true);
|
||||||
});
|
});
|
||||||
|
it('should create script from a hex string', function() {
|
||||||
|
var hexString = 'abcdef0123456789';
|
||||||
|
var s = Script.buildDataOut(hexString, 'hex');
|
||||||
|
should.exist(s);
|
||||||
|
s.toString().should.equal('OP_RETURN 8 0xabcdef0123456789');
|
||||||
|
s.isDataOut().should.equal(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('#buildScriptHashOut', function() {
|
describe('#buildScriptHashOut', function() {
|
||||||
it('should create script from another script', function() {
|
it('should create script from another script', function() {
|
||||||
|
|
Loading…
Reference in New Issue