diff --git a/config/env/common.js b/config/env/common.js index 399917a..9848110 100644 --- a/config/env/common.js +++ b/config/env/common.js @@ -166,7 +166,7 @@ export default { chatPubSubChan: 'psf-ipfs-chat-001', // IPFS gateway - ipfsGateway: process.env.IPFS_GATEWAY ? process.env.IPFS_GATEWAY : 'https://p2wdb-gateway-678.fullstack.cash/ipfs/', + ipfsGateway: process.env.IPFS_GATEWAY ? process.env.IPFS_GATEWAY : 'https://pin.fullstack.cash/ipfs/download/', // This can add specific Circuit Relay v2 servers to connect to. bootstrapRelays: [ diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index cfb8e9b..3f61050 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -384,9 +384,9 @@ class OfferUseCases { // Ensure the app wallet has enough funds to write to the P2WDB. // Note : this validation should be deprecated for nostr functionality? - const wif = this.adapters.wallet.bchWallet.walletInfo.privateKey - const canWriteToP2WDB = await this.adapters.p2wdb.checkForSufficientFunds(wif) - if (!canWriteToP2WDB) throw new Error('App wallet does not have funds for writing to the P2WDB.') + // const wif = this.adapters.wallet.bchWallet.walletInfo.privateKey + // const canWriteToP2WDB = await this.adapters.p2wdb.checkForSufficientFunds(wif) + // if (!canWriteToP2WDB) throw new Error('App wallet does not have funds for writing to the P2WDB.') if (offerEntity.buyOrSell.includes('sell')) { // Sell Offer @@ -456,13 +456,17 @@ class OfferUseCases { const offer = await this.OfferModel.findOne({ utxoTxid }) + // TODO: Offer should be found by TXID, then if there is more than one + // result, they should be filtered by the vout property. That will leave + // one remaining UTXO. + if (!offer) { throw new Error('offer not found') } return offer } catch (error) { - console.error('Error in use-cases/offer/findOfferByTxid(): ') + console.error('Error in use-cases/offer/findOfferByTxid(): ', error.message) throw error } } @@ -629,6 +633,7 @@ class OfferUseCases { } } + // Flag offers as NSFW. async flagOffer (flagData = {}) { try { if (!flagData.data) throw new Error('"data" property is required') diff --git a/src/use-cases/order.js b/src/use-cases/order.js index 505e402..bed43f5 100644 --- a/src/use-cases/order.js +++ b/src/use-cases/order.js @@ -55,7 +55,7 @@ class OrderLib { // Ensure sufficient tokens exist to create the order. // await this.ensureFunds(orderEntity) - await this.retryQueue.addToQueue(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]) diff --git a/test/unit/use-cases/offer.use-case.unit.js b/test/unit/use-cases/offer.use-case.unit.js index 03c07c3..005b857 100644 --- a/test/unit/use-cases/offer.use-case.unit.js +++ b/test/unit/use-cases/offer.use-case.unit.js @@ -503,19 +503,20 @@ describe('#offer-use-case', () => { await uut.takeOffer('eventId') }) }) + describe('#ensureFunds', () => { - it('should handle insufficient funds to use p2wdb', async () => { - try { - // Mock dependencies - sandbox.stub(uut.adapters.p2wdb, 'checkForSufficientFunds').resolves(false) - - await uut.ensureFunds(mockData.offerMockData.data) - - assert.fail('Unexpected code path') - } catch (err) { - assert.include(err.message, 'App wallet does not have funds for writing to the P2WDB') - } - }) + // it('should handle insufficient funds to use p2wdb', async () => { + // try { + // // Mock dependencies + // sandbox.stub(uut.adapters.p2wdb, 'checkForSufficientFunds').resolves(false) + // + // await uut.ensureFunds(mockData.offerMockData.data) + // + // assert.fail('Unexpected code path') + // } catch (err) { + // assert.include(err.message, 'App wallet does not have funds for writing to the P2WDB') + // } + // }) it('should throw error if sats needed could no be able to calculated', async () => { try { diff --git a/util/wallet/sweep-funds.js b/util/wallet/sweep-funds.js index acd098d..fce2588 100644 --- a/util/wallet/sweep-funds.js +++ b/util/wallet/sweep-funds.js @@ -9,10 +9,10 @@ // Public npm libraries import BCHJS from '@psf/bch-js' -import BchTokenSweep from 'bch-token-sweep/index' +import BchTokenSweep from 'bch-token-sweep' // Local libraries -import WalletAdapter from '../../src/adapters/wallet' +import WalletAdapter from '../../src/adapters/wallet.js' // Constants const EMTPY_ADDR_CUTOFF = 15 @@ -22,6 +22,7 @@ async function sweepFunds () { // Open the wallet files. const wallet = new WalletAdapter() const walletInfo = await wallet.openWallet() + const bchWallet = await wallet.instanceWallet(walletInfo) console.log('walletInfo: ', walletInfo) const rootAddr = walletInfo.cashAddress @@ -49,7 +50,7 @@ async function sweepFunds () { const sweeper = new BchTokenSweep( wifToSweep, rootWif, - bchjs, + bchWallet, 550, rootAddr ) @@ -68,7 +69,7 @@ async function sweepFunds () { // Wait between loop iterations. await bchjs.Util.sleep(3000) } catch (err) { - console.log(`error message with index ${hdIndex}: ${err.message}`) + console.log(`error message with index ${hdIndex}: ${err}`) emptyAddrCnt++ }