get blocks from esplora for cpfp indexer
This commit is contained in:
parent
f2ad184d1f
commit
6d6dd09d11
@ -10,7 +10,7 @@ export interface AbstractBitcoinApi {
|
|||||||
$getBlockHash(height: number): Promise<string>;
|
$getBlockHash(height: number): Promise<string>;
|
||||||
$getBlockHeader(hash: string): Promise<string>;
|
$getBlockHeader(hash: string): Promise<string>;
|
||||||
$getBlock(hash: string): Promise<IEsploraApi.Block>;
|
$getBlock(hash: string): Promise<IEsploraApi.Block>;
|
||||||
$getRawBlock(hash: string): Promise<string>;
|
$getRawBlock(hash: string): Promise<Buffer>;
|
||||||
$getAddress(address: string): Promise<IEsploraApi.Address>;
|
$getAddress(address: string): Promise<IEsploraApi.Address>;
|
||||||
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
|
$getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
|
||||||
$getAddressPrefix(prefix: string): string[];
|
$getAddressPrefix(prefix: string): string[];
|
||||||
|
@ -81,7 +81,7 @@ class BitcoinApi implements AbstractBitcoinApi {
|
|||||||
.then((rpcBlock: IBitcoinApi.Block) => rpcBlock.tx);
|
.then((rpcBlock: IBitcoinApi.Block) => rpcBlock.tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getRawBlock(hash: string): Promise<string> {
|
$getRawBlock(hash: string): Promise<Buffer> {
|
||||||
return this.bitcoindClient.getBlock(hash, 0)
|
return this.bitcoindClient.getBlock(hash, 0)
|
||||||
.then((raw: string) => Buffer.from(raw, "hex"));
|
.then((raw: string) => Buffer.from(raw, "hex"));
|
||||||
}
|
}
|
||||||
|
@ -55,9 +55,9 @@ class ElectrsApi implements AbstractBitcoinApi {
|
|||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getRawBlock(hash: string): Promise<string> {
|
$getRawBlock(hash: string): Promise<Buffer> {
|
||||||
return axios.get<string>(config.ESPLORA.REST_API_URL + '/block/' + hash + "/raw", this.axiosConfig)
|
return axios.get<string>(config.ESPLORA.REST_API_URL + '/block/' + hash + "/raw", { ...this.axiosConfig, responseType: 'arraybuffer' })
|
||||||
.then((response) => response.data);
|
.then((response) => { return Buffer.from(response.data); });
|
||||||
}
|
}
|
||||||
|
|
||||||
$getAddress(address: string): Promise<IEsploraApi.Address> {
|
$getAddress(address: string): Promise<IEsploraApi.Address> {
|
||||||
|
@ -744,8 +744,8 @@ class Blocks {
|
|||||||
let transactions;
|
let transactions;
|
||||||
if (Common.blocksSummariesIndexingEnabled()) {
|
if (Common.blocksSummariesIndexingEnabled()) {
|
||||||
transactions = await this.$getStrippedBlockTransactions(hash);
|
transactions = await this.$getStrippedBlockTransactions(hash);
|
||||||
const rawBlock = await bitcoinClient.getBlock(hash, 0);
|
const rawBlock = await bitcoinApi.$getRawBlock(hash);
|
||||||
const block = Block.fromHex(rawBlock);
|
const block = Block.fromBuffer(rawBlock);
|
||||||
const txMap = {};
|
const txMap = {};
|
||||||
for (const tx of block.transactions || []) {
|
for (const tx of block.transactions || []) {
|
||||||
txMap[tx.getId()] = tx;
|
txMap[tx.getId()] = tx;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user