mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 17:12:03 -07:00
71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
/*
|
|
Order Entity
|
|
An Order Entity is nearly the same as an Offer. But while an Offer is generated
|
|
by a webhook from P2WDB, the Order Entity is created internally. It is used
|
|
to track an Order generated by this application.
|
|
|
|
The Order tracks the hdIndex address used to hold tokens or BCH for sale.
|
|
*/
|
|
class Order {
|
|
// TODO: Create a fullValidate() function that validates a fully-hydrated
|
|
// order model.
|
|
|
|
inputValidate (data) {
|
|
const {
|
|
messageType,
|
|
messageClass,
|
|
tokenId,
|
|
buyOrSell,
|
|
rateInBaseUnit,
|
|
minUnitsToExchange,
|
|
numTokens,
|
|
makerAddr
|
|
} = data
|
|
|
|
// Input Validation
|
|
if (!messageType || typeof messageType !== 'number') {
|
|
throw new Error("Property 'messageType' must be an integer number.")
|
|
}
|
|
if (!messageClass || typeof messageClass !== 'number') {
|
|
throw new Error("Property 'messageClass' must be an integer number.")
|
|
}
|
|
if (!tokenId || typeof tokenId !== 'string') {
|
|
throw new Error("Property 'tokenId' must be a string.")
|
|
}
|
|
if (!buyOrSell || typeof buyOrSell !== 'string') {
|
|
throw new Error("Property 'buyOrSell' must be a string.")
|
|
}
|
|
if (!rateInBaseUnit || typeof rateInBaseUnit !== 'number') {
|
|
throw new Error("Property 'rateInBaseUnit' must be an integer number.")
|
|
}
|
|
if (!minUnitsToExchange || typeof minUnitsToExchange !== 'number') {
|
|
throw new Error("Property 'minUnitsToExchange' must be an integer number.")
|
|
}
|
|
if (!numTokens || typeof numTokens !== 'number') {
|
|
throw new Error("Property 'numTokens' must be a number.")
|
|
}
|
|
if (!makerAddr || typeof makerAddr !== 'string') {
|
|
throw new Error("Property 'makerAddr' must be a string.")
|
|
}
|
|
// if (!ticker || typeof ticker !== 'string') {
|
|
// throw new Error("Property 'ticker' must be a string.")
|
|
// }
|
|
|
|
const offerData = {
|
|
messageType,
|
|
messageClass,
|
|
tokenId,
|
|
buyOrSell,
|
|
rateInBaseUnit,
|
|
minUnitsToExchange,
|
|
numTokens,
|
|
makerAddr
|
|
// ticker
|
|
}
|
|
|
|
return offerData
|
|
}
|
|
}
|
|
|
|
export default Order
|