diff --git a/packages/bitcore-node/src/providers/chain-state/internal/internal.ts b/packages/bitcore-node/src/providers/chain-state/internal/internal.ts index 77f3fe2f34e..7e39d470de7 100644 --- a/packages/bitcore-node/src/providers/chain-state/internal/internal.ts +++ b/packages/bitcore-node/src/providers/chain-state/internal/internal.ts @@ -306,9 +306,9 @@ export class InternalStateProvider implements CSP.IChainStateService { finalQuery.blockTimeNormalized.$lt = new Date(args.endDate); } } - const { query, options } = Storage.getFindOptions(TransactionModel, args); - finalQuery = Object.assign({}, finalQuery, query); - finalOptions = options; + //const { query, options } = Storage.getFindOptions(TransactionModel, args); + //finalQuery = Object.assign({}, finalQuery, query); + finalOptions = args; } let transactionStream = TransactionModel.getTransactions({ query: finalQuery, options: finalOptions }); let listTransactionsStream = new ListTransactionsStream(wallet); @@ -342,7 +342,11 @@ export class InternalStateProvider implements CSP.IChainStateService { async getFee(params: CSP.GetEstimateSmartFeeParams) { const { chain, network, target } = params; - return this.getRPC(chain, network).getEstimateSmartFee(Number(target)); + if (chain === 'BCH') { + return this.getRPC(chain, network).getEstimateFee(Number(target)); + } else { + return this.getRPC(chain, network).getEstimateSmartFee(Number(target)); + } } async broadcastTransaction(params: CSP.BroadcastTransactionParams) { diff --git a/packages/bitcore-node/src/providers/chain-state/internal/transforms.ts b/packages/bitcore-node/src/providers/chain-state/internal/transforms.ts index d86de083e79..f6962b11072 100644 --- a/packages/bitcore-node/src/providers/chain-state/internal/transforms.ts +++ b/packages/bitcore-node/src/providers/chain-state/internal/transforms.ts @@ -61,6 +61,7 @@ export class ListTransactionsStream extends Transform { if (!sendingToOurself) { self.push( JSON.stringify({ + id: transaction._id, txid: transaction.txid, fee: transaction.fee, size: transaction.size, @@ -75,6 +76,7 @@ export class ListTransactionsStream extends Transform { } else { self.push( JSON.stringify({ + id: transaction._id, txid: transaction.txid, fee: transaction.fee, size: transaction.size, @@ -91,6 +93,7 @@ export class ListTransactionsStream extends Transform { if (fee > 0) { self.push( JSON.stringify({ + id: transaction._id, txid: transaction.txid, category: 'fee', satoshis: -fee, @@ -111,6 +114,7 @@ export class ListTransactionsStream extends Transform { if (weReceived) { self.push( JSON.stringify({ + id: transaction._id, txid: transaction.txid, fee: transaction.fee, size: transaction.size, diff --git a/packages/bitcore-node/src/rpc.ts b/packages/bitcore-node/src/rpc.ts index c676b78cb1d..4437fe46b79 100644 --- a/packages/bitcore-node/src/rpc.ts +++ b/packages/bitcore-node/src/rpc.ts @@ -109,6 +109,12 @@ export class RPC { async getEstimateSmartFee(target: number) { return this.asyncCall('estimatesmartfee', [target]); } + + + async getEstimateFee(target: number) { + return this.asyncCall('estimatefee', [target]); + } + } @LoggifyClass diff --git a/packages/bitcore-node/src/services/storage.ts b/packages/bitcore-node/src/services/storage.ts index 8e586e5ccea..e8669b364e4 100644 --- a/packages/bitcore-node/src/services/storage.ts +++ b/packages/bitcore-node/src/services/storage.ts @@ -4,6 +4,7 @@ import { TransformableModel } from '../types/TransformableModel'; import logger from '../logger'; import config from '../config'; import { LoggifyClass } from '../decorators/Loggify'; +import { ObjectID } from 'bson'; import { MongoClient, Db, Cursor } from 'mongodb'; import { MongoBound } from '../models/base'; import '../models'; @@ -87,6 +88,9 @@ export class StorageService { typecastedValue = new Date(oldValue) as any; break; } + // TODO: Micah check this! + } else if (modelKey == "_id") { + typecastedValue = new ObjectID(oldValue) as any; } } return typecastedValue; @@ -117,21 +121,28 @@ export class StorageService { res.end(); }); } - getFindOptions(model: TransformableModel, originalOptions: StreamingFindOptions) { let options: StreamingFindOptions = {}; - let query: any = {}; - if ( - originalOptions.since !== undefined && - originalOptions.paging && + let query: any = {}, since: any; + if ( originalOptions.paging && this.validPagingProperty(model, originalOptions.paging) ) { - options.since = this.typecastForDb(model, originalOptions.paging, originalOptions.since); + + + if (originalOptions.since !== undefined) { + since = this.typecastForDb(model, originalOptions.paging, originalOptions.since); + } + + if (originalOptions.direction && Number(originalOptions.direction) === 1) { - query[originalOptions.paging] = { $gt: originalOptions.since }; + if (since) { + query[originalOptions.paging] = { $gt: since }; + } options.sort = { [originalOptions.paging]: 1 }; } else { - query[originalOptions.paging] = { $lt: originalOptions.since }; + if (since) { + query[originalOptions.paging] = { $lt: since }; + } options.sort = { [originalOptions.paging]: -1 }; } }