Skip to content

Commit

Permalink
add _id to transactions results + fix typecast on paging
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Sep 21, 2018
1 parent 823a70a commit 910ce72
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 0 additions & 3 deletions packages/bitcore-node/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,9 @@ export class Transaction extends BaseModel<ITransaction> {
}

getTransactions(params: { query: any; options: StreamingFindOptions<ITransaction> }) {
console.log('[transaction.ts.316:params:]',params); //TODO
let originalQuery = params.query;
const { query, options } = Storage.getFindOptions(this, params.options);
const finalQuery = Object.assign({}, originalQuery, query);
console.log('[transaction.ts.321:finalQuery:]',finalQuery); //TODO
console.log('[transaction.ts.321:options:]',options); //TODO
return this.collection.find(finalQuery, options).addCursorFlag('noCursorTimeout', true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ export class InternalStateProvider implements CSP.IChainStateService {
//finalQuery = Object.assign({}, finalQuery, query);
finalOptions = args;
}
console.log('[internal.ts.307:finalQuery:]',finalQuery); //TODO
console.log('[internal.ts.308:finalOptions:]',finalOptions); //TODO
let transactionStream = TransactionModel.getTransactions({ query: finalQuery, options: finalOptions });
let listTransactionsStream = new ListTransactionsStream(wallet);
transactionStream.pipe(listTransactionsStream).pipe(stream);
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
26 changes: 16 additions & 10 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 @@ -119,27 +123,30 @@ export class StorageService {
}
getFindOptions<T>(model: TransformableModel<T>, originalOptions: StreamingFindOptions<T>) {
let options: StreamingFindOptions<T> = {};
let query: any = {};
let query: any = {}, since: any;
if ( originalOptions.paging &&
this.validPagingProperty(model, originalOptions.paging)
) {
//if (originalOptions.since !== undefined) {
// 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) {
if (originalOptions.since !== undefined) {
query[originalOptions.paging] = { $gt: originalOptions.since };
if (since) {
query[originalOptions.paging] = { $gt: since };
}
options.sort = { [originalOptions.paging]: 1 };
} else {
if (originalOptions.since !== undefined) {
query[originalOptions.paging] = { $lt: originalOptions.since };
if (since) {
query[originalOptions.paging] = { $lt: since };
}
options.sort = { [originalOptions.paging]: -1 };
}
}
options.limit = Math.min(originalOptions.limit || 100, 1000);
console.log('[storage.ts.138:options:]',options); //TODO
return { query, options };
}

Expand All @@ -152,7 +159,6 @@ console.log('[storage.ts.138:options:]',options); //TODO
) {
const { query, options } = this.getFindOptions(model, originalOptions);
const finalQuery = Object.assign({}, originalQuery, query);
console.log('[storage.ts.153:options:]',options); //TODO
let cursor = model.collection.find(finalQuery, options).stream({
transform: transform || model._apiTransform
});
Expand Down

0 comments on commit 910ce72

Please sign in to comment.