Added makerAddr to Order and Offer

This commit is contained in:
Chris Troutner
2022-03-22 11:05:31 -07:00
parent 449efd2a98
commit 4201850389
10 changed files with 41 additions and 8 deletions
+4
View File
@@ -34,6 +34,9 @@ Order entities have the following properties:
- For AVAX, the min currency is nano-Avax.
- for eCash, the min currency is bits.
- _minUnitsToExchange_ - The minimum order size accepted.
- _makerAddr_ - The address for the taker to send money to.
- _p2wdbTxid_ - The TXID proof-of-burn used to add the order to the P2WDB.
- _p2wdbHash_ - The CID used to identify the order entry in the P2WDB.
- Authentication Data:
- _signature_ - A message signed by the address which created the order.
@@ -70,6 +73,7 @@ Offer entities have the following properties:
- For AVAX, the min currency is nano-Avax.
- for eCash, the min currency is bits.
- _minUnitsToExchange_ - The minimum order size accepted.
- _makerAddr_ - The address for the taker to send money to.
- _p2wdbTxid_ - The TXID proof-of-burn used to add the order to the P2WDB.
- _p2wdbHash_ - The CID used to identify the order entry in the P2WDB.
- _offerStatus_ - The state of the offer. When the data is added to the P2WDB, it gets a value of 'posted', but the database model internal to bch-dex can have the following properties:
+1 -1
View File
@@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"test": "npm run test:all",
"test:all": "export BCH_DEX=test && nyc --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/",
"test:all": "export BCH_DEX=test && nyc --reporter=text mocha --exit --timeout 30000 --recursive test/unit test/e2e/automated/",
"test:unit": "export BCH_DEX=test && mocha --exit --timeout 15000 --recursive test/unit/",
"test:e2e:auto": "export BCH_DEX=test && mocha --exit --timeout 30000 test/e2e/automated/",
"test:integration": "export BCH_DEX=test && mocha --exit --timeout 45000 --recursive test/integration",
+1
View File
@@ -15,6 +15,7 @@ const Offer = new mongoose.Schema({
p2wdbTxid: { type: String },
p2wdbHash: { type: String },
offerStatus: { type: String },
makerAddr: { type: String },
// Authentication data
signature: { type: String },
+3
View File
@@ -2,6 +2,8 @@
Order Model. Orders are 'internal' to the system and track the HD wallet index
that contains funds for that Order. This is in contrast to Offers, which
are 'external' to the system and mirrored by every instance of bch-dex.
See the dev-docs/specification.md for details on each property.
*/
const mongoose = require('mongoose')
@@ -19,6 +21,7 @@ const Order = new mongoose.Schema({
minUnitsToExchange: { type: String },
p2wdbTxid: { type: String },
p2wdbHash: { type: String },
makerAddr: { type: String },
// Authentication data
signature: { type: String },
+18 -2
View File
@@ -17,7 +17,19 @@ class OfferEntity {
)
}
const { messageType, messageClass, tokenId, buyOrSell, rateInBaseUnit, minUnitsToExchange, numTokens, utxoTxid, utxoVout, offerStatus } = offerData.data
const {
messageType,
messageClass,
tokenId,
buyOrSell,
rateInBaseUnit,
minUnitsToExchange,
numTokens,
utxoTxid,
utxoVout,
offerStatus,
makerAddr
} = offerData.data
// Input Validation
if (!messageType || typeof messageType !== 'number') {
@@ -50,6 +62,9 @@ class OfferEntity {
if (offerStatus && !this.offerStatus.includes(offerStatus)) {
throw new Error("Property 'offerStatus' must be posted, taken, or dead")
}
if (!makerAddr || typeof makerAddr !== 'string') {
throw new Error("Property 'makerAddr' must be a string.")
}
const validatedOfferData = {
messageType,
@@ -65,7 +80,8 @@ class OfferEntity {
localTimestamp: offerData.localTimeStamp,
txid: offerData.txid,
p2wdbHash: offerData.hash,
offerStatus: offerStatus || this.offerStatus[0]
offerStatus: offerStatus || this.offerStatus[0],
makerAddr
}
return validatedOfferData
+4
View File
@@ -52,6 +52,10 @@ class OrderLib {
orderEntity.utxoTxid = utxoInfo.txid
orderEntity.utxoVout = utxoInfo.vout
// Specify the address to send payment.
orderEntity.makerAddr = this.adapters.wallet.bchWallet.walletInfo.cashAddress
console.log('orderEntity.makerAddr: ', orderEntity.makerAddr)
// Add P2WDB specific flag for signaling that this is a new offer.
orderEntity.dataType = 'offer'
+1 -1
View File
@@ -12,7 +12,7 @@ async function start () {
method: 'post',
url: `${LOCALHOST}/offer/take`,
data: {
offerCid: 'zdpuAxgdi3az59KrbscntQR2tXjU7tycjvJk6YNN2usiF2t9m'
offerCid: 'zdpuAs5Djp9VrnheYTSDVes6f4KJVds2u3juM3MxwFYbTV8m2'
}
}
+2 -1
View File
@@ -252,7 +252,8 @@ describe('#Offer-Entity', () => {
utxoTxid:
'241c06bf61384b8623477e419bf4779edbcc7e3bc862f0f179a9ed2967069b87',
utxoVout: 0,
offerStatus: 'posted'
offerStatus: 'posted',
makerAddr: 'bitcoincash:qzl0d3gcqeypv4cy7gh8rgdszxa9vvm2acv7fqtd00'
},
timestamp: '2021-09-20T17:54:26.395Z',
localTimeStamp: '9/20/2021, 10:54:26 AM',
+2 -1
View File
@@ -94,7 +94,8 @@ describe('#offer-use-case', () => {
numTokens: 0.02,
utxoTxid:
'241c06bf61384b8623477e419bf4779edbcc7e3bc862f0f179a9ed2967069b87',
utxoVout: 0
utxoVout: 0,
makerAddr: 'bitcoincash:qzl0d3gcqeypv4cy7gh8rgdszxa9vvm2acv7fqtd00'
},
timestamp: '2021-09-20T17:54:26.395Z',
localTimeStamp: '9/20/2021, 10:54:26 AM',
+5 -2
View File
@@ -13,6 +13,9 @@ const BchTokenSweep = require('bch-token-sweep/index')
// Local libraries
const WalletAdapter = require('../../src/adapters/wallet')
// Constants
const EMTPY_ADDR_CUTOFF = 5
async function sweepFunds () {
try {
// Open the wallet files.
@@ -69,9 +72,9 @@ async function sweepFunds () {
}
hdIndex++
} while (emptyAddrCnt < 10)
} while (emptyAddrCnt < EMTPY_ADDR_CUTOFF)
console.log('5 empty addresses detected. Exiting.')
console.log(`${EMTPY_ADDR_CUTOFF} empty addresses detected. Exiting.`)
console.log('\n\nDo not forget to reset the nextAddress property in the wallet.json file!\n\n')
} catch (err) {