"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalletStorage = exports.WalletModel = void 0;
const walletAddress_1 = require("../models/walletAddress");
const base_1 = require("./base");
class WalletModel extends base_1.BaseModel {
    constructor(storage) {
        super('wallets', storage);
        this.allowedPaging = [];
    }
    onConnect() {
        this.collection.createIndex({ pubKey: 1 }, { background: true });
    }
    _apiTransform(wallet, options) {
        const transform = { name: wallet.name, pubKey: wallet.pubKey };
        if (options && options.object) {
            return transform;
        }
        return JSON.stringify(transform);
    }
    async updateCoins(wallet) {
        const addressModels = await walletAddress_1.WalletAddressStorage.collection
            .find({ wallet: wallet._id })
            .addCursorFlag('noCursorTimeout', true)
            .toArray();
        const addresses = addressModels.map(model => model.address);
        return walletAddress_1.WalletAddressStorage.updateCoins({ wallet, addresses });
    }
}
exports.WalletModel = WalletModel;
exports.WalletStorage = new WalletModel();
//# sourceMappingURL=wallet.js.map