From 19ba38e8cedbd26591bb1a9fa599cdd3fde574e8 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 9 Aug 2025 15:08:31 -0700 Subject: [PATCH] Adding operator fee to Offer use case, entity, and database model --- src/adapters/localdb/models/offer.js | 5 ++++- src/entities/offer.js | 12 +++++++++++- src/use-cases/offer/index.js | 5 ++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/adapters/localdb/models/offer.js b/src/adapters/localdb/models/offer.js index 5b1a375..69358d9 100644 --- a/src/adapters/localdb/models/offer.js +++ b/src/adapters/localdb/models/offer.js @@ -35,8 +35,11 @@ const Offer = new mongoose.Schema({ lokadId: { type: String }, messageType: { type: Number }, messageClass: { type: Number }, - nostrEventId: { type: String } // Nostr Event Id. + nostrEventId: { type: String }, // Nostr Event Id. + // Operator fee and address + operatorAddress: { type: String }, + operatorPercentage: { type: Number } }) export default mongoose.model('offer', Offer) diff --git a/src/entities/offer.js b/src/entities/offer.js index 313548b..55d7428 100644 --- a/src/entities/offer.js +++ b/src/entities/offer.js @@ -33,7 +33,9 @@ class OfferEntity { makerAddr, ticker, tokenType, - nostrEventId + nostrEventId, + operatorAddress, + operatorPercentage } = offerData.data // Input Validation @@ -80,6 +82,14 @@ class OfferEntity { throw new Error("Property 'nostrEventId' must be a string.") } + // Add the operator address and percentage to the offer. + if (!operatorAddress || typeof operatorAddress !== 'string') { + throw new Error("Property 'operatorAddress' must be a string.") + } + if (!operatorPercentage || typeof operatorPercentage !== 'number') { + throw new Error("Property 'operatorPercentage' must be a number.") + } + // Convert the timestamp to a number. let timestamp = new Date(offerData.timestamp) timestamp = timestamp.getTime() diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index c8f4ce2..ab80bb1 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -111,7 +111,10 @@ class OfferUseCases { const utxoStatus = await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.utxoIsValid, utxo) // console.log('utxoStatus: ', utxoStatus) // if (utxoStatus === null) return false - if (!utxoStatus) return false + if (!utxoStatus) { + console.log(`UTXO txid: ${offerObj.data.utxoTxid}, vout: ${offerObj.data.utxoVout} has been spent. Skipping.`) + return false + } // A new offer gets a status of 'posted' offerObj.data.offerStatus = 'posted'