diff --git a/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts b/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts index aa9fe5d15..7b2802d1b 100644 --- a/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts +++ b/backend/src/api/bitcoin/bitcoin-api-abstract-factory.ts @@ -10,7 +10,7 @@ export interface AbstractBitcoinApi { $getBlockHash(height: number): Promise; $getBlockHeader(hash: string): Promise; $getBlock(hash: string): Promise; - $getRawBlock(hash: string): Promise; + $getRawBlock(hash: string): Promise; $getAddress(address: string): Promise; $getAddressTransactions(address: string, lastSeenTxId: string): Promise; $getAddressPrefix(prefix: string): string[]; diff --git a/backend/src/api/bitcoin/bitcoin-api.ts b/backend/src/api/bitcoin/bitcoin-api.ts index 0a3d674ec..cad11aeda 100644 --- a/backend/src/api/bitcoin/bitcoin-api.ts +++ b/backend/src/api/bitcoin/bitcoin-api.ts @@ -81,7 +81,7 @@ class BitcoinApi implements AbstractBitcoinApi { .then((rpcBlock: IBitcoinApi.Block) => rpcBlock.tx); } - $getRawBlock(hash: string): Promise { + $getRawBlock(hash: string): Promise { return this.bitcoindClient.getBlock(hash, 0) .then((raw: string) => Buffer.from(raw, "hex")); } diff --git a/backend/src/api/bitcoin/esplora-api.ts b/backend/src/api/bitcoin/esplora-api.ts index 3662347d6..37f6e5892 100644 --- a/backend/src/api/bitcoin/esplora-api.ts +++ b/backend/src/api/bitcoin/esplora-api.ts @@ -55,9 +55,9 @@ class ElectrsApi implements AbstractBitcoinApi { .then((response) => response.data); } - $getRawBlock(hash: string): Promise { - return axios.get(config.ESPLORA.REST_API_URL + '/block/' + hash + "/raw", this.axiosConfig) - .then((response) => response.data); + $getRawBlock(hash: string): Promise { + return axios.get(config.ESPLORA.REST_API_URL + '/block/' + hash + "/raw", { ...this.axiosConfig, responseType: 'arraybuffer' }) + .then((response) => { return Buffer.from(response.data); }); } $getAddress(address: string): Promise { diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 828c86c31..f247617de 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -744,8 +744,8 @@ class Blocks { let transactions; if (Common.blocksSummariesIndexingEnabled()) { transactions = await this.$getStrippedBlockTransactions(hash); - const rawBlock = await bitcoinClient.getBlock(hash, 0); - const block = Block.fromHex(rawBlock); + const rawBlock = await bitcoinApi.$getRawBlock(hash); + const block = Block.fromBuffer(rawBlock); const txMap = {}; for (const tx of block.transactions || []) { txMap[tx.getId()] = tx;