Skip to content

Commit 0980b3d

Browse files
authored
Merge pull request bitpay#2055 from micahriggan/fix/mongo-compile-error
Making the options param optional for api transform
2 parents f036a7a + bc1cc96 commit 0980b3d

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

packages/bitcore-node/package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bitcore-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@types/express": "^4.11.1",
5050
"@types/lodash": "^4.14.116",
5151
"@types/mocha": "^5.2.0",
52-
"@types/mongodb": "^3.1.19",
52+
"@types/mongodb": "^3.1.22",
5353
"@types/mongoose": "^5.0.11",
5454
"@types/node": "10.0.2",
5555
"@types/request": "^2.47.0",

packages/bitcore-node/src/models/block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class BlockModel extends BaseModel<IBlock> {
219219
return true;
220220
}
221221

222-
_apiTransform(block: Partial<MongoBound<IBlock>>, options: TransformOptions): any {
222+
_apiTransform(block: Partial<MongoBound<IBlock>>, options?: TransformOptions): any {
223223
const transform = {
224224
_id: block._id,
225225
chain: block.chain,

packages/bitcore-node/src/models/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export class TransactionModel extends BaseModel<ITransaction> {
521521
return this.collection.find(finalQuery, options).addCursorFlag('noCursorTimeout', true);
522522
}
523523

524-
_apiTransform(tx: Partial<MongoBound<ITransaction>>, options: TransformOptions): TransactionJSON | string {
524+
_apiTransform(tx: Partial<MongoBound<ITransaction>>, options?: TransformOptions): TransactionJSON | string {
525525
const transaction: TransactionJSON = {
526526
_id: tx._id ? tx._id.toString() : '',
527527
txid: tx.txid || '',

packages/bitcore-node/src/models/wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class WalletModel extends BaseModel<IWallet> {
2424
this.collection.createIndex({ pubKey: 1 }, { background: true });
2525
}
2626

27-
_apiTransform(wallet: IWallet, options: TransformOptions) {
27+
_apiTransform(wallet: IWallet, options?: TransformOptions) {
2828
let transform = { name: wallet.name, pubKey: wallet.pubKey };
2929
if (options && options.object) {
3030
return transform;

packages/bitcore-node/src/models/walletAddress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class WalletAddressModel extends BaseModel<IWalletAddress> {
2828
this.collection.createIndex({ chain: 1, network: 1, wallet: 1, address: 1 }, { background: true, unique: true });
2929
}
3030

31-
_apiTransform(walletAddress: { address: string }, options: TransformOptions) {
31+
_apiTransform(walletAddress: { address: string }, options?: TransformOptions) {
3232
let transform = { address: walletAddress.address };
3333
if (options && options.object) {
3434
return transform;
@@ -101,7 +101,7 @@ export class WalletAddressModel extends BaseModel<IWalletAddress> {
101101
})
102102
),
103103
{ ordered: false };
104-
104+
105105
} catch (err) {
106106
// Ignore duplicate keys, they may be half processed
107107
if (err.code !== 11000) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TransformOptions } from "./TransformOptions";
22
import { BaseModel, MongoBound } from "../models/base";
3-
type TransformProperty<T> = {_apiTransform: (model: T | MongoBound<T>, options: TransformOptions) => any};
3+
type TransformProperty<T> = {_apiTransform: (model: T | MongoBound<T>, options?: TransformOptions) => any};
44
export type TransformableModel<T> = BaseModel<T> & TransformProperty<T>;
55

packages/bitcore-node/test/verification/db-verify.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type ErrorType = {
2121
export async function validateDataForBlock(blockNum: number, log = false) {
2222
let success = true;
2323
const blockTxs = await TransactionStorage.collection.find({ chain, network, blockHeight: blockNum }).toArray();
24+
const blockTxids = blockTxs.map(t => t.txid);
25+
const coinsForTx = await CoinStorage.collection.find({ chain, network, mintTxid: { $in: blockTxids } }).toArray();
26+
2427
const seenTxs = {} as { [txid: string]: ITransaction };
2528
const errors = new Array<ErrorType>();
2629

@@ -46,9 +49,6 @@ export async function validateDataForBlock(blockNum: number, log = false) {
4649
}
4750
}
4851

49-
const blockTxids = blockTxs.map(t => t.txid);
50-
51-
const coinsForTx = await CoinStorage.collection.find({ chain, network, mintTxid: { $in: blockTxids } }).toArray();
5252
for (let coin of coinsForTx) {
5353
if (seenTxCoins[coin.mintTxid] && seenTxCoins[coin.mintTxid][coin.mintIndex]) {
5454
success = false;

0 commit comments

Comments
 (0)