mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Enable P2SH addresses to be used with the ElectrumX endpoints
This commit is contained in:
@@ -911,7 +911,9 @@ class Electrum {
|
||||
const address = _this.bitcore.Address.fromString(addrStr)
|
||||
// console.log(`address: ${address}`)
|
||||
|
||||
const script = _this.bitcore.Script.buildPublicKeyHashOut(address)
|
||||
const script = address.isPayToPublicKeyHash()
|
||||
? _this.bitcore.Script.buildPublicKeyHashOut(address)
|
||||
: _this.bitcore.Script.buildScriptHashOut(address)
|
||||
// console.log(`script: ${script}`)
|
||||
|
||||
const scripthash = _this.bitcore.crypto.Hash.sha256(script.toBuffer())
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('#ElectrumX Router', () => {
|
||||
})
|
||||
|
||||
describe('#addressToScripthash', () => {
|
||||
it('should accurately return a scripthash', () => {
|
||||
it('should accurately return a scripthash for a P2PKH address', () => {
|
||||
const addr = 'bitcoincash:qpr270a5sxphltdmggtj07v4nskn9gmg9yx4m5h7s4'
|
||||
|
||||
const scripthash = electrumxRoute.addressToScripthash(addr)
|
||||
@@ -104,6 +104,17 @@ describe('#ElectrumX Router', () => {
|
||||
|
||||
assert.equal(scripthash, expectedOutput)
|
||||
})
|
||||
|
||||
it('should accurately return a scripthash for a P2SH address', () => {
|
||||
const addr = 'bitcoincash:pz0z7u9p96h2p6hfychxdrmwgdlzpk5luc5yks2wxq'
|
||||
|
||||
const scripthash = electrumxRoute.addressToScripthash(addr)
|
||||
|
||||
const expectedOutput =
|
||||
'8bc2235c8e7d5634d9ec429fc0171f2c58e728d4f1e2fb7e440e313133cfa4f0'
|
||||
|
||||
assert.equal(scripthash, expectedOutput)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#_utxosFromElectrumx', () => {
|
||||
|
||||
Reference in New Issue
Block a user