From e049c413baab791bba14870a0f613b03760817af Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 1 Apr 2014 10:29:38 -0600 Subject: [PATCH] Refactored addressToScript for clarity --- lib/util.js | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/lib/util.js b/lib/util.js index 2fd3a37..f98bcd3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -238,33 +238,6 @@ exports.getVersionByte = function(addr){ return base58.decode(addr)[0]; }; -exports.addressToPubkey = function(addr){ - - var decoded = base58.decode(addr); - - if (decoded.length != 25){ - console.error('invalid address length for ' + addr); - throw new Error(); - } - - if (!decoded){ - console.error('base58 decode failed for ' + addr); - throw new Error(); - } - - /* We already do rpc.validateaddress so we don't need this - var ver = decoded[0]; - var cksumA = decoded.slice(-4); - var cksumB = exports.sha256d(decoded.slice(0, -4)).slice(0, 4); - - if (cksumA.toString('hex') != cksumB.toString('hex')){ - console.error('checksum did not match for ' + addr) - //throw new Error(); - }*/ - - return decoded.slice(1,-4); -}; - /* For POS coins - used to format wallet address for use in generation transaction's output @@ -286,8 +259,21 @@ exports.pubkeyToScript = function(key){ /* For POW coins - used to format wallet address for use in generation transaction's output */ - exports.addressToScript = function(addr){ - var pubkey = exports.addressToPubkey(addr); + + var decoded = base58.decode(addr); + + if (decoded.length != 25){ + console.error('invalid address length for ' + addr); + throw new Error(); + } + + if (!decoded){ + console.error('base58 decode failed for ' + addr); + throw new Error(); + } + + var pubkey = decoded.slice(1,-4); + return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), pubkey, new Buffer([0x88, 0xac])]); }; \ No newline at end of file