mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Merge pull request #120 from Permissionless-Software-Foundation/dh-npub-offer
feat(nostr): Added npub to Offer model
This commit is contained in:
@@ -18,7 +18,7 @@ const Offer = new mongoose.Schema({
|
|||||||
p2wdbHash: { type: String },
|
p2wdbHash: { type: String },
|
||||||
offerStatus: { type: String },
|
offerStatus: { type: String },
|
||||||
makerAddr: { type: String },
|
makerAddr: { type: String },
|
||||||
makerNpub: { type: String },
|
makerNpub: { type: String, default: null },
|
||||||
|
|
||||||
// Authentication data
|
// Authentication data
|
||||||
signature: { type: String },
|
signature: { type: String },
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class OfferEntity {
|
|||||||
utxoVout,
|
utxoVout,
|
||||||
offerStatus,
|
offerStatus,
|
||||||
makerAddr,
|
makerAddr,
|
||||||
|
makerNpub,
|
||||||
ticker,
|
ticker,
|
||||||
tokenType,
|
tokenType,
|
||||||
nostrEventId,
|
nostrEventId,
|
||||||
@@ -89,6 +90,10 @@ class OfferEntity {
|
|||||||
if (!operatorPercentage || typeof operatorPercentage !== 'number') {
|
if (!operatorPercentage || typeof operatorPercentage !== 'number') {
|
||||||
throw new Error("Property 'operatorPercentage' must be a number.")
|
throw new Error("Property 'operatorPercentage' must be a number.")
|
||||||
}
|
}
|
||||||
|
// Validate npub type if it exist
|
||||||
|
if (makerNpub && typeof makerNpub !== 'string') {
|
||||||
|
throw new Error("Property 'makerNpub' must be a string.")
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the timestamp to a number.
|
// Convert the timestamp to a number.
|
||||||
let timestamp = new Date(offerData.timestamp)
|
let timestamp = new Date(offerData.timestamp)
|
||||||
@@ -113,7 +118,8 @@ class OfferEntity {
|
|||||||
makerAddr,
|
makerAddr,
|
||||||
ticker,
|
ticker,
|
||||||
tokenType,
|
tokenType,
|
||||||
nostrEventId
|
nostrEventId,
|
||||||
|
makerNpub
|
||||||
}
|
}
|
||||||
// console.log('offer entity validatedOfferData: ', validatedOfferData)
|
// console.log('offer entity validatedOfferData: ', validatedOfferData)
|
||||||
|
|
||||||
|
|||||||
@@ -491,6 +491,36 @@ describe('#Offer-Entity', () => {
|
|||||||
assert.include(err.message, "Property 'operatorPercentage' must be a number.")
|
assert.include(err.message, "Property 'operatorPercentage' must be a number.")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
it('should throw an error if makerNpub is not a string', () => {
|
||||||
|
try {
|
||||||
|
const offerData = {
|
||||||
|
data: {
|
||||||
|
messageType: 1,
|
||||||
|
messageClass: 1,
|
||||||
|
tokenId: 'fakeId',
|
||||||
|
buyOrSell: 'buy',
|
||||||
|
rateInBaseUnit: 1000,
|
||||||
|
minUnitsToExchange: 350,
|
||||||
|
numTokens: 1,
|
||||||
|
utxoTxid: 'fakeTxid',
|
||||||
|
utxoVout: 0,
|
||||||
|
offerStatus: 'posted',
|
||||||
|
makerAddr: 'bitcoincash:qzl0d3gcqeypv4cy7gh8rgdszxa9vvm2acv7fqtd00',
|
||||||
|
tokenType: 1,
|
||||||
|
nostrEventId: 'test',
|
||||||
|
operatorAddress: 'bitcoincash:qzl0d3gcqeypv4cy7gh8rgdszxa9vvm2acv7fqtd00',
|
||||||
|
operatorPercentage: 10,
|
||||||
|
makerNpub: 1234
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uut.validate(offerData)
|
||||||
|
|
||||||
|
assert.fail('Unexpected code path')
|
||||||
|
} catch (err) {
|
||||||
|
// console.log(err)
|
||||||
|
assert.include(err.message, "Property 'makerNpub' must be a string.")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('should validate a new offer', () => {
|
it('should validate a new offer', () => {
|
||||||
const offerObj = {
|
const offerObj = {
|
||||||
@@ -513,7 +543,8 @@ describe('#Offer-Entity', () => {
|
|||||||
tokenType: 1,
|
tokenType: 1,
|
||||||
nostrEventId: 'test',
|
nostrEventId: 'test',
|
||||||
operatorAddress: 'bitcoincash:qzl0d3gcqeypv4cy7gh8rgdszxa9vvm2acv7fqtd00',
|
operatorAddress: 'bitcoincash:qzl0d3gcqeypv4cy7gh8rgdszxa9vvm2acv7fqtd00',
|
||||||
operatorPercentage: 10
|
operatorPercentage: 10,
|
||||||
|
makerNpub: 'npub1dtkf954h5k2yuv04xp44g5hnmk5k0ppv8mekxafm2gc0vveaxh6s0297qg'
|
||||||
},
|
},
|
||||||
timestamp: '2021-09-20T17:54:26.395Z',
|
timestamp: '2021-09-20T17:54:26.395Z',
|
||||||
localTimeStamp: '9/20/2021, 10:54:26 AM',
|
localTimeStamp: '9/20/2021, 10:54:26 AM',
|
||||||
@@ -539,6 +570,8 @@ describe('#Offer-Entity', () => {
|
|||||||
assert.property(result, 'txid')
|
assert.property(result, 'txid')
|
||||||
assert.property(result, 'p2wdbHash')
|
assert.property(result, 'p2wdbHash')
|
||||||
assert.property(result, 'tokenType')
|
assert.property(result, 'tokenType')
|
||||||
|
assert.property(result, 'makerAddr')
|
||||||
|
assert.property(result, 'makerNpub')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user