mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Got /order/take mocked up for further development
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
local Offers are no different than Orders generated by other peers.
|
||||
*/
|
||||
|
||||
// Local libraries
|
||||
const OrderEntity = require('../../entities/order')
|
||||
const config = require('../../../config')
|
||||
|
||||
class OrderUseCases {
|
||||
constructor (localConfig = {}) {
|
||||
@@ -20,6 +22,9 @@ class OrderUseCases {
|
||||
)
|
||||
}
|
||||
|
||||
// Encapsulate dependencies
|
||||
this.config = config
|
||||
|
||||
this.orderEntity = new OrderEntity()
|
||||
this.OrderModel = this.adapters.localdb.Order
|
||||
}
|
||||
@@ -105,15 +110,34 @@ class OrderUseCases {
|
||||
const utxos = this.adapters.wallet.bchWallet.utxos.utxoStore
|
||||
console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
|
||||
|
||||
// TODO: Move funds to create a segrated UTXO for taking the order
|
||||
|
||||
// Create a partially signed transaction.
|
||||
// https://github.com/Permissionless-Software-Foundation/bch-js-examples/blob/master/bch/applications/collaborate/sell-slp/e2e-exchange/step2-purchase-tx.js#L59
|
||||
const partialTxHex = await this.adapters.wallet.generatePartialTx(orderInfo)
|
||||
// return partialTxHex
|
||||
|
||||
return partialTxHex
|
||||
// Create valid Order object
|
||||
const takenOrderInfo = Object.assign({}, orderInfo)
|
||||
takenOrderInfo.patialTxHex = partialTxHex
|
||||
delete takenOrderInfo.p2wdbHash
|
||||
delete takenOrderInfo._id
|
||||
takenOrderInfo.offerHash = orderInfo.p2wdbHash
|
||||
|
||||
// return true
|
||||
// Write order info to the P2WDB
|
||||
// TODO: This will trigger the webhook. Find some way of triggering the
|
||||
// webhook on new orders, but not on counteroffers
|
||||
const p2wdbObj = {
|
||||
wif: this.adapters.wallet.bchWallet.walletInfo.privateKey,
|
||||
data: takenOrderInfo,
|
||||
appId: this.config.p2wdbAppId
|
||||
}
|
||||
const hash = await this.adapters.p2wdb.write(p2wdbObj)
|
||||
|
||||
// Return the P2WDB CID
|
||||
return hash
|
||||
} catch (err) {
|
||||
console.error('Error in use-cases/order/takeOrder()')
|
||||
console.error('Error in use-cases/order/takeOrder(): ', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -125,6 +149,8 @@ class OrderUseCases {
|
||||
// console.log('this.adapters.wallet: ', this.adapters.wallet.bchWallet)
|
||||
// console.log(`walletInfo: ${JSON.stringify(this.adapters.wallet.bchWallet.walletInfo, null, 2)}`)
|
||||
|
||||
await this.adapters.wallet.bchWallet.walletInfoPromise
|
||||
|
||||
// Ensure the app wallet has enough funds to write to the P2WDB.
|
||||
const wif = this.adapters.wallet.bchWallet.walletInfo.privateKey
|
||||
const canWriteToP2WDB = await this.adapters.p2wdb.checkForSufficientFunds(wif)
|
||||
|
||||
Reference in New Issue
Block a user