mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Successfully detecting and routing offers and counter-offers
This commit is contained in:
@@ -350,6 +350,9 @@ class WalletAdapter {
|
||||
}]
|
||||
console.log(`receivers: ${JSON.stringify(receivers, null, 2)}`)
|
||||
|
||||
// Update the UTXO store of the wallet.
|
||||
await this.bchWallet.getUtxos()
|
||||
|
||||
const txid = await this.bchWallet.send(receivers)
|
||||
|
||||
const utxoInfo = {
|
||||
|
||||
@@ -36,6 +36,19 @@ class P2WDBRESTControllerLib {
|
||||
try {
|
||||
console.log('p2wdb REST API handler: body: ', ctx.request.body)
|
||||
|
||||
const dataType = ctx.request.body.data.dataType
|
||||
|
||||
if (dataType.includes('counter')) {
|
||||
console.log('counter-offer data detected.')
|
||||
} else if (dataType.includes('offer')) {
|
||||
console.log('offer data detected')
|
||||
|
||||
const offerObj = ctx.request.body
|
||||
await _this.useCases.offer.createOffer(offerObj)
|
||||
} else {
|
||||
console.log('Could not route P2WDB webhook data.')
|
||||
}
|
||||
|
||||
// const orderObj = ctx.request.body.order
|
||||
//
|
||||
// const hash = await _this.useCases.order.createOrder(orderObj)
|
||||
|
||||
@@ -149,6 +149,9 @@ class OfferUseCases {
|
||||
delete takenOfferInfo._id
|
||||
takenOfferInfo.offerHash = offerInfo.p2wdbHash
|
||||
|
||||
// Add P2WDB specific flag for signaling that this is a new offer.
|
||||
takenOfferInfo.dataType = 'counter-offer'
|
||||
|
||||
// Write offer info to the P2WDB
|
||||
// TODO: This will trigger the webhook. Find some way of triggering the
|
||||
// webhook on new offers, but not on counteroffers
|
||||
|
||||
@@ -18,8 +18,8 @@ async function start () {
|
||||
tokenId:
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
||||
buyOrSell: 'sell',
|
||||
rateInBaseUnit: 1000,
|
||||
minUnitsToExchange: 1000,
|
||||
rateInBaseUnit: 5000,
|
||||
minUnitsToExchange: 5000,
|
||||
numTokens: 1
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ async function start () {
|
||||
method: 'post',
|
||||
url: `${LOCALHOST}/offer/take`,
|
||||
data: {
|
||||
offerCid: 'zdpuB1gqwyto4hJnR2YgnttZiXifzUQ5NLRVBuXEtonwa3f4g'
|
||||
offerCid: 'zdpuAxgdi3az59KrbscntQR2tXjU7tycjvJk6YNN2usiF2t9m'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,8 @@ describe('#wallet', () => {
|
||||
hdIndex: 6
|
||||
})
|
||||
uut.bchWallet = {
|
||||
send: async () => 'fake-txid'
|
||||
send: async () => 'fake-txid',
|
||||
getUtxos: async () => {}
|
||||
}
|
||||
|
||||
const amountSat = 1000
|
||||
|
||||
@@ -35,9 +35,11 @@ async function sweepFunds () {
|
||||
do {
|
||||
// Generate a keypair from the HD wallet.
|
||||
const childNode = masterHDNode.derivePath(`m/44'/245'/0'/0/${hdIndex}`)
|
||||
// const cashAddress = bchjs.HDNode.toCashAddress(childNode)
|
||||
const cashAddress = bchjs.HDNode.toCashAddress(childNode)
|
||||
const wifToSweep = bchjs.HDNode.toWIF(childNode)
|
||||
|
||||
console.log(`\nSweeping ${cashAddress}`)
|
||||
|
||||
try {
|
||||
// Sweep tokens from address
|
||||
const sweeper = new BchTokenSweep(
|
||||
@@ -62,12 +64,12 @@ async function sweepFunds () {
|
||||
// Wait between loop iterations.
|
||||
await bchjs.Util.sleep(3000)
|
||||
} catch (err) {
|
||||
console.log(`error message: ${err.message}`)
|
||||
console.log(`error message with index ${hdIndex}: ${err.message}`)
|
||||
emptyAddrCnt++
|
||||
}
|
||||
|
||||
hdIndex++
|
||||
} while (emptyAddrCnt < 5)
|
||||
} while (emptyAddrCnt < 10)
|
||||
|
||||
console.log('5 empty addresses detected. Exiting.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user