mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Adding operator fee to Offer use case, entity, and database model
This commit is contained in:
@@ -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)
|
||||
|
||||
+11
-1
@@ -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()
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user