From 71ed3b83dd69813433c0b7f24b1aa9e5c485537e Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 2 Apr 2019 14:40:58 -0300 Subject: [PATCH] Send legacy address for BCH on bitgo api --- lib/plugins/wallet/bitgo/bitgo.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/plugins/wallet/bitgo/bitgo.js b/lib/plugins/wallet/bitgo/bitgo.js index 5dab08df..d7e72bc3 100644 --- a/lib/plugins/wallet/bitgo/bitgo.js +++ b/lib/plugins/wallet/bitgo/bitgo.js @@ -12,6 +12,7 @@ const userAgent = 'Lamassu-Server/' + pjson.version const NAME = 'BitGo' const SUPPORTED_COINS = ['BTC', 'ZEC', 'LTC', 'BCH', 'DASH'] +const BCH_CODES = ['BCH', 'TBCH'] function buildBitgo (account) { const env = account.environment === 'test' ? 'test' : 'prod' @@ -34,19 +35,24 @@ function checkCryptoCode (cryptoCode) { } function getLegacyAddress (address, cryptoCode) { - const BCH_CODES = ['BCH', 'TBCH'] if (!BCH_CODES.includes(cryptoCode)) return address return toLegacyAddress(address) } function getCashAddress (address, cryptoCode) { - const BCH_CODES = ['BCH', 'TBCH'] if (!BCH_CODES.includes(cryptoCode)) return address return toCashAddress(address) } +function formatToGetStatus (address, cryptoCode) { + if (!BCH_CODES.includes(cryptoCode)) return address + + const [part1, part2] = getLegacyAddress(address, cryptoCode).split(':') + return part2 || part1 +} + function sendCoins (account, address, cryptoAtoms, cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => getWallet(account, cryptoCode)) @@ -99,7 +105,10 @@ function newAddress (account, info) { function getStatus (account, toAddress, requested, cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => getWallet(account, cryptoCode)) - .then(wallet => wallet.transfers({ type: 'receive', address: toAddress })) + .then(wallet => wallet.transfers({ + type: 'receive', + address: formatToGetStatus(toAddress, cryptoCode) + })) .then(({ transfers }) => { const filterConfirmed = _.filter(it => it.state === 'confirmed' && it.type === 'receive'