43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const Input = require('./input');
|
|
const Output = require('./output');
|
|
const logger = require('../lib/logger');
|
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
const TransactionSchema = new Schema({
|
|
hash: { type: String, default: '' },
|
|
witnessHash: { type: String, default: '' },
|
|
fee: { type: Number, default: 0 },
|
|
rate: { type: Number, default: 0 },
|
|
ps: { type: Number, default: 0 },
|
|
height: { type: Number, default: 0 },
|
|
block: { type: String, default: '' },
|
|
index: { type: Number, default: 0 },
|
|
version: { type: Number, default: 0 },
|
|
flag: { type: Number, default: 0 },
|
|
lockTime: { type: Number, default: 0 },
|
|
inputs: [Input.schema],
|
|
outputs: [Output.schema],
|
|
size: { type: Number, default: 0 },
|
|
network: { type: String, default: '' },
|
|
});
|
|
|
|
TransactionSchema.index({ hash: 1 });
|
|
|
|
TransactionSchema.methods.byId = function txById(txid, cb) {
|
|
return this.model('Transaction').findOne(
|
|
{ hash: txid },
|
|
(err, tx) => {
|
|
if (err) {
|
|
logger.log('error',
|
|
`TransactionSchema.methods.byId: ${err}`);
|
|
return cb(err);
|
|
}
|
|
return cb(null, tx);
|
|
});
|
|
};
|
|
|
|
|
|
module.exports = mongoose.model('Transaction', TransactionSchema);
|