Refactored addressToScript for clarity
This commit is contained in:
parent
741c2a6a6b
commit
e049c413ba
44
lib/util.js
44
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])]);
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user