Support CashAddr format (#109)
* Don't convert BCH address * Update for CashAddr * Rename to Bitcoin Cash * fix typo
This commit is contained in:
parent
982c60c7f5
commit
edd54c16f5
4 changed files with 6 additions and 27 deletions
|
|
@ -1,6 +1,5 @@
|
|||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const bs58check = require('bs58check')
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
|
|
@ -37,29 +36,11 @@ function balance (account, cryptoCode) {
|
|||
return accountBalance(account, cryptoCode, 1)
|
||||
}
|
||||
|
||||
function bchToBtcVersion (version) {
|
||||
if (version === 0x1c) return 0x00
|
||||
if (version === 0x28) return 0x05
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
// Bitcoin-ABC only accepts BTC style addresses at this point,
|
||||
// so we need to convert
|
||||
function bchToBtcAddress (address) {
|
||||
const buf = bs58check.decode(address)
|
||||
const version = buf[0]
|
||||
buf[0] = bchToBtcVersion(version)
|
||||
return bs58check.encode(buf)
|
||||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
const coins = cryptoAtoms.shift(-unitScale).toFixed(8)
|
||||
|
||||
const btcAddress = bchToBtcAddress(address)
|
||||
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('sendtoaddress', [btcAddress, coins]))
|
||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||
.catch(err => {
|
||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||
throw err
|
||||
|
|
@ -72,9 +53,7 @@ function newAddress (account, info) {
|
|||
}
|
||||
|
||||
function addressBalance (address, confs) {
|
||||
const btcAddress = bchToBtcAddress(address)
|
||||
|
||||
return fetch('getreceivedbyaddress', [btcAddress, confs])
|
||||
return fetch('getreceivedbyaddress', [address, confs])
|
||||
.then(r => BN(r).shift(unitScale).round())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue