Simplify Script constructor. close #41

This commit is contained in:
Andreas Brekken 2014-03-01 19:19:27 +01:00
parent 354d31a297
commit 4a4e75d007

View file

@ -4,21 +4,14 @@ var conv = require('./convert');
var Address = require('./address');
var Script = function(data) {
if (!data) {
this.buffer = [];
} else if ('string' == typeof data) {
this.buffer = conv.hexToBytes(data);
} else if (util.isArray(data)) {
this.buffer = data;
} else if (data instanceof Script) {
this.buffer = data.buffer;
} else {
throw new Error('Invalid script');
}
this.buffer = data || [];
this.parse();
};
Script.fromHex = function(data) {
return new Script(conv.hexToBytes(data))
};
Script.fromPubKey = function(str) {
var script = new Script();
var s = str.split(' ');