UNPKG

machinomy

Version:

Micropayments powered by Ethereum

40 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const pify_1 = require("../../util/pify"); const payment_1 = require("../../payment"); const AbstractPaymentsDatabase_1 = require("../AbstractPaymentsDatabase"); class NedbPaymentsDatabase extends AbstractPaymentsDatabase_1.default { async save(token, payment) { const serialized = payment_1.PaymentSerde.instance.serialize(payment); serialized.kind = this.kind; serialized.token = token; serialized.createdAt = Date.now(); // log.info(`Saving payment for channel ${payment.channelId} and token ${token}`) await this.engine.exec(client => client.insert(serialized)); } /** * Find a payment with maximum value on it inside the channel. */ async firstMaximum(channelId) { // log.info(`Trying to find last payment for channel ${channelId.toString()}`) let query = { kind: this.kind, channelId: channelId.toString() }; let raw = await this.engine.exec(client => { return pify_1.default((cb) => { client.datastore.find(query).sort({ value: -1 }).limit(1).exec(cb); }); }); return this.inflatePayment(raw[0]); } /** * Find a payment by token. */ async findByToken(token) { let query = { kind: this.kind, token: token }; let raw = await this.engine.exec(client => { return client.findOne(query); }); return this.inflatePayment(raw); } } exports.default = NedbPaymentsDatabase; //# sourceMappingURL=NedbPaymentsDatabase.js.map