From 4a4e75d007291b661ae1df5d85dac48bf650bfea Mon Sep 17 00:00:00 2001 From: Andreas Brekken Date: Sat, 1 Mar 2014 19:19:27 +0100 Subject: [PATCH] Simplify Script constructor. close #41 --- src/script.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/script.js b/src/script.js index 7a544bd..5d04371 100644 --- a/src/script.js +++ b/src/script.js @@ -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(' ');