diff --git a/config/env/common.js b/config/env/common.js index 9f55345..58f058c 100644 --- a/config/env/common.js +++ b/config/env/common.js @@ -191,5 +191,9 @@ export default { disableNewAccounts: process.env.DISABLE_NEW_ACCOUNTS ? true : false, // Admin password - adminPassword: process.env.ADMIN_PASSWORD + adminPassword: process.env.ADMIN_PASSWORD, + + // The Operator of BCH DEX can elect to receive a percentage of each sale. + operatorAddress: process.env.OPERATOR_ADDRESS ? process.env.OPERATOR_ADDRESS : 'bitcoincash:qqsrke9lh257tqen99dkyy2emh4uty0vky9y0z0lsr', + operatorPercentage: process.env.OPERATOR_PERCENTAGE ? parseFloat(process.env.OPERATOR_PERCENTAGE) : 2.0 } diff --git a/src/adapters/localdb/models/order.js b/src/adapters/localdb/models/order.js index fd0651f..0f38c1c 100644 --- a/src/adapters/localdb/models/order.js +++ b/src/adapters/localdb/models/order.js @@ -43,7 +43,11 @@ const Order = new mongoose.Schema({ // Additional properties found in createOrder dataType: { type: String, required: true }, - userId: { type: String, required: true } + userId: { type: String, required: true }, + + // Operator fee and address + operatorAddress: { type: String }, + operatorPercentage: { type: Number } }) export default mongoose.model('order', Order) diff --git a/src/use-cases/order.js b/src/use-cases/order.js index ff31bf8..a75d0b1 100644 --- a/src/use-cases/order.js +++ b/src/use-cases/order.js @@ -44,6 +44,7 @@ class OrderLib { if (!entryObj.tokenId) throw new Error('entry does not contain required properties') + // Get the user data from the database, for the user creating the new Order. const user = await this.UserModel.findById(entryObj.userId) if (!user) throw new Error('user not found') @@ -81,13 +82,7 @@ class OrderLib { // await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.optimize, {}) await userWallet.optimize() - // Ensure sufficient tokens exist to create the order. - // await this.ensureFunds(orderEntity) - // await this.retryQueue.addToQueue(this.ensureFunds, orderEntity) - // Get Ticker for token ID. - // const tokenData = await this.adapters.wallet.bchWallet.getTxData([entryObj.tokenId]) - // const tokenData = await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.getTxData, [entryObj.tokenId]) const tokenData = await userWallet.getTxData([entryObj.tokenId]) // console.log(`tokenData: ${JSON.stringify(tokenData, null, 2)}`) orderEntity.ticker = tokenData[0].tokenTicker @@ -107,15 +102,20 @@ class OrderLib { // await this.adapters.wallet.bchWallet.getUtxos() // await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.initialize, {}) await userWallet.initialize() + // Update the order with the new UTXO information. orderEntity.utxoTxid = utxoInfo.txid orderEntity.utxoVout = utxoInfo.vout orderEntity.tokenType = utxoInfo.tokenType - // Add P2WDB specific flag for signaling that this is a new offer. + // Add flag to signal that this is a new offer. orderEntity.dataType = 'offer' orderEntity.userId = user._id + // Add the operator address and percentage to the order. + orderEntity.operatorAddress = this.config.operatorAddress + orderEntity.operatorPercentage = this.config.operatorPercentage + // Post the new Order information to Nostr under the topic set in the // config file. const postObj = {