From f9e76a3dfbf8803ea7e2dabf83bf041bb554118e Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 26 Mar 2022 20:31:34 -0700 Subject: [PATCH] fix(createOffer()): Prevening duplicate Offers from being created --- src/adapters/index.js | 2 +- src/use-cases/offer/index.js | 8 ++++++++ src/use-cases/order.js | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/adapters/index.js b/src/adapters/index.js index 3501e77..0007287 100644 --- a/src/adapters/index.js +++ b/src/adapters/index.js @@ -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) diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index 43dc2e9..489fc82 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -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 diff --git a/src/use-cases/order.js b/src/use-cases/order.js index 31b766f..bb4a36e 100644 --- a/src/use-cases/order.js +++ b/src/use-cases/order.js @@ -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)