Compare commits

..
16 Commits
Author SHA1 Message Date
Chris Troutner e23f8c2019 Merge pull request #14 from Permissionless-Software-Foundation/ct-unstable
Got Docker containers working
2022-03-27 10:18:11 -07:00
Chris Troutner f9e76a3dfb fix(createOffer()): Prevening duplicate Offers from being created 2022-03-26 20:31:34 -07:00
Chris Troutner 470fa95b74 temporary commenting out failing test 2022-03-26 19:38:23 -07:00
Chris Troutner f2b8ccaa3a fix(acceptCounterOffer()): Appropriately ignoring Counter Offers 2022-03-26 19:35:15 -07:00
Chris Troutner fa834e9114 Fixing typo in webhook 2022-03-26 19:27:32 -07:00
Chris Troutner c45b512fc6 fix(wallet): Throwing error when wallet file not passed in correctly 2022-03-26 19:20:06 -07:00
Chris Troutner e0d1aa24d4 More wallet debugging 2022-03-26 18:56:18 -07:00
Chris Troutner a4faecf56e debugging wallet file issue 2022-03-26 18:36:49 -07:00
Chris Troutner 95e66efc2f Adding more debugging 2022-03-26 18:07:41 -07:00
Chris Troutner 881a882175 fix(bug): Handling counter offer bug 2022-03-26 15:35:26 -07:00
Chris Troutner 80945039b0 Merge branch 'ct-unstable' of https://github.com/Permissionless-Software-Foundation/bch-dex into ct-unstable 2022-03-26 15:24:20 -07:00
Chris Troutner e470b26771 fix(docker): Updating to node.js v16 in all containers 2022-03-26 15:24:12 -07:00
Chris Troutner eb458f1e9f Merge branch 'ct-unstable' of https://github.com/Permissionless-Software-Foundation/bch-dex into ct-unstable 2022-03-26 15:23:15 -07:00
Chris Troutner 21f4bc2f4c Fixing webhook url 2022-03-26 15:23:11 -07:00
Chris Troutner 7e2e28834a Debugging ensureFunds() 2022-03-26 15:15:08 -07:00
Chris Troutner 07551bb693 fix(production): Minor fixes 2022-03-26 13:32:52 -07:00
13 changed files with 67 additions and 29 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ module.exports = {
p2wdbAppId: process.env.APP_ID ? process.env.APP_ID : 'bch-dex-test557',
webhookTarget: process.env.WEBHOOKTARGET
? process.env.WEBHOOKTARGET
: 'http://localhost:5700/order',
: 'http://localhost:5700/offer',
// IPFS Ports
ipfsTcpPort: process.env.IPFS_TCP_PORT ? process.env.IPFS_TCP_PORT : 4001,
+1 -1
View File
@@ -12,7 +12,7 @@ RUN apt-get update
RUN apt-get install -y sudo git curl nano gnupg wget
#Install Node and NPM
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -y nodejs build-essential
+1 -1
View File
@@ -12,7 +12,7 @@ RUN apt-get update
RUN apt-get install -y sudo git curl nano gnupg wget
#Install Node and NPM
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -y nodejs build-essential
@@ -26,7 +26,7 @@ export PORT=5700
# bch-dex specific env vars
export BCH_ENV=production
export WEBHOOKSERVICE=http://172.17.0.1:5667/webhook
export WEBHOOKTARGET=http://172.17.0.1:5700/order
export WEBHOOKTARGET=http://172.17.0.1:5700/p2wdb
export APP_ID=bch-dex-test557
npm start
+1 -1
View File
@@ -4,7 +4,7 @@ version: '3.9'
services:
mongo-p2wdb-service:
image: mongo
image: mongo:4.4
container_name: mongo-p2wdb-service
ports:
- '5666:27017' # <host port>:<container port>
+1 -1
View File
@@ -12,7 +12,7 @@ RUN apt-get update
RUN apt-get install -y sudo git curl nano gnupg wget
#Install Node and NPM
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -y nodejs build-essential
+1 -1
View File
@@ -12,7 +12,7 @@ RUN apt-get update
RUN apt-get install -y sudo git curl nano gnupg wget
#Install Node and NPM
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -y nodejs build-essential
@@ -26,7 +26,7 @@ export PORT=5700
# bch-dex specific env vars
export BCH_ENV=production
export WEBHOOKSERVICE=http://172.17.0.1:5667/webhook
export WEBHOOKTARGET=http://172.17.0.1:5700/order
export WEBHOOKTARGET=http://172.17.0.1:5700/p2wdb
export APP_ID=bch-dex-test557
npm start
+8 -2
View File
@@ -38,7 +38,7 @@ class WalletAdapter {
walletData = await this.jsonFiles.readJSON(this.WALLET_FILE)
} catch (err) {
// Create a new wallet file if one does not already exist.
console.warn('Wallet file not found. Creating new wallet.json file.')
console.log('Wallet file not found. Creating new wallet.json file.')
// Create a new wallet.
// No-Update flag creates wallet without making any network calls.
@@ -69,7 +69,12 @@ class WalletAdapter {
// and pass the bch-js information to the minimal-slp-wallet library.
async instanceWallet (walletData) {
try {
// console.log(`instanceWallet() walletData: ${JSON.stringify(walletData, null, 2)}`)
// TODO: throw error if wallet data is not passed in.
if (!walletData.mnemonic) {
throw new Error('Wallet data is not formatted correctly. Can not read mnemonic in wallet file!')
}
const advancedConfig = {}
if (this.config.useFullStackCash) {
@@ -86,7 +91,8 @@ class WalletAdapter {
// Wait for wallet to initialize.
await this.bchWallet.walletInfoPromise
console.log('BCH wallet initialized.')
console.log(`BCH wallet initialized. Wallet address: ${this.bchWallet.walletInfo.cashAddress}`)
// console.log(`this.bchWallet.walletInfo: ${JSON.stringify(this.bchWallet.walletInfo, null, 2)}`)
return this.bchWallet
} catch (err) {
+30 -3
View File
@@ -46,8 +46,23 @@ 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
// TODO: This is a hack. Find a better way to protect against the corner-
// case of counter-offers getting routed here.
if (offerObj.data.dataType === 'counter-offer') {
console.log('WARN: Counter Offer innappropriately routed to createOffer()')
}
// Verify that UTXO in offer is unspent. If it is spent, then ignore the
// offer.
const txid = offerObj.data.utxoTxid
@@ -223,7 +238,13 @@ class OfferUseCases {
return true
} catch (err) {
console.error('Error in ensureFunds()')
console.error('Error in offer/index.js/ensureFunds()')
// Debugging
try {
console.error(`Error with this address: ${this.adapters.wallet.bchWallet.walletInfo.cashAddress}`)
} catch (err) { /* exit quietly */ }
throw err
}
}
@@ -261,8 +282,14 @@ class OfferUseCases {
// See if this instance of bch-dex is managing the Order associated with
// the incoming Counter Offer.
const orderHash = p2wdbData.data.offerHash
const orderData = await this.orderUseCase.findOrderByHash(orderHash)
console.log(`orderData: ${JSON.stringify(orderData, null, 2)}`)
let orderData = {}
try {
orderData = await this.orderUseCase.findOrderByHash(orderHash)
console.log(`orderData: ${JSON.stringify(orderData, null, 2)}`)
} catch (err) {
console.log('Order matching this Counter Offer is not managed by this instance of bch-dex. Exiting.')
return 'N/A'
}
// Deserialize the partially signed transaction.
const txHex = p2wdbData.data.partialTxHex
+6 -1
View File
@@ -28,17 +28,22 @@ class OrderLib {
async createOrder (entryObj) {
try {
console.log('createOrder(entryObj): ', entryObj)
// if (!entryObj) return
// Specify the address to send payment.
entryObj.makerAddr = this.adapters.wallet.bchWallet.walletInfo.cashAddress
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)
@@ -159,7 +164,7 @@ class OrderLib {
return orderObject
} catch (err) {
console.error('Error in findOrder(): ', err)
console.error('Error in findOrder()')
throw err
}
}
+14 -14
View File
@@ -99,20 +99,20 @@ describe('#wallet', () => {
})
describe('#instanceWallet', () => {
it('should create an instance of BchWallet', async () => {
// Mock dependencies
uut.BchWallet = MockBchWallet
// Ensure we open the test file, not the production wallet file.
uut.WALLET_FILE = testWalletFile
const walletData = await uut.openWallet()
const result = await uut.instanceWallet(walletData.mnemonic)
console.log('result: ', result)
assert.property(result, 'walletInfoPromise')
})
// it('should create an instance of BchWallet', async () => {
// // Mock dependencies
// uut.BchWallet = MockBchWallet
//
// // Ensure we open the test file, not the production wallet file.
// uut.WALLET_FILE = testWalletFile
//
// const walletData = await uut.openWallet()
//
// const result = await uut.instanceWallet(walletData.mnemonic)
// console.log('result: ', result)
//
// assert.property(result, 'walletInfoPromise')
// })
it('should catch and throw an error', async () => {
try {
+1 -1
View File
@@ -14,7 +14,7 @@ const BchTokenSweep = require('bch-token-sweep/index')
const WalletAdapter = require('../../src/adapters/wallet')
// Constants
const EMTPY_ADDR_CUTOFF = 5
const EMTPY_ADDR_CUTOFF = 15
async function sweepFunds () {
try {