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>;
 | 
			
		||||
  $getBlockHeader(hash: string): Promise<string>;
 | 
			
		||||
  $getBlock(hash: string): Promise<IEsploraApi.Block>;
 | 
			
		||||
  $getRawBlock(hash: string): Promise<string>;
 | 
			
		||||
  $getRawBlock(hash: string): Promise<Buffer>;
 | 
			
		||||
  $getAddress(address: string): Promise<IEsploraApi.Address>;
 | 
			
		||||
  $getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]>;
 | 
			
		||||
  $getAddressPrefix(prefix: string): string[];
 | 
			
		||||
 | 
			
		||||
@ -81,7 +81,7 @@ class BitcoinApi implements AbstractBitcoinApi {
 | 
			
		||||
      .then((rpcBlock: IBitcoinApi.Block) => rpcBlock.tx);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $getRawBlock(hash: string): Promise<string> {
 | 
			
		||||
  $getRawBlock(hash: string): Promise<Buffer> {
 | 
			
		||||
    return this.bitcoindClient.getBlock(hash, 0)
 | 
			
		||||
      .then((raw: string) => Buffer.from(raw, "hex"));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -55,9 +55,9 @@ class ElectrsApi implements AbstractBitcoinApi {
 | 
			
		||||
      .then((response) => response.data);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $getRawBlock(hash: string): Promise<string> {
 | 
			
		||||
    return axios.get<string>(config.ESPLORA.REST_API_URL + '/block/' + hash + "/raw", this.axiosConfig)
 | 
			
		||||
      .then((response) => response.data);
 | 
			
		||||
  $getRawBlock(hash: string): Promise<Buffer> {
 | 
			
		||||
    return axios.get<string>(config.ESPLORA.REST_API_URL + '/block/' + hash + "/raw", { ...this.axiosConfig, responseType: 'arraybuffer' })
 | 
			
		||||
      .then((response) => { return Buffer.from(response.data); });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $getAddress(address: string): Promise<IEsploraApi.Address> {
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user