Skip to content

Commit 51ccf3f

Browse files
author
Micah Riggan
committed
fix(node): removing confirmations
Confirmations should be calculated client side by doing tip.height - item.blockHeight
1 parent 8a9050a commit 51ccf3f

File tree

1 file changed

+6
-44
lines changed
  • packages/bitcore-node/src/providers/chain-state/internal

1 file changed

+6
-44
lines changed

packages/bitcore-node/src/providers/chain-state/internal/internal.ts

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TransactionJSON } from "../../../types/Transaction";
1+
import { TransactionJSON } from '../../../types/Transaction';
22
import config from '../../../config';
33
import through2 from 'through2';
44

@@ -12,7 +12,7 @@ import { CSP } from '../../../types/namespaces/ChainStateProvider';
1212
import { Storage } from '../../../services/storage';
1313
import { RPC } from '../../../rpc';
1414
import { LoggifyClass } from '../../../decorators/Loggify';
15-
import { TransactionModel, ITransaction } from '../../../models/transaction';
15+
import { TransactionModel } from '../../../models/transaction';
1616
import { ListTransactionsStream } from './transforms';
1717
import { StringifyJsonStream } from '../../../utils/stringifyJsonStream';
1818
import { StateModel } from '../../../models/state';
@@ -86,18 +86,7 @@ export class InternalStateProvider implements CSP.IChainStateService {
8686
if (options.sort) {
8787
cursor = cursor.sort(options.sort);
8888
}
89-
let blocks = await cursor.toArray();
90-
const tip = await this.getLocalTip(params);
91-
const tipHeight = tip ? tip.height : 0;
92-
const blockTransform = (b: IBlock) => {
93-
let confirmations = 0;
94-
if (b.height && b.height >= 0) {
95-
confirmations = tipHeight - b.height + 1;
96-
}
97-
const convertedBlock = BlockModel._apiTransform(b, { object: true }) as IBlock;
98-
return { ...convertedBlock, confirmations };
99-
};
100-
return blocks.map(blockTransform);
89+
return cursor.toArray();
10190
}
10291

10392
private getBlocksQuery(params: CSP.GetBlockParams | CSP.StreamBlocksParams) {
@@ -167,16 +156,7 @@ export class InternalStateProvider implements CSP.IChainStateService {
167156
if (blockHash !== undefined) {
168157
query.blockHash = blockHash;
169158
}
170-
const tip = await this.getLocalTip(params);
171-
const tipHeight = tip ? tip.height : 0;
172-
return Storage.apiStreamingFind(TransactionModel, query, args, req, res, t => {
173-
let confirmations = 0;
174-
if (t.blockHeight !== undefined && t.blockHeight >= 0) {
175-
confirmations = tipHeight - t.blockHeight + 1;
176-
}
177-
const convertedTx = TransactionModel._apiTransform(t, { object: true }) as Partial<ITransaction>;
178-
return JSON.stringify({ ...convertedTx, confirmations: confirmations });
179-
});
159+
return Storage.apiStreamingFind(TransactionModel, query, args, req, res);
180160
}
181161

182162
async getTransaction(params: CSP.StreamTransactionParams) {
@@ -186,16 +166,9 @@ export class InternalStateProvider implements CSP.IChainStateService {
186166
}
187167
network = network.toLowerCase();
188168
let query = { chain: chain, network, txid: txId };
189-
const tip = await this.getLocalTip(params);
190-
const tipHeight = tip ? tip.height : 0;
191169
const found = await TransactionModel.collection.findOne(query);
192170
if (found) {
193-
let confirmations = 0;
194-
if (found.blockHeight && found.blockHeight >= 0) {
195-
confirmations = tipHeight - found.blockHeight + 1;
196-
}
197-
const convertedTx = TransactionModel._apiTransform(found, { object: true }) as TransactionJSON;
198-
return { ...convertedTx, confirmations: confirmations };
171+
return TransactionModel._apiTransform(found, { object: true }) as TransactionJSON;
199172
} else {
200173
return undefined;
201174
}
@@ -368,18 +341,7 @@ export class InternalStateProvider implements CSP.IChainStateService {
368341
if (args.includeSpent !== 'true') {
369342
query.spentHeight = { $lt: SpentHeightIndicators.pending };
370343
}
371-
const tip = await this.getLocalTip(params);
372-
const tipHeight = tip ? tip.height : 0;
373-
const utxoTransform = (c: ICoin): string => {
374-
let confirmations = 0;
375-
if (c.mintHeight && c.mintHeight >= 0) {
376-
confirmations = tipHeight - c.mintHeight + 1;
377-
}
378-
c.confirmations = confirmations;
379-
return CoinModel._apiTransform(c) as string;
380-
};
381-
382-
Storage.apiStreamingFind(CoinModel, query, { limit }, req, res, utxoTransform);
344+
Storage.apiStreamingFind(CoinModel, query, { limit }, req, res);
383345
}
384346

385347
async getFee(params: CSP.GetEstimateSmartFeeParams) {

0 commit comments

Comments
 (0)