Permissionless-Software-Foundation / fulcrum-api

A REST API wrapper for Fulcrum Electrumx indexer and electrum-cash JS library.
MIT License
0 stars 1 forks source link

P2SH32 addresses are not supported by the api #13

Open mr-zwets opened 1 week ago

mr-zwets commented 1 week ago

When using the fulcrum-api through bch-js to get utxos for a p2sh32 address (default smart contract addresses in CashScript)

the api returns

{
  "success": false,
  "error": {
    "success": false,
    "error": "Invalid Argument: Must provide a `hash` or `hashBuffer` property"
  }
}

for example for: https://api.fullstack.cash/v5/electrumx/utxos/bitcoincash:pdpjeyus929guj00y3sz3ec8ehd2v73e4art9v7prsvke5yujvt5vs6mz82xa

The P2SH32 address format was added in the may 2023 upgrade together with CashTokens and is the more cryptographically secure version of P2SH20.

The easy fix would be just to not use this function to convert all addresses to scripthashes this is unneeded for recent electrum versions 😄👍

Address support has been there since Version 1.4.3

See https://electrum-cash-protocol.readthedocs.io/en/latest/protocol-methods.html

christroutner commented 1 week ago

:tada: This issue has been resolved in version 1.4.6 :tada:

Your semantic-release bot :package::rocket:

christroutner commented 1 week ago

I chased down the line of code that was throwing an error on the example P2SH32 address. It turned out to be this line which calls the bitcore-lib-cash library. I tried upgrading to the latest version, but that didn't fix the issue.

I then tried the changes in #14 to use addresses instead of a scripthash. That appeared to work, but it upon further investigation is was not returning UTXOs for any addresses, even normal P2PKH addresses known to have UTXOs in them. It also broke the bch-js API.

I reverted the code back.

If another developer would like to submit a PR that fixes this issue and does not break any existing functionality (like not breaking the wallet.fullstack.cash web wallet). I'd be happy to merge it.

At present, this looks like there is too much work involved to support this change. I'm happy to support P2SH32 addresses, but only if it does not impact existing functionality and business goals. At the moment, P2SH32 support is not a priority for the PSF or for me personally.

I'll leave this issue open, in case someone comes along and wants to try to fix it.