Closed bucko13 closed 8 months ago
Is there an ETA of this getting merged into main?
Blockstream API broadcast accepts raw tx not JSON object. I am experiencing a CORS policy failure on preflight as well as the broadcast itself. Copying the HEX and posting it via CURL works successfully.
public async broadcastTransaction(rawTx: string): Promise<any> {
try {
if (this.type === ClientType.PRIVATE) {
return bitcoindSendRawTransaction({
hex: rawTx,
...this.bitcoindParams,
});
}
return await this.Post(`/tx`, { tx: rawTx });
} catch (error) {
throw new Error(`Failed to broadcast transaction: ${error.message}`);
}
}
Description
With a recent release adding mempool.space support (#347), a few issues came to light, which this PR seeks to address.
Problems
Rate Limiting in mempool.space
The biggest one noticed in #364 was that recent rate limiting implemented on mempool.space's main production endpoint caused significant performance degradation. Throttling was already an issue with blockstream for which we added a delay to avoid hitting the rate limit, but this may not be enough.
Hard to change client
Unfortunately the way to change the client had to come from unchained-bitcoin, which is really inconvenient and probably not the right long term place for this.
Clumsy API
Every api call had to pass in the network and client info even though once the wallet is setup, this doesn't change. Would be nice to just get this from the store and be done.
Mempool not a perfect drop-in replacement
One of the api calls (getFeeEstimates) was not quite a drop-in b/w mempool and blockstream. So this might've been broken as well
Hard to make changes
If there are any changes in the future (immediate example: mempool is going to have a websocket option for using as a wallet backend), it's not easy to update the client without backwards incompatible changes.
Solution
BlockchainClient
class (d3201c2), which once initialized with the connection details shares an api no matter what client you're connecting withclientActions
shows how easy it should be to support multiple clients. It's one line now to change the default public b/w blockstream and mempool and eventually we should easily be able to support either and leave it up to the user.Does this PR introduce a breaking change?
Does this PR fix an open issue?