From ad9ad3ed7544765c41736d8bfc3ffb7f6804be1a Mon Sep 17 00:00:00 2001 From: joshuayabut Date: Fri, 20 Apr 2018 12:30:14 -0700 Subject: [PATCH] Add regtest address support --- src/address.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/address.js b/src/address.js index b53636ef4..41da472c7 100644 --- a/src/address.js +++ b/src/address.js @@ -353,7 +353,8 @@ Address._transformStringCashAddr = function(data, network, type) { $.checkArgument( !network || (network === 'livenet' && decoded.prefix === 'bitcoincash') || - (network === 'testnet' && decoded.prefix === 'bchtest'), + (network === 'testnet' && decoded.prefix === 'bchtest') || + (network === 'testnet' && decoded.prefix === 'bchreg'), 'Invalid network.' ); $.checkArgument( @@ -622,7 +623,10 @@ Address.prototype._toStringBitpay = function() { * @returns {string} Bitcoin address */ Address.prototype._toStringCashAddr = function() { - var prefix = this.network.toString() === 'livenet' ? 'bitcoincash' : 'bchtest'; + var prefix = this.network.toString(); + if (prefix === 'livenet') prefix = 'bitcoincash'; + else if (prefix === 'testnet' && this.network.regtestEnabled !== true) prefix = 'bchtest'; + else if (prefix === 'testnet' && this.network.regtestEnabled === true) prefix = 'bchreg'; var type = this.type === Address.PayToPublicKeyHash ? 'P2PKH' : 'P2SH'; return cashaddr.encode(prefix, type, this.hashBuffer); }