Skip to content

Commit

Permalink
fix estimateFee for BCH and paging options
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Sep 21, 2018
1 parent d99bab1 commit 823a70a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/bitcore-node/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@ 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 @@ -300,10 +300,12 @@ 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;
}
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 Expand Up @@ -336,7 +338,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
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
19 changes: 12 additions & 7 deletions packages/bitcore-node/src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,29 @@ 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 &&
if ( originalOptions.paging &&
this.validPagingProperty(model, originalOptions.paging)
) {
options.since = this.typecastForDb(model, originalOptions.paging, originalOptions.since);
//if (originalOptions.since !== undefined) {
// options.since = this.typecastForDb(model, originalOptions.paging, originalOptions.since);
//}
if (originalOptions.direction && Number(originalOptions.direction) === 1) {
query[originalOptions.paging] = { $gt: originalOptions.since };
if (originalOptions.since !== undefined) {
query[originalOptions.paging] = { $gt: originalOptions.since };
}
options.sort = { [originalOptions.paging]: 1 };
} else {
query[originalOptions.paging] = { $lt: originalOptions.since };
if (originalOptions.since !== undefined) {
query[originalOptions.paging] = { $lt: originalOptions.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 @@ -148,6 +152,7 @@ export class StorageService {
) {
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 823a70a

Please sign in to comment.