Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS: getTransactionConfirmations won't work with Electrs #422

Closed
nkuba opened this issue Nov 25, 2022 · 0 comments · Fixed by #501
Closed

TS: getTransactionConfirmations won't work with Electrs #422

nkuba opened this issue Nov 25, 2022 · 0 comments · Fixed by #501
Labels
🔌 typescript TypeScript library

Comments

@nkuba
Copy link
Member

nkuba commented Nov 25, 2022

The current implementation of getTransactionConfirmations won't work with Electrs, as verbose transaction details are not supported there (see: Blockstream/electrs#36 (comment)).

// eslint-disable-next-line valid-jsdoc
/**
* @see {BitcoinClient#getTransactionConfirmations}
*/
getTransactionConfirmations(
transactionHash: TransactionHash
): Promise<number> {
return this.withElectrum<number>(async (electrum: any) => {
const transaction = await electrum.blockchain_transaction_get(
transactionHash,
true
)
return transaction.confirmations
})
}

We should implement a workaround to cover Electrs.
An example workaround was implemented in the Keep Client:
https://github.com/keep-network/keep-core/blob/d69e971fc734031111699f95eccc3bbbafe4345f/pkg/bitcoin/electrum/electrum.go#L163-L206

@nkuba nkuba changed the title getTransactionConfirmations won't work with Electrs tbtc.ts: getTransactionConfirmations won't work with Electrs Nov 25, 2022
@nkuba nkuba added the 🔌 typescript TypeScript library label Nov 25, 2022
@nkuba nkuba changed the title tbtc.ts: getTransactionConfirmations won't work with Electrs TS: getTransactionConfirmations won't work with Electrs Jan 25, 2023
@nkuba nkuba self-assigned this Jan 25, 2023
lukasz-zimnoch added a commit that referenced this issue Jan 26, 2023
…ol integration (#501)

Closes: #422

In this PR we update the implementation of TypeScript Electrum
integration to support Esplora/Electrs servers.

As per Blockstream/electrs#36 verbose
transactions are not supported by Esplora/Electrs.
This affects our implementation of `getTransaction` and
`getTransactionConfirmations` functions.

For a consistent code in the client without alternative paths for
different Electrum servers implementations I decided to not use verbose
transactions at all.

###
[getTransactionConfirmations](26d4f01)

1. Get the raw transaction
2. Deserialize the raw transaction
3. Find transaction block height by finding it in a history of
   transactions for the output script included in the transaction.
4. Get the latest block height
5. Calculate number of confirmations by subtracting the transaction
   block height from the latest block height and adding one.

###
[getTransaction](a7aedd1)

We get a raw transaction and deserialize it with `bcoin`. This lets us
define a consistent type for returned transactions
(093d4ec). Before these changes, I
observed that Electrum server implementations are not consistent with
data returned in verbose JSON.

### Electrum tests

We can test electrum integration against different kinds of servers.
The most popular implementations are:
- ElectrumX
- Fulcrum
- Electrs/Esplora

We can find a list of public servers here:
https://1209k.com/bitcoin-eye/ele.php?chain=tbtc

The electrs-esplora server seems pretty unstable, so we don't want to
enable it in tests until we add retries
(#485).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔌 typescript TypeScript library
Projects
None yet
2 participants