Source: models/utxoModel.js

  1. /**
  2. * @fileoverview UTXO Model for Satoshi Showdown.
  3. * This model defines the structure and constraints for UTXOs on the platform.
  4. *
  5. *
  6. * @module models/UTXO
  7. * @requires mongoose - Mongoose library for MongoDB object modeling, offering schema definition and data validation.
  8. */
  9. const mongoose = require("mongoose");
  10. /**
  11. * UTXO Schema definition for Satoshi Showdown.
  12. * Represents Unspent Transaction Output (UTXO) data, crucial for tracking and managing cryptocurrency transactions.
  13. * Includes references to users, events, and wallets, along with key transactional data like address, amount, and blockchain information.
  14. *
  15. * @typedef {Object} UTXOSchema
  16. * @property {mongoose.Schema.Types.ObjectId} userRef - Reference to the User model, linking the UTXO to a specific user.
  17. * @property {mongoose.Schema.Types.ObjectId} eventRef - Reference to the Event model, associating the UTXO with a particular event.
  18. * @property {string} address - Address owning the UTXO.
  19. * @property {number} amount - Amount of cryptocurrency (in satoshis) represented by this UTXO.
  20. * @property {string} transactionHash - Hash of the transaction where this UTXO originated.
  21. * @property {number} outputIndex - Output index in the transaction (vout).
  22. * @property {string} scriptPubKey - ScriptPubKey for the output, defining how the UTXO can be spent.
  23. * @property {string} scriptType - Type of script, e.g., 'pay-to-pubkey-hash'.
  24. * @property {number} blockHeight - Block height at which this UTXO was mined (optional).
  25. * @property {Date} timestamp - Timestamp of when the transaction was confirmed.
  26. * @property {boolean} spent - Indicates if the UTXO has been spent.
  27. * @property {string} spendingTxHash - Transaction hash that spent this UTXO (if spent).
  28. * @property {boolean} refund - Marks the UTXO as part of a refund (optional).
  29. * @property {string} refundTxHash - Reference to the transaction that refunded this UTXO (if applicable).
  30. * @property {string} keyPath - HD wallet key path for this UTXO (optional).
  31. *
  32. * @type {mongoose.Schema}
  33. */
  34. const UTXOSchema = new mongoose.Schema(
  35. {
  36. userRef: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
  37. eventRef: { type: mongoose.Schema.Types.ObjectId, ref: "Event" },
  38. txRef: { type: mongoose.Schema.Types.ObjectId, ref: "Transaction" },
  39. address: { type: String, required: true },
  40. amount: { type: Number, required: true },
  41. transactionHash: { type: String, required: true },
  42. outputIndex: { type: Number, required: true },
  43. scriptPubKey: { type: String, required: true },
  44. scriptType: { type: String, required: true },
  45. blockHeight: Number,
  46. timestamp: Date,
  47. spent: { type: Boolean, default: false },
  48. spendingTxHash: String,
  49. refund: { type: Boolean, default: false },
  50. refundTxHash: String,
  51. keyPath: { type: String, required: false },
  52. },
  53. { timestamps: true }
  54. );
  55. const UTXO = mongoose.model("UTXO", UTXOSchema);
  56. module.exports = UTXO;