From c27209cceb8019f5339eb01216f15e2d0a351865 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 11 Sep 2022 10:51:32 -0700 Subject: [PATCH] fix(offer): Fixing bugs related to making and taking offers --- package-lock.json | 5 ++++- src/adapters/index.js | 4 ++++ src/use-cases/offer/index.js | 25 +++++++++++++++++-------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index e02d38e..e1aeffc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14788,7 +14788,8 @@ }, "node_modules/p2wdb/node_modules/axios": { "version": "0.24.0", - "license": "MIT", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", + "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", "dependencies": { "follow-redirects": "^1.14.4" } @@ -29415,6 +29416,8 @@ }, "axios": { "version": "0.24.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", + "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", "requires": { "follow-redirects": "^1.14.4" } diff --git a/src/adapters/index.js b/src/adapters/index.js index 9ccc28c..de8af3b 100644 --- a/src/adapters/index.js +++ b/src/adapters/index.js @@ -71,6 +71,10 @@ class Adapters { // Wait until a webhook is established with the P2WDB await this.webhook.waitUntilSuccess(this.config.webhookTarget) + + // Overwrite instances of wallet used by P2WDB lib. + this.p2wdb.bchWallet = this.wallet.bchWallet + this.p2wdb.bchjs = this.wallet.bchWallet.bchjs } console.log('Async Adapters have been started.') diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index d252fef..3134d9c 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -146,15 +146,21 @@ class OfferUseCases { } // Verify that UTXO for sale is unspent. Abort if it's been spent. - const txid = offerInfo.utxoTxid - const vout = offerInfo.utxoVout - const utxoStatus = await this.adapters.bchjs.Blockchain.getTxOut( - txid, - vout - ) + // const txid = offerInfo.utxoTxid + // const vout = offerInfo.utxoVout + + const utxo = { + tx_hash: offerInfo.utxoTxid, + tx_pos: offerInfo.utxoVout + } + const utxoStatus = await this.adapters.wallet.bchWallet.utxoIsValid(utxo) + // const utxoStatus = await this.adapters.bchjs.Blockchain.getTxOut( + // txid, + // vout + // ) console.log('utxoStatus: ', utxoStatus) - if (utxoStatus === null) { - console.log(`utxo txid: ${txid}, vout: ${vout}`) + if (!utxoStatus) { + console.log(`utxo txid: ${offerInfo.utxoTxid}, vout: ${offerInfo.utxoVout}`) // TODO: Mark this Offer as 'dead' @@ -236,6 +242,9 @@ class OfferUseCases { await this.adapters.wallet.bchWallet.walletInfoPromise // console.log(`utxos: ${JSON.stringify(this.adapters.wallet.bchWallet.utxos.utxoStore, null, 2)}`) + // Refresh the wallet UTXOs + await this.adapters.wallet.bchWallet.initialize() + // 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)