Skip to content

Commit

Permalink
Merge pull request bitpay#1717 from matiu/bug/paging
Browse files Browse the repository at this point in the history
Bug/paging
  • Loading branch information
micahriggan authored Sep 24, 2018
2 parents 2eb09ab + 910ce72 commit a9720c0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions packages/bitcore-node/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions packages/bitcore-node/src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -117,21 +121,28 @@ export class StorageService {
res.end();
});
}

getFindOptions<T>(model: TransformableModel<T>, originalOptions: StreamingFindOptions<T>) {
let options: StreamingFindOptions<T> = {};
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 };
}
}
Expand Down

0 comments on commit a9720c0

Please sign in to comment.