Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/paging #1717

Merged
merged 2 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ export class InternalStateProvider implements CSP.IChainStateService {
finalQuery.blockTimeNormalized = finalQuery.blockTimeNormalized || {};
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 @@ -336,7 +336,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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, does BCH not like estimateSmartFee?

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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me, I think since we're making this property a special case, having it this way is pretty clear

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