fix(createOffer()): Prevening duplicate Offers from being created

This commit is contained in:
Chris Troutner
2022-03-26 20:31:34 -07:00
parent 470fa95b74
commit f9e76a3dfb
3 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ class Adapters {
// Open the wallet file
const walletData = await this.wallet.openWallet()
console.log('walletData: ', walletData)
// console.log('walletData: ', walletData)
// Instance the wallet.
await this.wallet.instanceWallet(walletData, this.bchjs)
+8
View File
@@ -46,6 +46,14 @@ class OfferUseCases {
try {
console.log('Use Case createOffer(offerObj): ', offerObj)
// Return if Offer already exists in database with the same P2WDB CID.
try {
await this.findOfferByHash(offerObj.hash)
console.log('Offer already found in local database.')
return false
} catch (err) { /* exit quietly */ }
// console.log('this.adapters.bchjs: ', this.adapters.bchjs)
// Input Validation
+4
View File
@@ -35,11 +35,15 @@ class OrderLib {
console.log('entryObj.makerAddr: ', entryObj.makerAddr)
// Get Ticker for token ID.
// TODO: Move this below the orderEntity.validate() call.
const tokenData = await this.adapters.wallet.bchWallet.getTxData([entryObj.tokenId])
// console.log(`tokenData: ${JSON.stringify(tokenData, null, 2)}`)
entryObj.ticker = tokenData[0].tokenTicker
// Input Validation
// TODO: Remove ticker from validation.
// TODO: Rename validate() to inputValidate(). Create fullValidate() that
// validates a fully hydrated Order entity.
const orderEntity = this.orderEntity.validate(entryObj)
console.log('orderEntity: ', orderEntity)